Search the Community
Showing results for tags 'linux commands'.
-
The post 5 Different Types of Shell Commands and Their Usage in Linux first appeared on Tecmint: Linux Howtos, Tutorials & Guides .When it comes to gaining absolute control over your Linux system, then nothing comes close to the command line interface (CLI). In order to become The post 5 Different Types of Shell Commands and Their Usage in Linux first appeared on Tecmint: Linux Howtos, Tutorials & Guides.View the full article
-
In this guide, we will demonstrate using the open command in Linux. Prerequisites To perform the steps demonstrated in this guide, you will need the following components: A properly configured Linux system. For testing, consider using a Linux VM. Basic understanding of the command-line interface. The open command In Linux, the open command is a CLI tool that attempts to open a specified file, directory, or URL using the default program. Check out the following example: open https://linuxhint.com/ Here, the open command will open the URL on the default web browser. open vs xdg-open Some Linux systems use xdg-open (part of the xdg-utils package) instead of the open command. In practice, they both behave the same: xdg-open https://example.com To rectify this, we can create an alias for the xdg-open command. The following example demonstrates creating a temporary Bash alias: alias open='xdg-open' Verify if the alias was created successfully: alias alias open Note that various command arguments of the open command won’t work with xdg-open. Some distros implement the open command as a symlink to xdg-open (Ubuntu, for example). Using the open Command Opening Text Files To open a text file in the default text editor/viewer, run the following command: open test.txt Opening an URL If we attempt to open a URL, the expected behavior is to open the URL in the default web browser. open https://archlinux.org Opening a File using a Specific App If not specified, the open command will use the default app to open the specified file/URL. However, we can specify a different program to use when attempting to open the file. To open with a different program, the command structure is as follows: open -a We can also specify what app to use using bundle identifier: open -b Note that it won’t work with xdg-open. Opening a File in a New Program Instance If the file-associated program is already running, then open will use the already-running instance. In some situations, however, we may want to open the file in a new program instance. To open the file with a new program instance, use the “-n” flag: open -n Note that this method will also not work with xdg-open. Final Thoughts In this guide, we demonstrated using the open command on Linux. It takes a file, directory, or URL as an argument and launches the default program designated to handle it. Interested in learning about other Linux commands? Check out the Linux commands sub-category. Happy computing! View the full article
-
In this guide, we will demonstrate a number of ways of using the APT command on Linux. Prerequisites To perform the steps demonstrated in this guide, you will need the following components: A properly configured Linux distro that uses APT as the package manager, for example, Debian, Ubuntu, Linux Mint, Devuan, etc. Basic understanding of the CLI and package management. The APT Command Any Linux distro comprises a number of packages. To manage these numerous packages in an efficient manner, almost all distros use one or more package managers. APT is one such package manager. It’s a CLI tool that can install, uninstall, and manage DEB packages on distros like Debian, Ubuntu, and Debian/Ubuntu-based ones. If an APT command is to make system-level changes, it must run with root privilege (with the help of the sudo command). Using the APT Command Example 1: Updating the List of Available Packages Before APT can work with packages, it needs a working database of all the available packages. To generate the most up-to-date database, run the following command: sudo apt update Here, APT will fetch the latest package database from the package repo(s). If any package update is available, APT will also print a notification. Example 2: List Available Package Upgrades If APT finds package upgrades, the following command will list all of them: apt list --upgradable Example 3: Upgrading Packages If one or more package updates were found, then you can upgrade all of them at once using the following command: sudo apt upgrade Alternatively, the following command will upgrade the whole system by removing, installing, and upgrading packages as needed: sudo apt full-upgrade Example 4: Upgrading Specific Packages If you don’t want to install all the package upgrades but specific ones, use the following command structure: sudo apt --only-upgrade install [package_name] Example 5: Downgrading Packages Sometimes, a package upgrade may break things. In such a situation, you may want to downgrade the problematic package(s) to an earlier version. To downgrade a package, run the following command: apt install [package_name]=[older_package_version] Example 6: Searching for a Package To check if a package is available from the package repo, use the following command: apt search [package_name] Example 7: Installing a Package If a package exists on the package repo(s) specified in the sources.list, then you can directly install it using the following command: sudo apt install [package_name] Example 8: Installing a Specific Package Version The procedure is the same as example #5. If you want to install a specific version of a package, specify it in the following manner: sudo apt install [package_name]=[package_version] If the package version is not specified, then APT will automatically install the latest package. Example 9: Listing Available Package Versions The default package repo(s), in most cases, will host multiple versions of a package. The following command will reveal all the available package versions: apt-cache policy [package_name] Example 10: Holding a Package Whenever running the apt upgrade command, it will check for upgrades for all the installed packages. In certain situations, however, you may want to skip upgrading certain packages for various reasons (stability, compatibility, etc.). In such a situation, you can mark the target package(s) as hold. Basically, whenever performing automatic package upgrades, APT will skip these packages. To mark a package as hold, run the following command: sudo apt-mark hold [package_name] To get a list of all the hold packages, run the following command: apt-mark showhold To remove the hold mark from a package, use the following command: sudo apt-mark unhold [package_name] Example 11: Installing a DEB Package Debian and Debian-based systems use DEB as the software packaging. All the packages from the package repo(s) also come as DEB files. To install a DEB package, use the following APT command: sudo apt install [path_to_deb] APT should take care of all the necessary dependencies as well. Example 12: Uninstalling a Package To uninstall a package, use the following command: sudo apt remove [package_name] Generally, APT won’t remove the package dependencies. To remove them afterward, run the following command: sudo apt autoremove We can also instruct APT to perform both of these actions in a single command: sudo apt autoremove --purge [package_name] Note that purging a package will also remove all the package-related configuration files, so exercise caution. Example 13: Listing Installed Packages APT keeps track of all the packages installed from the package repo(s) and DEB packages. The following command will list all the installed packages that APT is keeping track of: apt list --installed We can filter this output using grep to check if a package with a particular name/pattern is installed: apt list --installed | grep [pattern] Learn more about grep. Example 14: Package Details Before installing a package from the repo, we can check detailed info about it: apt show [package_name] Example 15: Downloading a Package from Repo To download a package from the package repo(s) without installing it, use the following command: apt download [package_name] It will download the package as a DEB file in the current directory. You can later install it using APT following the steps demonstrated in example #11. Bonus: Editing sources.list The sources.list file contains the URL for all the APT repos. We can open it using APT for editing: sudo apt edit-sources Alternatively, we can manually edit it using any text editor: sudo vim /etc/apt/sources.list In the case of Ubuntu, to auto select the nearest mirror, update the repo URLs with the following one: mirror://mirrors.ubuntu.com/mirrors.txt After updating sources.list, you have to update the APT cache: sudo apt update Bonus: APT Documentation The following command will print a quick help page: apt --help To learn more about all the available options with in-depth explanations, check out the man page: man apt Final Thoughts In this guide, we demonstrated numerous ways of using the APT command. We learned about installing, uninstalling, upgrading, downgrading, and downloading packages on Debian and Debian-based systems. While APT handles DEB packages, there are other Linux packaging formats, for example, flatpak, snap, etc. These packages are designed to be practically universal Linux packages that can be installed on any Linux system. Happy computing! View the full article
-
The post How to Use Compound Expressions with Awk in Linux – Part 5 first appeared on Tecmint: Linux Howtos, Tutorials & Guides .All along, we have been looking at simple expressions when checking whether a condition has been met or not. What if you want to use The post How to Use Compound Expressions with Awk in Linux – Part 5 first appeared on Tecmint: Linux Howtos, Tutorials & Guides.View the full article
-
The post How to Use Comparison Operators & Data Filtering with Awk – Part 4 first appeared on Tecmint: Linux Howtos, Tutorials & Guides .When dealing with numerical or string values in a line of text, filtering text or strings using comparison operators comes in handy for awk command The post How to Use Comparison Operators & Data Filtering with Awk – Part 4 first appeared on Tecmint: Linux Howtos, Tutorials & Guides.View the full article
-
As the name suggests, grep or global regular expression print lets you search for specific text patterns within a file’s contents. Its functionalities include pattern recognition, defining case sensitivity, searching multiple files, recursive search, and many more. So whether you’re a beginner or a system administrator, knowing about the grep command to locate the files efficiently is good. This tutorial will explain how to use grep in Linux and discuss its different applications. How To Use Grep Command in Linux The basic function of the grep command is to search for a particular text inside a file. You can do that by entering the following command: grep "text_to_search" file.txt Please replace ‘text_to_search’ with the text you want to search for and ‘file.txt’ with the target file. For example, to find the string “Hello” in the file named file.txt, we will use: grep "Hello" file.txt On entering the above command, grep will scan the Intro.txt file for “Hello.” As a result, it shows the output of the whole line or lines containing the target text. If the target file is on a path different from your current directory, please mention that path along with the file name. For instance: grep "Hello" ~/Documents/file.txt Here, the tildes ‘~’ mark represents your home directory. The above example shows how you can search for a piece of text in a single file. However, if you want to do the same search on multiple files at once, mention them subsequently in one grep command: grep "Hello" file.txt Linux_info.txt Password.txt In case you’re not sure about your string’s cases(uppercase or lowercase), perform a case-insensitive search by using the i option: grep -i "hello" Intro.txt Although the string we input was not the exact match, we received accurate results through the case-insensitive search. In case you want to invert the changes and check files that don’t contain the specific pattern, then please use the v option: grep -v "Hello" file.txt Linux_info.txt Password.txt Moreover, if you want to display the lines that start with a certain word, use the ‘^’ symbol. It serves as an anchor that specifies the beginning of the line. grep "^Hello" file.txt The above commands will only be useful when you know which file to search. In this case, you can recursively search the string inside the whole directory using the r option. For example, let’s search “Hello” inside the Documents directory: grep -r "Hello" ~/Documents Furthermore, you can also count the number of times the input string appears in a file through the c option: grep -c "Hello" Intro.txt Similarly, you can display the line numbers along with the matched lines with the n option: grep -n "Hello" Intro.txt A Quick Wrap-up Users often remember that a file used to contain a piece of text but forget the file name, which can land them in deep trouble. Hence, this tutorial was about using the grep command to search for text in a file’s contents. Furthermore, we have used different examples to demonstrate how you can tweak the grep command’s functioning with a few options. You can experiment by combining multiple options to find out what suits best according to your use case. View the full article
-
Linux works well as a multiuser operating system. Many users can access a single OS simultaneously without interpreting each other. However, if others can access your directories or files, the risk may increase. Hence, from a security perspective, securing the data from others is essential. Linux has features to control access from permissions and ownership. The ownership of files, folders, or directories is categorized into three parts, which are: User (u): This is the default owner, also called the file’s creator. Group (g): It is the collection of multiple users with the same permissions to access folders or files. Other (o): Those users not in the above two categories belong to it. That’s why Linux offers simple ways to change file permissions without hassles. So in this quick blog, we have included all the possible methods to change file permissions in Linux. How to Change File Permissions in Linux In Linux, mainly Linux file permissions are divided into three parts, and these are: Read (r): In this category, users can only open and read the file and can’t make any changes to it. Write (w): Users can edit, delete, and modify the file content with written permission. Execute (x): When the user has this permission, they can execute the executable script and access the file details. Owner Representation Modify permission using the operator Permission symbols for symbolic mode Permission symbols for absolute mode User → u To add use ‘+’ Read → r To add or subtract read use ± 4 Group → g To subtract use ‘-‘ Write → w To add or subtract read use ± 2 Other → o To set use ‘=’ Execute → x To add or subtract read use ± 1 As you can see from the above table, there are two types of symbol representation of permission. You can use both of these modes (symbolic and absolute) to change file permissions using the chmod command. The chmod refers to the change mode that allows users to modify the access permission of files or folders. Using chmod Symbolic Mode In this method, we use the symbol (for owner- u, g, o; for permission- r, w, x) to add, subtract, or set the permissions using the following syntax: chmod <owner_symbol> mode <permission_symbol> <filename> Before changing the file permission, first, we need to find the current one. For this, we use the ‘ls’ command. ls -l Here the permission symbols belong to the following owner: ‘-‘ : shows the file type. ‘rw-‘ : shows the permission of the user (read and write) ‘rw-‘ : shows the permission of the group(read and write) ‘r- -‘ : shows the permission of others (read) In the above image, we highlighted one file in which the user has read and write permission, the group has read and write permission, and the other has only read permission. So here, we are going to add executable permission to others. For this, use the following command: chmod o+x os.txt As you can see, the execute permission has been added to the other category. Simultaneously, you can also change the multiple permissions of different owners. Following the above example, again, we change the permissions in it. So, here, we add executable permission from the user, remove write permission from the group, and add write permission to others. For this, we can run the below command: chmod -v u+x ,g-w,o+w os.txt Note: Use commas while separating owners, but do not leave space between them. Using chmod Absolute Mode Similarly, you can change the permission through absolute mode. In this method, mathematical operators (+, -, =) and numbers represent the permissions, as shown in the above table. For example, let’s take an example and the updated permission of the file data is as follows: Mathematical representation of the permission: User Read + Write Permission is represented as 665 4+2=6 Group Read + Write 4+2=6 Other Read + Execute 4+1=5 Now, we are going to remove read permission from the user and others, and the final calculation is: User Read + Write -Read (-4) Updated permission is represented as 261 4+2=6 6-4=2 Group Read + Write – 4+2=6 6 Other Read + Execute -Read (-4) 4+1=5 5-4=1 To update the permission, use the following chmod command: chmod -v 261 os.txt Change User Ownership of the File Apart from changing the file permission, you may also have a situation where you have to change the file ownership. For this, the chown is used which represents the change owner. The file details represent the following details: <filetype> <file_permission> <user_name> <group_name> <file_name> So, in the above example, the owner’s or user name is ‘prateek’, and you can change the user name that only exists on your system. Before changing the username, first list all the users using the following command: cat /etc/passwd Or awk -F ':' '{print $1}' /etc/passwd Now, you can change the username of your current or new file between these names. The general syntax to change the file owner is as follows: sudo chown <new_username> <filename> Note: Sudo permission is required in some cases. Based on the above result, we want to change the username from ‘prateek’ to ‘proxy.’ To do this, we run the below command in the terminal: sudo chown proxy os.txt Change Group Ownership of the File First, list all the groups that are present in your system using the following command: cat /etc/group | cut -d: f1 The ‘chgrp’ command (change group) changes the filegroup. Here, we change the group name from ‘prateek’ to ‘disk’ using the following command: sudo chgrp disk os.txt Conclusion Managing file permissions is essential for access control and data security. In this guide, we focused on changing the file permissions in Linux. It has a feature through which you can control ownership (user, group, others) and permissions (read, write, execute). Users can add, subtract, or set the permissions according to their needs. Users can easily modify the file permissions through the chmod command using the symbolic and absolute methods. View the full article
-
Operating systems use packets for transferring the data on a network. These are small chunks of information that carry data and travel among devices. Moreover, when any network problem arises, packets aid in identifying the root cause of the underlying problem. How? By tracing the route of those packets. The traceroute command in Linux helps you map the path packets take while traveling to a specific destination. This further helps you troubleshoot network latency, packet loss, network hops, DNS resolution issues, slow website access, and more. So, in this blog, we will explain simple ways to use the traceroute command in Linux. How To Use Traceroute Command in Linux Firstly, the traceroute does not come preinstalled in many Linux distributions. However, you can install it by executing one of the below command according to your system: Operating System Command Debian/Ubuntu sudo apt install traceroute Fedora sudo dnf install traceroute Arch Linux sudo pacman -Sy traceroute openSUSE sudo zypper install traceroute After installation, you can implement the traceroute command by entering: traceroute <destination_IP> Replace <destination_IP> with the device’s IP address at the destination. Once you run the command, your system will display the list of hops with the IP address and response time. Hops are the devices that your packets go through while traveling to a specific destination. For example, let’s use the traceroute command for Google’s IP address: traceroute 8.8.8.8 The result shows only one hop while marking others as an asterisk(*). This happens because the subsequent hops did not respond within the timeout period of 3 seconds. Moreover, the traceroute command, by default, uses DNS resolution to get the hostnames of hops, which slows down the process. You can omit that part and guide it to display only the IP addresses by using the -n option: traceroute -n <destination_IP> If you want to limit the number of hops, use the -m option along with the traceroute command: traceroute -m N <destination_IP> Here, put the desired number of hops in place of N. On execution, it will return only N number of hops in the results. The traceroute command only displays every hop’s round-trip time(RTT). However, you can get more detailed timing information with the -I option: traceroute -I <destination_IP> This command sends an ICMP echo request to retrieve more accurate RTT data. For instance, retake the example of Google: Tip: If your specified destination restricts ICMP packets, you can instead trace the UDP packets by employing the -U option: traceroute -U <destination_IP> In case you want to explore more options for traceroute, then please run the below command: traceroute --help A Quick Wrap-up Traceroute is an amazing CLI utility that you can use to diagnose network-related issues in Linux. It traces the path of packets to identify all the critical issues of the network. Hence, We have explained every single detail about the traceroute command with the help of some examples. View the full article
-
The htop is a CLI utility to check an interactive list of running processes in real-time. It is a more feature-rich and user-friendly alternative to the top command. The htop command allows you to manage system processes, monitor resources, and perform other administration tasks. One of the most prominent features of htop is that it shows color-coded processes, which helps you differentiate them based on resource usage. Furthermore, it lets you customize the results with its sort and filter options. So, this short tutorial is about how to use the htop command in Linux without hassles. Unlike top, the htop command is not preinstalled in most Linux systems. That’s why you must install it using the following commands: Operating System Command Debian/Ubuntu sudo apt-get install htop Fedora sudo dnf install htop RHEL/CentOS sudo yum install htop Now, you can use the htop command, so let’s start with the basics: htop When you execute the above command, it launches the htop utility. Here, you can use the arrow keys to navigate up and down the processes. Moreover, press ‘F1’ or ‘?’ to get the help screen for additional navigation shortcuts. Sort Processes in htop In htop, you can sort the processes by CPU, memory, and other usage. Open the sorting menu by pressing F6: For example, select the PERCENT_CPU option and press ‘Enter.’ As you can see in the above image, all the processes are now sorted by CPU consumption. Search and Filter Processes in htop To search any process in htop, please go through the following steps: Press ‘F3’ to open the search bar. Similarly, press ‘F4’ to filter out the processes. Additional Options with htop -d, –delay=[argument]: By default, htop updates the processes every second, but you can add a delay using this option. For instance, to introduce a delay of 10 seconds, we would enter ‘–delay=10.’ -C, –no-color: This option disables the color output, which is helpful in systems with limited terminal support for colors. -u, –user=[username]: To display the processes for a specific user. Just replace ‘[username]’ with the target user’s name. -p, –pid=[PID1,PID2]: Displays information for specified process IDs. For example, let’s check the details of PID 1: htop -p 1 -v, –version: Prints htop version information. -h, –help: This displays a help message with usage information. Kill a Process in htop If you want to kill any process, select it and press the ‘F9’ key or ‘k’ to transmit a kill signal for the selected process. Wrapping Up Htop is a powerful utility for interactively checking system processes in real time. This tutorial briefly discusses how to use the htop command. As htop is not a preinstalled utility in Linux distributions, your first step is to install it using the mentioned commands. Later, we explained how to sort, search, filter, and kill processes from the htop utility. View the full article
-
All UNIX-based operating systems, including Linux, follow the structure that “everything is a file.” These systems treat all the regular files, directories, processes, symbolic links, and devices like external hardware as files. You can create, modify, and delete files using the commands or from the File Manager. Deleting files is essential when you accidentally create multiple files that become unnecessary for the system. So, in this quick blog, we will explain quick ways to delete a file in Linux with no trouble. There are a few methods of deleting the files, so let’s look at them individually with the correct examples. The rm Command You can use the rm command to delete the file from the terminal. For example, you want to delete the “filename.txt” located in the Downloads directory, so first run the below command to open the directory in the terminal: cd ~/Downloads Then, use the following command: rm filename.txt The rm command doesn’t display any output, but you can use the -v option to get the output: rm -v filename.txt If you want to delete multiple files from the current directory, you can mention all those files in a single rm command. For example, to delete three files– file1.txt, file2.txt, file3.txt, please run the below command: rm file1.txt file2.txt file3.txt In case you want to delete all the files with the same extension, then you can run the following command: rm *.txt As the above image shows, we have deleted all the .txt files from the Downloads directory. Moreover, you can use multiple extensions in a single command to delete different types of files simultaneously. For example, let’s delete all the files having the .txt and the .sh extensions: rm -v *.sh *.txt Similarly, you can empty a directory by only adding the * in the rm command: rm * Remember, the above command deletes all files except the directories. Hence, if there is a subdirectory, then the terminal will show the following output: However, you can use the -r option with the rm command to delete the subdirectories. The -r option recursively deletes the directory along with its contents: rm -r * In case you want to get the confirmation before deleting the file, please use the -i option. rm -i * Once you run the command, the system will show a confirmation prompt, so all you have to do is press Y to delete or N to decline it. From the File Manager We recommend deleting the file from the File Manager if you are a Linux beginner. So first open the File Manager and locate the directory: Now select the file and right-click it to get the context menu. Finally, click on the Move to Trash option or press Delete button. A Quick Wrap-up Linux has various commands and methods to delete a file quickly. However, users must know how to delete files to maintain an organized system and minimal storage consumption. This quick tutorial explained two ways of doing so. Initially, we discussed how the rm command works, then explained briefly the step-by-step process of deleting files using the GUI. View the full article
-
The Logrotate utility simplifies the process of administering log files. It relocates and replaces log files to manage their size and organize them while maintaining the information present inside them. For example, it will maintain seven log files to keep daily records for seven days. While rotating the log files, Logrotate deletes irrelevant old logs, preventing them from consuming excessive disk space. It runs periodically in the background to keep your systems organized and clean. So, if you want to learn about Logrotate, this blog is for you. Here, we have included in-depth information about how to set Logrotate on Linux. How To Set Logrotate on Linux Although many Linux distributions have Logrotate as the pre-installed utility. However, if your system does not have Logrotate, please use the following command to install it: sudo apt install logrotate Now, let’s move to the configuration part. There are two kinds of logrotate configurations– global and system-specific. Open the ‘/etc/logrotate.conf’ file using a text editor. It is Logrotate’s primary configuration file, and any changes made to it will affect the whole system. sudo nano /etc/logrotate.conf This file has three key sections: To specify the rotation frequency, i.e., the time it should rotate the logs. It is set to weekly by default, but you can change it to daily, weekly, or monthly. To define the number of rotated files it should keep, adjust the value based on how much historical data you want to retain. For instance, ‘rotate 4’ guides it to keep the latest four rotated log files and delete the earlier ones to free up disk space. The third is to specify the permissions and ownership of the new log files it’ll create. You can tweak these settings according to what suits your system best. For instance, to maintain weekly records for one month(28 days), you must enter: weekly rotate 4 create 0644 root root This way, it will rotate one file weekly and keep four such files. Further, it creates a new log file for currently occurring events while giving the root user and group the read-and-write permissions and read-only for others. If you have to monitor a specific application’s logs for underlying issues. In that case, you can tailor log rotation settings for that application by creating its separate logrotate configuration file. Let’s take an example of conda. First, create its file using: sudo nano /etc/logrotate.d/conda In this file, add configurations specific to the conda logs: /var/log/conda/*.log { weekly rotate 4 compress delaycompress missingok notifempty create 0644 root root } Here, the compress command guides to compress the files so that resulting files take up less space. With the delaycompress command, you can hold the latest rotated file uncompressed to make it convenient for the users to refer to it. The missingok option tells logrotate to ignore the absence of a log file and continue its operations without any error. At last, with notifempty, logrotate won’t rotate any empty log file. The logrotate should run automatically as per the default settings. However, you must confirm it using: nano /etc/cron.daily/logrotate A Quick Wrap-up Knowing the configuration process of the logrotate utility is crucial for system administrators and is also essential for disk management in Linux devices. Hence, this blog explains the approaches used to set logrotate on Linux. You can modify configurations globally and simultaneously change them for specific applications. Moreover, system-specific configurations should be used responsibly because they always override global settings. View the full article
-
Cron is a time-based job scheduler that lets you schedule tasks and run scripts periodically at a fixed time, date, or interval. Moreover, these tasks are called cron jobs. With cron jobs, you can efficiently perform repetitive tasks like clearing cache, synchronizing data, system backup and maintenance, etc. These cron jobs also have other features like command automation, which can significantly reduce the chances of human errors. However, many Linux users face multiple issues while setting up a cron job. So, this article provides examples of how to set up a cron job in Linux. How To Set up a Cron Job Firstly, you must know about the crontab file to set up a cron job in Linux. You can access this file to view information about existing cron jobs and edit it to introduce new ones. Before directly opening the crontab file, use the below command to check that your system has the cron utility: sudo apt list cron If it does not provide an output as shown in the given image, install cron using: sudo apt-get install cron -y Now, verify that the cron service is active by using the command as follows: service cron status Once you are done, edit the crontab to start a new cron job: crontab -e The system will ask you to select a particular text editor. For example, we use the nano editor by entering ‘1’ as input. However, you can choose any of the editors because the factor affecting a cron job is its format, which we’ll explain in the next steps. After choosing an editor, the crontab file will open in a new window with basic instructions displayed at the top. Finally, append the following crontab expression in the file: * * * * * /path/script Here, each respective asterisk(*) indicates minutes, hours, daily, weekly, and monthly. This defines every aspect of time so that the cron job can execute smoothly at the scheduled time. Moreover, replace the terms path and script with the path containing the target script and the script’s name, respectively. Time Format to Schedule Cron Jobs As the time format discussed in the above command can be confusing, let’s discuss its format in brief: In the Minutes field, you can enter values in the range 0-59, where 0 and 59 represent the minutes visible on a clock. For an input number, like 9, the job will run at the 9th minute every hour. For Hours, you can input values ranging from 0 to 23. For instance, the value for 2 PM would be ’14.’ The Day of the Month can be anywhere between 1 and 31, where 1 and 31 again indicate the first and last Day of the Month. For value 17, the cron job will run on the 17th Day of every Month. In place of Month, you can enter the range 1 to 12, where 1 means January and 12 means December. The task will be executed only during the Month you specify here. Note: The value ‘*’ means every acceptable value. For example, if ‘*’ is used in place of the minutes’ field, the task will run every minute of the specified hour. For example, below is the expression to schedule a cron job for 9:30 AM every Tuesday: 30 9 * * 2 /path/script For example, to set up a cron job for 5 PM on weekends in April: 0 17 * 4 0,6-7 /path/script As the above command demonstrates, you can use a comma and a dash to provide multiple values in a field. So, the upcoming section will explain the use of various operators in a crontab expression. Arithmetic Operators for Cron Jobs Regardless of your experience in Linux, you’ll often need to automate jobs to run twice a year, thrice a month, and more. In this case, you can use operators to modify a single cron job to run at different times. Dash(-): You can specify a range of values using a dash. For instance, to set up a cron job from 12 AM to 12 PM, you can enter * 0-12 * * * /path/script. Forward Slash(/): A slash helps you divide a field’s acceptable values into multiple values. For example, to make a cron job run quarterly, you’ll enter * * * /3 * /path/script. Comma(,): A comma separates two different values in a single input field. For example, the cron expression for a task to be executed on Mondays and Wednesdays is * * * * 1,3 /path/script. Asterisk(*): As discussed above, the asterisk represents all values the input field accepts. It means an asterisk in place of the Month’s field will schedule a cron job for every Month. Commands to Manage a Cron Job Managing the cron jobs is also an essential aspect. Hence, here are a few commands you can use to list, edit, and delete a cron job: The l option is used to display the list of cron jobs. The r option removes all cron jobs. The e option edits the crontab file. All the users of your system get their separate crontab files. However, you can also perform the above operations on their files by adding their username between the commands– crontab -u username [options]. A Quick Wrap-up Executing repetitive tasks is a time-intensive process that reduces your efficiency as an administrator. Cron jobs let you automate tasks like running a script or commands at a specific time, reducing redundant workload. Hence, this article comprehensively explains how to create a cron job in Linux. Furthermore, we briefed the proper usage of the time format and the arithmetic operators using appropriate examples. View the full article
-
- cron
- scheduling
-
(and 1 more)
Tagged with:
-
Processes are the running instances of programs that consume system resources. Listing these processes helps you monitor system activity, and troubleshoot issues. That’s why there are multiple tools and utilities in Linux that you can use to list the currently running process. However, many beginners don’t know the exact way to list the process without errors. So, in this short article, we will explain different methods to list the process in Linux. We have divided this section into multiple parts to give you the best commands to list the processes in Linux. The ps Command The ps, or “process status,” is the most common utility to list processes in the terminal: ps -e The -e option guides ps to show every process regardless of whether the user owns those processes. Furthermore, you can customize the ps command to produce additional details using the “aux” options: ps aux The top Command If you desire to view the real-time list of system processes, please use the top command. It continuously updates the process list according to new and completed processes, providing more accurate results: top The above command on execution shows the list of processes as per their CPU consumption. Moreover, You can not interact with the terminal until you press “q” to quit the top utility. The pstree Command The pstree is very different from the above two commands because it displays the hierarchical relationship of processes in a tree-like structure. It helps you visually understand how a process starts and its connection with other active processes. pstree The Glances Tool The Glances tool provides a brief overview of the currently running process. However, you have to install the tool by running the below command: Operating System Command Debian/Ubuntu sudo apt install glances Fedora sudo dnf install glances Arch Linux sudo pacman -Sy glances openSUSE sudo zypper install glances After the successful installation, you can open the Glances by running the following command: glances A Quick Summary Knowing how to list processes can help free up the space and turn off the currently running process. This article covered four ways– the top, ps, pstree, and pgrep commands. You can choose to use any of them according to what suits you best. We recommend you use any commands carefully, or you may get errors. View the full article
-
Linux is a famous OS due to its features, like its robust file management system. It lets you perform various operations such as creating, editing, moving, and renaming those files. However, these features pose no advantage if you cannot locate your desired files. This is quite a common issue, and many users often forget a file’s location. So, this quick tutorial has all the easy methods to find a file in Linux with no hassles. In this section, we have included multiple commands such as find and locate. So let’s take a look at them one by one: The Find Command The find powerful command to search files based on various criteria. For example, let’s search for the Password.txt file located in the Documents directory: cd ~/Documents find Password.txt In case you don’t know the directory of the file, then you can run the below command: find -name Password.txt The above command produces accurate results only if you enter the file name in proper cases. Otherwise, you can run a case-insensitive search by using the -i option: find -iname password.txt Moreover, you can guide the system to search only for files or only for directories by using the -f or -d options, respectively. For files: find -type f -iname password.txt For directories: find -type d -iname password.txt The locate Command The locate is more efficient than find as it scans your system periodically and indexes it in advance. So, whenever you use the locate command, it quickly refers to the index and returns the file location. Locate is not a pre-installed command, so please run the below command to install it: sudo apt install mlocate -y Now, let’s find the Password.txt using the locate command: locate Password.txt Similarly, you can use the -i option to make the command case insensitive: locate -i password.txt The File Manager If you are a Linux beginner, we recommend you to use the File Manager to find a file. For example let’s find the Password.txt file so please open the File Manager. Here, either you can press CTRL + F or click on the search icon to open the search bar: Now, you can search for the Password.txt in the search bar: A Quick Wrap-up It sometimes becomes difficult for Linux users to find a specific file due to the complex file storage. Hence, we have explained three simple methods for finding a file with no hassles. First, one explains the find and locate commands and their functionality. Lastly, we have included the easiest method for Linux beginners to find files right from the File Manager. View the full article
-
Archive(zip) files reduce space consumption to make the data transferable. That’s why most files you download from the web are in zip formats like tar, zip, and rar. However, you first need to unzip these files to access the data. Although a few tools are available to unzip files, Linux contains simple commands that can be used to unzip files quickly. Therefore, in this quick tutorial, we will explain different ways to unzip files in Linux. In this section, we have included commands and graphical tools to unzip files without getting errors. From File Manager If you are new to Linux, we recommend that you use the File Manager to unzip the files. First, open the File Manager and go to the directory where you saved the zip file. Now, right-click on the file; you will get two “extract here” and “extract to” options. So please choose “extract here” to unzip the file in the same directory or “extract to” to unzip the file in any other directory. In case the zip file is password protected, the system will give you a pop-up window to enter the password: The unzip Command If you’re specifically dealing with a zip format file, use the unzip command. Otherwise, you can jump right into the next section. To unzip a file using the unzip command, first navigate to the directory where the zip file is located. For example, let’s open the Downloads directory: cd Downloads Now use the unzip command in the following manner: unzip Music.zip If you want to list the content of a zip file, then please use the -l option: unzip -l Script.zip You can also extract the zip file data in any other directory by using the -d option: unzip Script.zip -d ~/Documents In case the zip file is password protected, you need to use the -P option, including the password in the command: unzip -P 12345 Scripts.zip The tar Command The tar is the second most commonly used archive format after ‘zip’, which makes it equally essential to be aware of. For unzipping ‘tar’ files, Linux provides the tar command that can handle formats like ‘.tar,’ ‘.tgz,’ ‘.taz,’ ‘.tar.xz’, and more. Let’s take an example of a zip file, ‘Scripts.tar,’ and unzip it using the tar command: tar -xvf Scripts.tar Furthermore, if the tar archive is compressed using gzip and bzip2, use the ‘-z’ or ‘-j’ options, respectively. For instance, had the file in the above example been ‘Scripts.tar.gz’ or ‘Scripts.tar.bz2’, we would have used: tar -xvfz Scripts.tar.gz OR tar -xvfj Scripts.tar.bz2 A Quick Wrap-up Unzipping a file is a fundamental task, and as a Linux user, you must know the various methods to unzip a file. This short guide explains the two common commands that let you unzip files of different archive formats. For the zip format, the straightforward approach is via the unzip command, whereas for other formats, you must use the tar command. View the full article
-
Data transmission is one of the most invaluable tasks in today’s internet world. Although numerous tools are available on the web to download files, Linux is one step ahead. The wget utility in Linux is a simple, powerful, and proficient tool for downloading files using download links. The wget command includes various features, such as resuming interrupted downloads, speed and bandwidth customization, encrypted downloads, and simultaneous file downloads. Moreover, it can interact with Rest APIs. So, in this brief tutorial, we will cover all the ways to use the wget command in Linux. How To Use the wget Command in Linux Whether you need a single file or want to download the entire file set, the wget utility helps you achieve both tasks. It also offers a few options to tweak its overall functioning. The standard wget command lets you download a file from a website. For example, to download jquery-3.7.1.js from its official website, please use the wget command: wget https://code.jquery.com/jquery-3.7.1.js The wget command, by default, saves the downloaded files in the current directory with their original names listed on the website. However, you can save it at a specific location or with a particular name through the ‘-O’ option. For instance, you can use the below wget command to save the above file with the name JavaScript.js: wget -O JavaScript.js https://code.jquery.com/jquery-3.7.1.js Similarly, to download the file at another path without changing the current directory, please mention the new file path along with the desired filename: wget -O ~/Downloads/JavaScript.js https://code.jquery.com/jquery-3.7.1.js If your download fails, you can resume it from where it left off using the ‘–continue’ or ‘-c’ option: wget -c https://code.jquery.com/jquery-3.7.1.js While downloading a file, if you’re also performing other online tasks that require sufficient internet bandwidth, use the ‘-limit-rate’ option to limit its speed. wget --limit-rate=50k https://code.jquery.com/jquery-3.7.1.js Here, ’50k’ means limiting the speed to 50KB/s for the specified file. However, you can replace it with your desired limit. This is usually helpful when you do not want the wget command to consume all available bandwidth. The most powerful feature of the wget utility is its ability to download entire websites recursively. You can use the ‘-r’ or ‘–recursive’ option to download all HTML pages, linked files, CSS, and images. For example: wget -r https://code.jquery.com/jquery-3.7.1.js Conclusion The wget command is a powerful and versatile tool for downloading files from URLs. This brief tutorial explains how to use the wget command and its applications. Its prominent feature is recursive website download, but it also allows renaming downloaded files and resuming uninterrupted downloads. Moreover, if you have a low bandwidth, use the ‘–limit-rate’ option to limit the download speed. View the full article
-
Ubuntu is a preferred Linux distribution, especially for programmers and developers. When using Ubuntu 24.04, you must know how to install pip. As a Python developer or user, pip is a Python package manager that allows you to install and manage Python packages for your projects. Besides, when installing a package that requires some dependencies, you might require pip to help install them. Installing pip on Ubuntu 24.04 is straightforward. With only a few commands, you will have pip installed and ready for use. This post shares all the details you should know regarding installing pip. How to Install pip on Ubuntu 24.04 Different circumstances make installing pip on Ubuntu 24.04 a must-know for everyone. If you are a Python developer using Ubuntu 24.04, you inevitably need pip to install and manage Python packages. As a regular Ubuntu 24.04 user, pip helps install package dependencies and is the recommended approach for installing packages by sourcing them from indexes such as PyPI. It’s worth mentioning that Python has two flavors, but for this example, we are focused on installing pip for Python3. Besides, Python3 is the latest flavor and is recommended for any Python activity. For Python 3 packages, including pip, they will have the ‘python3-’ prefix before their name. Below are the steps to follow to install pip on Ubuntu 24.04 Step 1: Update the Ubuntu 24.04 Package List Before installing pip on Ubuntu 24.04, we must update the package list. Doing so helps refresh the sources list, allowing us to access the recent pip version. Run the update command below. $ sudo apt update You will get prompted to enter your password to run the apt command, as it is an administrative task that requires sudo privileges. Once you enter the password, allow the process to complete. Step 2: Install Python3 pip Ubuntu 24.04 has pip in its repository. Since we want to install pip for Python3, not Python2, we must specify it when running the install command. Here’s how you install pip. $ sudo apt install python3-pip Once you run the command, it will execute and fetch the pip package and its dependencies. Once the process is complete, you will have managed to install pip on your Ubuntu 24.04. Step 3: Verify the Installation Although we’ve successfully installed pip on Ubuntu 24.04, we still need to verify the installation. One way to do this is to check the installed pip version. The command below will return the pip version if installed. $ pip3 --version We’ve installed pip 24.0 for this guide. How to Use pip on Ubuntu 24.04 After installing pip, the next task is to understand how to use it for different tasks. Like other packages, pip also has a help page where you will view all the various options and their descriptions. To access the help page, execute the below command. $ pip3 --help You will get an output showing the available options alongside their descriptions. Go through the output to understand the different actions you can take when running pip. For instance, if we want to see the different packages installed on our system, we can list them using the below command. $ pip3 list We then get an output showing the available packages and a brief description of the version. Feel free to explore how to use pip more, depending on your project needs. Conclusion pip is a reliable Python package manager. With pip, you can install and manage Python packages with ease, offering convenience in installing project dependencies. To install pip, specify what Python flavor to use, and then run the install command. This post focuses on installing Python3-pip, and we’ve given the steps to follow, from installing pip to giving an example of how to use it. View the full article
-
Linux is full of commands to perform various tasks with ease, and the reboot command is one of them. The reboot command lets you restart the system in a controlled manner. It has multiple applications, whether you want to troubleshoot issues, apply ongoing updates, or reboot your system. That’s why understanding the reboot command is essential for every Linux user. Indeed, most users don’t know much about the reboot command. This short guide will explore various ways to use the reboot command in Linux, along with some usage scenarios. How To Use the Reboot Command in Linux The reboot command can restart your system. It also offers several other options to customize and control the overall reboot process. Let’s look at some of the most common ways to use the reboot command. To restart your system, you merely need to open the terminal and enter “reboot,” as shown below: reboot On execution, this initiates a standard system restart that will close all running programs and services before shutting down and rebooting the system. In some situations, you need to reboot the system immediately with no delay. However, some ongoing processes will interfere and extend the reboot time. In that case, you can forcefully reboot your system by using the “-f” or “–force” options: sudo reboot -f Please use this command cautiously because it forcefully terminates the running processes without giving them the chance to shut down properly. In case you don’t want to restart the system, then you can use the –poweroff option as shown below: reboot --poweroff Similarly, you can use the -f option with the –poweroff to turn off the system forcefully: reboot -f --poweroff Note: Remember that the –poweroff option will force the system to power off immediately, bypassing the complete graceful shutdown process. Hence, if you don’t want to perform the power off action, please use the halt (-h) option. Whenever you use the -h option, it stops all processes(foreground and background), brings the system to a complete halt, and shuts it down. It’s similar to turning off the device manually but in a controlled manner initiated by the system. reboot -h This command is useful when you plan to shut down the system but intend to wait to restart it. When the Linux system restarts, it records this event in the wtmp file. It keeps track of system logins, reboot events, etc. However, you can prevent the reboot event from being recorded in the wtmp file using the “-n” or “–no-wtmp” option. reboot -n A Quick Recap The reboot command in Linux is a fundamental tool that lets you perform controlled system restarts. This was a brief introduction to the reboot command for a standard system restart, forced restart, system halt and shutdown, and recordless system reboot. Understanding its usage and options allows you to reboot your systems confidently without any hassles. View the full article
-
Linux is a command-based operating system that relies primarily on commands to execute tasks. During a terminal session, you run various commands; noting them is not feasible as it can be time-intensive. That’s why the history command is handy to view previously run commands in the terminal. It helps you recall and reuse earlier commands and troubleshoot unexpected system behavior. So this short blog will briefly explain how to use the history command in Linux, including its usage, options, and some examples. How To Use the history Command in Linux You can run the below command to check the history of the previously executed commands: history The above command, by default, shows a list of up to 1,000 commands. If you wish to view a specific number of commands, go for the below command: history N Where N is the required number of preceding commands. For example, to see the last 3 commands executed, we will enter: history 3 Please combine history with the grep command to search for a particular earlier command. For instance, to search for occurrences of cd: history | grep cd If you want to reuse any previous commands, please check that command’s line number. For example, let’s reuse the cd ~/Documents available in the 9th row: !9 If you want to clear the history, then please use the -c option: history -c Moreover, the ‘-d N’ option deletes a specific entry at N. For example, let’s delete the history from raw 200 to 275: history -d 200-275 A Quick Wrap-up The history command is a valuable tool in Linux’s range of commands. It allows you to recall and manage previously executed commands. This blog demonstrated how to use the history command with practical examples. Furthermore, we explained two primary options to manage the command history. View the full article
-
Synchronizing files and data among multiple servers is crucial for smooth functioning. Fortunately, many tools are available online for file synchronization, and Rsync is one of them. Rsync is one of the most popular and widely used utilities for remotely syncing data in Linux. Rsync features efficient file transfer, preservation of file metadata, updating existing files, partial transfers, and more. This makes Rsync an ideal choice for nearly all administrators. So, this guide will be all about using the Rsync command in Linux without hassles. How To Use the Rsync Command in Linux Most Linux distributions contain the Rsync utility, but you have to install it through the following command: Operating System Command Debian/Ubuntu sudo apt install rsync Fedora sudo dnf install rsync Arch Linux sudo pacman -Sy rsync After completing the installation, please run the below command to initiate data syncing between the source and the target: rsync -o source target Here, you should replace the source with the directory from where you want to synchronize the data and target with the directory where you want to store that data. For example, let’s sync the Videos and Documents directories by running the following command: rsync -o Videos Documents If you want to copy-paste data within the same system, use the following command: sudo rsync -avz /source/path /target/path/ The ‘-a’ or ‘–archive’ keeps the file attributes intact during a data transfer. The ‘-v’ or ‘–verbose’ option is to display what data is being transferred. Although optional, you should use the ‘-z’ or ‘–compress’ option to compress the data during transfer. This aids in speeding up the synchronization process. Let’s take an example and use the above rsync command to synchronize files from the Scripts directory to the Python directory: sudo rsync -avz ~/Scripts ~/Python Moreover, the primary purpose of rsync is to transfer data remotely between two devices or servers connected over a network: rsync -av -e ssh user@remote_host:/source/path/ /target/path Here, the ‘-e ssh’ option commands your system to use the secure shell/SSH for this transaction. Furthermore, if the system encounters any interruption during a remote file transfer, don’t worry. You can resume it through the ‘–partial’ option: rsync --partial -av -e ssh user@remote_host:/source/path/ /target/path Dry Run Rsync initiates the file transfer immediately after you enter a command. Therefore, to avoid any unintended consequences, you should always perform a dry run first. During a dry run, your system simply demonstrates the actions of your command without an actual data transfer. Hence, here you can add the ‘–dry-run’ option to start a dry run. For instance, to see what’s going to happen during a data sync from Python to Scripts directory, use: rsync -avz --dry-run ~/Python ~/Scripts Make Identical Servers In case there are some files in the target directory that are not available in the source directory, This results in non-uniformity, and in some cases, it even causes unnecessary disk consumption. So you can use the ‘–delete’ option to delete the data from the target which is not present at the source. For example: rsync -av --delete /source/path/ /target/path/ Show Progress During Transfers If you want to see the progress of your transfer, enter the ‘–progress’ option to display the progress indicator. For instance, on enabling the progress indicator, the above example will produce the following results: rsync -avz --progress ~/Python ~/Scripts A Quick Summary Mastering rsync commands enables you to efficiently transfer files to both local and remote hosts. It’s a robust tool for synchronizing data across different locations. This guide comprehensively explains how to use the rsync command in Linux. First, we look at rsync’s installation on Linux systems. Then, it comprehensively demonstrates different rsync commands and methods according to the use cases. View the full article
-
Linux is full of commands that allow you to achieve every task with numerous commands. Having these text-based commands is handy; you can unleash the full potential of your Linux system. Moreover, the terminal is the most popular command line interface (CLI) for executing these commands. While working in the terminal, the screen gets cluttered with various commands and their outputs. Hence, erasing everything from the terminal window is a basic yet essential task for users, especially those unfamiliar with the CLI. In this short article, we have included various methods to clear the screen in Linux Clearing the screen is fundamental whether working in the terminal or accessing any remote server via SSH. There are three ways for it, so let’s take a look at all of them: The clear Command The clear is the most straightforward method to wipe the screen: clear After executing the command, the system will immediately clear the terminal window, giving you a blank screen. The Keyboard Shortcut If you prefer keyboard shortcuts over commands, use CTRL+L. Unlike the clear command, this shortcut does not delete any contents of your current terminal window. Instead, it scrolls down the window to make it appear like the screen has been cleared. For example: echo "Hi Prateek" Now, press CTRL+L. The ANSI Escape Sequences- Advanced Method Advanced users or those proficient in terminal interactions can also use ANSI escape sequences to clear the screen. The escape sequence for this is ‘\033[2J’, and it works very similar to the keyboard shortcut. For instance: echo "Hi Prateek, this is a test message." echo -e "\033[2J" In this command, the ‘-e’ option instructs the shell to start interpreting the backslash escapes in the entered sequence. On execution, you’ll get the below result: Conclusion Even a beginner in Linux must know how to clear a terminal screen to navigate efficiently in the CLI environment. This short tutorial contains three methods to do so: the clear command, the CTRL+L keyboard shortcut, and an ANSI escape sequence. The clear command and the keyboard shortcut are the primary approaches, whereas the escape sequence is just an addition for an advanced user. View the full article
-
Understanding and effectively utilizing networking tools in this digital world is crucial to maintaining proper internet functions. Every Linux distribution comes with various preinstalled network tools like host, traceroute, dig, nslookup, etc. These tools help you analyze and troubleshoot arising connectivity issues. The dig or Domain Information Groper command is a versatile DNS lookup utility that allows you to query DNS servers for their records. Subsequently, it helps you diagnose DNS-related problems and gather essential information about domain names. This article will cover how to use the dig command in Linux without hassles. You can use dig commands for tasks like DNS querying, accessing multiple types of DNS records, performing reverse DNS lookups, and more. Hence, let’s divide this section further to explain different use cases. Basic DNS Query The default dig command runs a DNS query to retrieve the DNS records associated with a particular domain name: dig website.com Replace “website.com” with the domain you want to tailor your query. For instance, we will use the dig command below for Google’s domain, “google.com.” dig google.com Specific DNS Records Types There are numerous types of DNS records, but you can query specific DNS record types using the ‘-t’ option. For example, let’s retrieve the mail exchange records for Google: dig -t MX google.com Query a Specific DNS Server If you want to query a specific DNS server, specify its IP address using the ‘@’ symbol in the following manner: dig @8.8.8.8 google.com Here, replace 8.8.8.8 and google.com with your target IP address and domain. On running, you’ll get the results as follows: Reverse DNS Lookup Reverse DNS lookup lets you map an IP address to a domain name, providing information about the domain associated with that IP address. Administrators primarily use it for network troubleshooting, while other uses include email server verification, login and security, and content delivery optimization. To use it, please enter the command below: dig -x IP_address Replace IP_address with your IP address. Again, taking Google’s example, if we put 8.8.8.8 in the dig command: dig -x 8.8.8.8 The last section shows “dns.google,” indicating that the IP address we entered corresponds to Google. Wrapping Up The dig command is a powerful and versatile tool for network administrators and users. It provides various DNS querying features, making it invaluable for network diagnostics. Moreover, we briefly explain querying on a specific server, reverse DNS lookup, and querying according to DNS record types. View the full article
-
- dig
- linux commands
-
(and 1 more)
Tagged with:
-
In Linux, commands help you achieve tasks like troubleshooting network issues, executing scripts, organizing system structure, and more. Moreover, some situations require you to run lengthy commands repeatedly, and typing them consumes much of your time. In this case, the alias command is the savior, creating shortcuts for long commands or a sequence of commands. It also improves productivity and reduces errors. However, many users and even Linux experts have yet to learn how to use the alias command correctly. So, this short tutorial will quickly explain how to use the alias command in Linux without any hassles. The alias Command with Examples The alias command is simple, and you can use it as: alias alias_name='command' Please replace the ‘alias_name’ and ‘command’ with the name of the alias and the target command, respectively. In simple words, alias means the shortcut command you want to create. For instance, you can create the following alias if you frequently use the ‘sudo apt update && upgrade’ command to update the system: alias update='sudo apt update && upgrade' Now, whenever you type and run ‘update’ in the terminal, the system will automatically start updating: The above aliases last only for the current terminal session. However, if you want to make a persisting alias, add it to your shell’s configuration file. Typically, for Bash, it is the ‘.bashrc’ file. Let’s retake the above example to convert ‘update’ to a permanent alias. First, you have to open the configuration file with a text editor: nano ~/.bashrc After that, add the aliases in the following manner: alias update='sudo apt update && upgrade' Finally, save the file and run the ‘source ~/.bashrc’ command to apply the changes. A Quick Wrap-up The alias command in Linux empowers a user to customize the command line experience and enhance productivity. By creating personalized shortcuts, you can easily streamline your workflow and navigate your system. Here, we discussed the method to create temporary and permanent aliases. Furthermore, remember all the mentioned tips to maintain clarity and efficiency. View the full article
-
- alias
- linux commands
-
(and 1 more)
Tagged with:
-
The cat or concatenate command is a versatile utility for combining two or more files. You can also use the cat command to print a file’s content on the terminal without opening it in a text editor. The cat command has various other functionalities like appending to files, displaying the number of lines, creating new files, etc. However, many users, especially beginners, know little about the cat command. So this article has everything a novice needs to know about the cat command in Linux. How To Use Cat Command in Linux As we have mentioned earlier, the cat command is used to display a file’s content. So here is the basic expression of the cat command: cat [options] <file> Now let’s take an example to display the content of the script.txt file: cat script.txt If you have run a script or a piece of code and want to save its output to a file, please run the following command: cat > output.txt If any other file named ‘output.txt’ does not exist in your current directory, this command will first create it. Then, it will save the output of the previously executed command into it. To concatenate multiple files and then display their content, use the following command: cat file.txt filename.txt Along with the file contents, you can show their line numbers using the -n option: cat -n file.txt You can use the below command when you have two files, i.e., file1 and file2, but want to append the content of file2 to file1: cat filename.txt >> file.txt Similarly, you can clone the content of one file to another: cat file.txt > filename.txt A Quick Recap The cat command is a powerful and versatile utility offering multiple features. However, users often are unaware of its true potential, which leaves it underutilized. Therefore, this article briefly explains the cat command, its options, and various use cases. We have demonstrated how to use the cat command to display a file’s content, make a file’s copy, append it to another file, and show the number of lines, etc. View the full article
-
- cat
- linux commands
-
(and 1 more)
Tagged with:
-
YUM, or also known as Yellowdog Updater Modified, is a package management tool developed by Yellowdog Linux. It is the default and widely used software package manager in Fedora, RHEL, CentOS Linux systems, etc. Its primary features allow you to install, upgrade, and uninstall software packages on your devices. YUM has been a reliable tool and evolved into its next-generation version, Dandified YUM(DNF). Furthermore, you can easily access YUM through the command line, making it the preferred choice of most administrators. However, many users still need to discover and want to learn various use cases of YUM. This quick guide will briefly describe YUM in Linux and demonstrate some examples of its use. How to Use YUM in Linux You can install any new software using a simple yum install command followed by your desired package name. For example, to install the r sync utility, we would use: yum install rsync Additionally, you do not need to worry about the dependencies the new packages need because YUM takes care of it all. You can use the below-given command to update any particular package: yum update package_name Please replace ‘package_name’ with the package name you want to update. For instance, let’s update the curl utility: yum update curl Similarly you can completely remove a package from your system through the following command: yum remove package_name Again replace ‘package_name’ like shown in the above section. After executing this command, enter ‘y’ to confirm the removal of your target package and its dependencies. For example, if we have to remove the curl package installed in the previous section, we will run: yum remove curl If you want to view detailed information about a package before installing it immediately, use the yum info command. For example: yum info curl It will display information about Curl’s latest version, release, size, license, and description. You can also take a brief look at the packages installed on your system by running: yum list installed In case you are unable to recall the exact name of your desired package, use the search function as follows: yum search [specific_keyword] Just replace [specific_keyword] with your target keyword. It will show all the matching package names. A Quick Summary YUM is the default package management utility in Fedora, RHEL, CentOS, and other similar Linux distributions that the Yellowdog Linux originally developed. This guide quickly explained YUM in Linux with the help of multiple examples. Here, we demonstrated how to use YUM to install, remove, and upgrade packages on your systems. View the full article
-
- package managers
- linux
-
(and 5 more)
Tagged with:
-
Forum Statistics
67.4k
Total Topics65.3k
Total Posts