{"id":1764,"date":"2021-01-29T11:43:00","date_gmt":"2021-01-29T11:43:00","guid":{"rendered":"http:\/\/linoxide.com\/how-tos\/essential-linux-basic-commands\/"},"modified":"2026-01-29T12:23:43","modified_gmt":"2026-01-29T12:23:43","slug":"essential-linux-basic-commands","status":"publish","type":"post","link":"https:\/\/linoxide.com\/linux-command\/essential-linux-basic-commands\/","title":{"rendered":"Basic Linux Commands You Should Know"},"content":{"rendered":"\n<p>Linux is a family of open-source operating systems, which are built upon the Linux Kernel. It is derived from UNIX and is also known as a UNIX-like operating system. Linux was released in 1991 by Linus Torvalds. You can use it for free, modify and redistribute it.<\/p>\n\n\n\n<p>Linux is secure, fast, and powerful and is used by organizations to store their critical data. Most web hosting services and cloud infrastructure companies use Linux as their back-end. The good thing is you have lots of Linux distributions to choose from such as Ubuntu, Fedora, Debian, Mint, and Pop!_OS.<\/p>\n\n\n\n<p>Although Linux distributions provide a graphical user interface, using the Linux command line interface (CLI) is more effective and efficient. CLI is basically a text-based interface to run commands or programs, manage files and interact with the system. CLI is a synonym for a terminal. Shell program run in the terminal to give command prompt. Popular shell programs are bash, sh, zsh, fish, and csh.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Basic Linux Commands<\/h2>\n\n\n\n<p>Let\u2019s learn here some of the most commonly used Linux commands that will help to run tasks easily, effectively, and more productive.<\/p>\n\n\n\n<p>Have the terminal opened on your favorite Linux distribution to run the commands. Remember commands in Linux are case-sensitive. To open the terminal you can use press CTRL + ALT + T from the keyboard.<\/p>\n\n\n\n<p>Here is the list of Linux basic commands you should know.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. ls Command<\/h3>\n\n\n\n<p>ls is one of the most frequently used basic command in Linux. The ls command-line utility is used to list files and directories that exist inside a directory.<\/p>\n\n\n\n<p>By default, when used without any options, ls lists only the contents of the current directory in alphabetical order without any additional information.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls<\/code><\/pre>\n\n\n\n<p>Type ls \/home\/bob\/Project to see the contents of the directory Project.<\/p>\n\n\n\n<p>You can use options with the ls command for variation in results:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>ls -a<\/code>\u00a0lists hidden files along with other files and directories.<\/li>\n\n\n\n<li><code>ls -al<\/code>\u00a0lists files and directories with file permissions, ownership, and size information.<\/li>\n\n\n\n<li><code>ls -ltr<\/code>\u00a0list file names in the last modification time in reverse order.<\/li>\n<\/ul>\n\n\n\n<p>The output of ls -al<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-rw-r--r-- 1 bob developers 281 Apr&nbsp; 1&nbsp; 2020 \/source\/project\/learn.py<\/code><\/pre>\n\n\n\n<p>The owner (ie bob) has read and write permissions, other members of the group have read permissions, and the rest of the world has read permissions on the file. The file is owned by the user named bob and belongs to the developers group. The total size of the file is 281 bytes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. cd Command<\/h3>\n\n\n\n<p>cd stands for change directory, which is used to change the current working directory. The cd command is used to navigate through Linux files and directories. You need to specify either the full path of the target directory or the directory name you want to change to.<\/p>\n\n\n\n<p>If you are in the \/home\/bob\/Documents directory and need to go to the Photos subdirectory, then type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd Photos<\/code><\/pre>\n\n\n\n<p>Use the absolute path to change directory, change to \/home\/bob\/Pictures directory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd \/home\/bob\/Pictures<\/code><\/pre>\n\n\n\n<p>Some shortcuts that you can use for easy navigation:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>cd ..<\/code>\u00a0moves one directory up.<\/li>\n\n\n\n<li><code>cd<\/code>\u00a0moves to the home folder.<\/li>\n\n\n\n<li><code>cd -<\/code>\u00a0switch to the parent directory<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3. mkdir Command<\/h3>\n\n\n\n<p>The mkdir stands for make directory. The mkdir command is used to create a new directory in Linux.<\/p>\n\n\n\n<p>When you type&nbsp;<code>mkdir Pop<\/code>, it will create a directory named Pop in the current directory. Whereas, the following Linux command will create a directory named Source inside the Documents directory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir Documents\/Source<\/code><\/pre>\n\n\n\n<p>Use -p option to create the entire directory structure. For example to create a directory 2020 and its sub-directory Source in the existing Documents directory, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir -p Documents\/2020\/Source<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. cat Command<\/h3>\n\n\n\n<p>The cat stands for concatenate. It is one of the basic command in the Linux operating system. The cat command is used to concatenate files, view the content of a file, create a new file, or redirect output in files.<\/p>\n\n\n\n<p>Type cat command followed by a file name to see the contents of the file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat users.txt<\/code><\/pre>\n\n\n\n<p>The cat command can also be used to perform some advanced operations, such as:<\/p>\n\n\n\n<p>To create a new file named file1.txt, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat &gt; file1.txt<\/code><\/pre>\n\n\n\n<p>The existing contents of the department.txt file will be overwritten by the contents of users.txt:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat users.txt &gt; department.txt<\/code><\/pre>\n\n\n\n<p>To convert the content of file users.txt from lowercase to uppercase and store it in output.txt, use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat users.txt | tr a-z A-Z &gt; output.txt<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5. df Command<\/h3>\n\n\n\n<p>The df stands for disk filesystem. It is used to get a complete summary of used and available disk space of the file system in your Linux computer.<\/p>\n\n\n\n<p>Options can be used with the df command to get variations in the output such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>-a<\/code>\u00a0displays all file systems.<\/li>\n\n\n\n<li><code>-h<\/code>\u00a0displays output in a human-readable format.<\/li>\n\n\n\n<li><code>-T<\/code>\u00a0displays file system type.<\/li>\n\n\n\n<li><code>-m<\/code>\u00a0displays output in mebibyte (MiB).<\/li>\n\n\n\n<li><code>-g<\/code>\u00a0displays output in gibibyte (GiB).<\/li>\n<\/ul>\n\n\n\n<p>Check disk usage information of a particular file system, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>df \/dev\/sda5<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">Output <code>Filesystem 1K-blocks Used&nbsp; &nbsp; &nbsp; &nbsp; Available Use%&nbsp; Mounted on \/dev\/sda5 &nbsp; 40503552&nbsp; &nbsp; 9132528 &nbsp; 29283856&nbsp; 24% \/<\/code><\/pre>\n\n\n\n<p>Here, \/dev\/sda5 has a total size of 40503552, the used size is 9132528, and the available size is 29283856. The file system has used 24% of the total allocated space and it is mounted on \/.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6. du Command<\/h3>\n\n\n\n<p>Use the du (stands for disk usage) command to gain disk usage information of a particular file or directory on your Linux computer. By default, the du command displays disk usage information in the number of blocks used by a file. Use the&nbsp;<code>-h<\/code>&nbsp;option with this command to display output in a human-readable format.<\/p>\n\n\n\n<p>Specify the file name or directory name to display its disk usage.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>du -h \/var\/log\/apache\/access.log<\/code> <code>du -h \/var\/log<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">7. cp Command<\/h3>\n\n\n\n<p>The cp command is used to copy files and directories from the source directory to another location. By default, it copies only the given file or directory, but you can use the -r option to copy a directory along with its subdirectories.<\/p>\n\n\n\n<p>The following command copy the file users.txt from the current working directory to the Documents\/records directory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cp users.txt Documents\/records\/<\/code><\/pre>\n\n\n\n<p>To create a copy of the file file2.txt with the name file2_backup.txt in your current working directory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cp file2.txt file2_backup.txt<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">8. mv Command<\/h3>\n\n\n\n<p>Use the mv (stands for move) command to move files or directories from the source to the destination directory. It can be used to rename a file\/directory.<\/p>\n\n\n\n<p>The following mv command moves the users.txt file to the Documents\/records directory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mv users.txt Documents\/records<\/code><\/pre>\n\n\n\n<p>To rename the employees.txt file to users.txt:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mv employees.txt users.txt<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">9. rm Command<\/h3>\n\n\n\n<p>Use the rm (stands for remove) command to remove the given file, multiple files, or a group\/type of files. By default, the rm command does not require user confirmation to delete a file, but you can enable user confirmation using the -i option.<\/p>\n\n\n\n<p>Options can be used with the rm command for the following needs:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>-i<\/code>\u00a0deletes files in interactive mode.<\/li>\n\n\n\n<li><code>-f<\/code>\u00a0forcefully removes the write-protected file.<\/li>\n\n\n\n<li><code>-r<\/code>\u00a0recursively deletes files, directories, and subdirectories in the specified parent directory.<\/li>\n\n\n\n<li><code>-d<\/code>\u00a0deletes the specified empty directory.<\/li>\n<\/ul>\n\n\n\n<p>Removes the file named documents.txt from the current directory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rm documents.tx<\/code><\/pre>\n\n\n\n<p>To remove directories and their contents recursively, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rm -r Documents<\/code><\/pre>\n\n\n\n<p>To remove the directory without being prompted, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rm -rf dir1<\/code><\/pre>\n\n\n\n<p>The rm-rf command should be used with caution.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">10. Man &amp; help Command<\/h3>\n\n\n\n<p>Use the man command to display the user manual of the Linux command. Almost all the Linux commands have man pages, which is a kind of documentation that is displayed on the terminal. The Linux commands manual page explains what a particular command does, syntax, and accepted arguments.<\/p>\n\n\n\n<p>Type man followed by the command name to display the command user manual page.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>man mkdir<\/code><\/pre>\n\n\n\n<p>Similarly, you can also use the \u2013-help option to display the help pages of a particular command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir --help<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">11. chmod command<\/h3>\n\n\n\n<p>The chmod command is used to change the mode (permission) of a file. The basic permissions a file can have are r(read), w(write), and x(execute).<\/p>\n\n\n\n<p>Using numeric mode you can set read (value is 4), write (value is 2 and execute (value is 1) permissions for owner, group and all others.<\/p>\n\n\n\n<p>For example to give file1.txt owner and group read and write permissions and only read permission to all others, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chmod 664 file1.txt<\/code><\/pre>\n\n\n\n<p>You may use -R option to recursively&nbsp;set permissions for all files and directories in a given directory.<\/p>\n\n\n\n<p>To make the file executable, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chmod +x myscript.sh<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">12. chown command<\/h3>\n\n\n\n<p>The chown command is used to change file and directory ownership in Linux.<\/p>\n\n\n\n<p>To change both owner and group of file, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chown ownername:groupname filename<\/code><\/pre>\n\n\n\n<p>You may use -R option to recursively&nbsp;set ownership for all files and directories in a given directory.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">13. pwd Command<\/h3>\n\n\n\n<p>pwd stands for present working directory. The pwd command prints the absolute path of the current directory on your Linux terminal. The present working directory is the directory in which you are currently working.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pwd<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">Output <code>\/home\/linuxopsys<\/code><\/pre>\n\n\n\n<p>In the example \/home\/linuxopsys is the current directory.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">14. uname Command<\/h3>\n\n\n\n<p>Use the uname (stands for UNIX name) command to display fundamental information about your Linux computer. By default, this command prints only the type of the operating system, such as Linux. You can use different options with this command to print other information about your computer such as OS, kernel version, machine name, network, and so on.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>-a<\/code>\u00a0display all information about your computer.<\/li>\n\n\n\n<li><code>-s<\/code>\u00a0display Linux kernel name.<\/li>\n\n\n\n<li><code>-m<\/code>\u00a0displays machine information.<\/li>\n\n\n\n<li><code>-i<\/code>\u00a0display hardware platform information.<\/li>\n<\/ul>\n\n\n\n<p>The output of&nbsp;<code>uname -a<\/code>&nbsp;command on my machine:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Linux linux 5.13.0-37-generic #42~20.04.1-Ubuntu SMP Tue Mar 15 15:44:28 UTC 2022 x86_64 x86_64 x86_64 GNU\/Linux<\/code><\/pre>\n\n\n\n<p>All system information including OS type, name, user name, kernel release, and hardware platform is displayed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">15. who Command<\/h3>\n\n\n\n<p>Use the who command to list currently logged-in users on your Linux computer. This command also supports few options to display specific information, such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>-a<\/code>\u00a0displays all available information about logged-in users.<\/li>\n\n\n\n<li><code>-b<\/code>\u00a0displays boot time.<\/li>\n\n\n\n<li><code>-H<\/code>\u00a0displays header names.<\/li>\n<\/ul>\n\n\n\n<p>The output of who command looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root pts\/0 2022-04-28 01:30 (192.168.1.10) bob pts\/1 2022-04-28 02:40 (192.168.1.22) linuxopsys pts\/2 2022-04-28 02:05 (192.168.1.22)<\/code><\/pre>\n\n\n\n<p>It shows 3 users with their logged in date and time.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">16. uptime Command<\/h3>\n\n\n\n<p>Use the uptime command to display the current system time, the duration for which the system has been up, the number of logged-in users, and average load time for 1, 5, and 15-minute intervals. This Linux command retrieves information from the \/proc\/uptime file.<\/p>\n\n\n\n<p>The output of uptime command from my system:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>17:11:28 up 6 days,&nbsp; 3:23,&nbsp; 1 user,&nbsp; load average: 0.00, 0.01, 0.00<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">17. hostname Command<\/h3>\n\n\n\n<p>Use hostname command to display the Domain Name System (DNS) name and set the hostname or Network Information System (NIS) of your system.<\/p>\n\n\n\n<p>Display host name and domain name, type:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>hostname<\/code> <code>linuxopsys<\/code><\/pre>\n\n\n\n<p>Some distributions allow you to set hostname for your machine, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo hostname NEW_HOSTNAME<\/code><\/pre>\n\n\n\n<p>You can replace NEW_HOSTNAME with your actual machine name.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">18. top, htop Command<\/h3>\n\n\n\n<p>Use the top or htop commands to monitor the server\u2019s processes or vital system resources in real-time. Both these commands are used for the same purpose, but their output is different. The default output displays information about top CPU-consuming processes along with RAM usage.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>top<\/code><\/pre>\n\n\n\n<p>The command also displays system up time, load average, number of logged in users, memory, total tasks, and running tasks.<\/p>\n\n\n\n<p>Htop is an improved version of the top command. It display colorful text and allows for output scrolling. Htop doesnt comes preinstalled on most Linux distros.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">19. touch Command<\/h3>\n\n\n\n<p>Use the touch command to create an empty file on your Linux computer, or to modify the timestamp of a file. The primary function of this command is to update file timestamps, but it is most commonly used to create a file. The touch command can update access and modification timestamps of the specified file, and create the file if it does not already exist.<\/p>\n\n\n\n<p>To create a new empty file named install.doc, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>touch install.doc<\/code><\/pre>\n\n\n\n<p>In this example, the modification time of the file updates.txt is updated to the current time.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>touch -m updates.txt<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">20. zip and unzip Command<\/h3>\n\n\n\n<p>Use the zip command-line utility to create an archive of files, and the unzip command for uncompressing a zip archive. The zip command can also be used to modify a zip archive.<\/p>\n\n\n\n<p>To create a zip archive named users.zip from the specified files:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>zip users.zip output.txt install.doc newfiles.txt updates.txt<\/code><\/pre>\n\n\n\n<p>To extract the contents of the users.zip archive to the current directory:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>unzip users.zip<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">21. tar Command<\/h3>\n\n\n\n<p>Use the tar command to create a compressed or uncompressed archive of specified files. You can also use this command to modify, maintain, or extract tar archives. Tar archives can combine multiple files or directories into a single file.<\/p>\n\n\n\n<p>The tar command provides multiple options to create a tarball:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>-c creates an archive.<\/li>\n\n\n\n<li>-x extracts the archive.<\/li>\n\n\n\n<li>-f assigns filename to the archive.<\/li>\n\n\n\n<li>-t displays files in an archive.<\/li>\n<\/ul>\n\n\n\n<p>To create an uncompressed archive file named users.tar of the specified files.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tar cf users.tar updates.txt newfiles.txt<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">22. ln Command<\/h3>\n\n\n\n<p>Use the ln command for creating hard and soft links to existing files or directories. By default, this command creates hard links. Specify the -s option to create symbolic or soft links.<\/p>\n\n\n\n<p>To create a symbolic link from the updates.txt file to the newitems.txt file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ln -s updates.txt newitems.txt<\/code><\/pre>\n\n\n\n<p>Here we can see the symlink that we created in the previous example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ls -l newitems.txt<\/code> <code>lrwxrwxrwx 1 linuxopsys linuxopsys 11 Apr 14 13:53 newitems.txt -&gt; updates.txt<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">23. sudo Command<\/h3>\n\n\n\n<p>Use the sudo command to execute commands as root or another Linux user, as specified in your security policy. This command allows you to execute commands that otherwise require a root password.<\/p>\n\n\n\n<p>Specify the command that requires root permissions after the sudo command. To run the useradd command as sudo to create a new user named bob:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo useradd bob<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">24. apt Command<\/h3>\n\n\n\n<p>Use the apt (stands for advanced package tool) command to install, update, or delete packages on Ubuntu and Debian Linux distributions.<\/p>\n\n\n\n<p>Some of the most commonly used apt commands are apt update, apt upgrade, apt install, apt remove, apt list, and apt search.<\/p>\n\n\n\n<p>To update the package index by pulling the latest updates from the APT repository:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update<\/code><\/pre>\n\n\n\n<p>To install the latest updates to all Linux packages:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt upgrade<\/code><\/pre>\n\n\n\n<p>Let\u2019s use apt command to install a package. To install the htop application, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install htop<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">25. dnf Command<\/h3>\n\n\n\n<p>DNF is&nbsp;a software package manager and is the successor to YUM (Yellow-Dog Updater Modified). Use the dnf (stand for dandified yum) command to install, update, or delete packages on Red Hat-based Linux distributions.<\/p>\n\n\n\n<p>To install the latest updates to all Red Hat Linux packages:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf upgrade<\/code><\/pre>\n\n\n\n<p>To remove the package epel-release:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf remove epel-release<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">26. useradd Command<\/h3>\n\n\n\n<p>Use the useradd command to add new users to your Linux system. This command enables you to add a new user with specific group preferences, user ID (UID), and login shell. When you run this command without any option, it creates a user using the default account settings specified in the \/etc\/default\/useradd file.<\/p>\n\n\n\n<p>To create a new user named steve that has GID 1000, and UID 1021, and will expire on 31<sup>st<\/sup>&nbsp;May 2022:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo useradd -g 1000 -u 1021 -e 2022-05-31 steve<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">27. groupadd Command<\/h3>\n\n\n\n<p>Use the groupadd command to add a new group to your Linux system. This command enables you to add a new group with specific group preferences and override default \/etc\/login.def default values. When you create a new user group using this command, it adds a new entry in the \/etc\/group file.<\/p>\n\n\n\n<p>To create a new group named docs that has GID 1018:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo groupadd -g 1018 docs<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">28. usermod Command<\/h3>\n\n\n\n<p>Use the usermod command to change the properties of existing users in Linux. Using this command, you can modify the password, primary group, login directory, expiry date, and other user attributes. You can also add a user to an existing group using this command.<\/p>\n\n\n\n<p>To add the user steve to sudo group, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo usermod -aG sudo steve<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">29. ps Command<\/h3>\n\n\n\n<p>Use the ps command to check the status of the active processes on your Linux system, and display information about these processes. Administrators can use this information to kill the processes or to set process priorities.<\/p>\n\n\n\n<p>To show all running processes in the default output format:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ps<\/code><\/pre>\n\n\n\n<p>To display all running processes in full format:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ps -af<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">30. kill Command<\/h3>\n\n\n\n<p>Use the kill command to manually terminate a given process. It is located in \/bin\/kill and it sends signals to another process that terminates the specified process.<\/p>\n\n\n\n<p>To display all available signals:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kill -l<\/code><\/pre>\n\n\n\n<p>To kill the PID 257:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kill 257<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">31. ping Command<\/h3>\n\n\n\n<p>Use the ping, also known as the Packet Internet Groper, command to check network connectivity between two computers. You can use this command to troubleshoot connectivity, name resolution, and reachability. It accepts an IP address or an URL as an input.<\/p>\n\n\n\n<p>To check network connectivity to 172.168.1.1 IP address and send 5 data packets:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ping -c 5 172.168.1.1<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">32. vi and nano Command<\/h3>\n\n\n\n<p>Use the vi and nano commands to create a new file, read a file, or edit an existing file. Vi is the default text editor for several Linux distributions and it is very simple to use. Nano is a terminal-based text editor that is ideal for making some changes to any files or creating basic plain text files.<\/p>\n\n\n\n<p>To open the existing file or to create a new file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vi updates.txt<\/code> or <code>nano filename.txt<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">33. history Command<\/h3>\n\n\n\n<p>Use the history command to view the history of all the previously executed terminal commands that you run. The maximum number of entries that BASH should store can be defined in your .bashrc file. Linux commands that you execute are considered events and every event is associated with an event number. You can recall, remove, or change commands using their event numbers.<\/p>\n\n\n\n<p>To list the last 5 commands, including itself:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>history 5<\/code><\/pre>\n\n\n\n<p>To remove the history of event number 1525:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>history -d 1525<\/code><\/pre>\n\n\n\n<p>Note: history command behavior may change depending on the shell you are being used.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">34. passwd Command<\/h3>\n\n\n\n<p>Use the passwd command to change the user account password. A normal user can change only their own password, but the root user or user with sudo privileges can change the password of any user account. This command can also be used to delete or expire an account password.<\/p>\n\n\n\n<p>To change the password for the user bob:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo passwd bob<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">35. which Command<\/h3>\n\n\n\n<p>Use the which command to locate the executable file of the specified command. This command searches for the executable file location in the $PATH environment variable. The which command returns any of the following status:<\/p>\n\n\n\n<p>To display executable file locations for useradd command, type:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>which useradd<\/code> <code>\/usr\/sbin\/useradd<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">36. less Command<\/h3>\n\n\n\n<p>Use the less command to view the contents of a file one screen at a time, starting at the beginning. This command provides the capability of both backward and forward navigation. The less command has quick file access because it does not access the entire file if the file is large.<\/p>\n\n\n\n<p>To display the contents of the updates.txt file one screen at a time.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>less updates.txt<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">37. tail Command<\/h3>\n\n\n\n<p>Use the tail command to view the contents of a file, starting at the bottom. By default, it displays the last 10 lines of the file, but you can change this default behavior. The tail command can also be used to monitor the file. When you add new lines to the file, then the display is updated.<\/p>\n\n\n\n<p>To display the last 10 lines of the file updates.txt:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tail updates.txt<\/code><\/pre>\n\n\n\n<p>To display the last 15 lines of the file access.log:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tail -n 15 access.log<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">38. head Command<\/h3>\n\n\n\n<p>Use the head command to display the contents of a file, starting at the beginning. By default, it displays the first 10 lines of the file, but you can change this default behavior.<\/p>\n\n\n\n<p>To display the first 10 lines of the file updates.txt:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>head updates.txt<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">39. grep Command<\/h3>\n\n\n\n<p>Use the grep, also known as global regular expression print, the command to search for a word or string of characters in a file or directory. The search pattern is termed regular expression. When the grep command finds a matching string in the file, then this command prints the line that contains the string.<\/p>\n\n\n\n<p>To search for the string \u2018welcome\u2019 in the file log.txt:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep welcome log.txt<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">40. diff Command<\/h3>\n\n\n\n<p>Use the diff command to do a line-by-line comparison of two files and display their differences. You can also use this command to compare the contents of Linux directories.<\/p>\n\n\n\n<p>To show differences between two files named source.java and newsource.java, type<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">diff \/dir1\/source.java \/dir2\/newsource.java<\/pre>\n\n\n\n<p>To show differences between Documents and Docs directories.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>diff Documents\/ Docs<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">41. find Command<\/h3>\n\n\n\n<p>Use the find command to search and locate the files and directories that match the specified conditions. This command enables you to search using file or folder name, creation date, modification date, permissions, and owner.<\/p>\n\n\n\n<p>To search the file named program.py in the \/home\/linuxopsys\/projects directory, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>find \/home\/linuxopsys\/projects -type f -name program.py<\/code><\/pre>\n\n\n\n<p>To search for files with given permissions in the current directory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>find . -perm 664<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">42. echo Command<\/h3>\n\n\n\n<p>Use the echo command to display the specified text or string on the terminal. This command is most commonly used in batch files and scripting languages to display standard text output. You can also use this command to display the values of an environment variable.<\/p>\n\n\n\n<p>To print the string \u201cThis is a sample string\u201d on the terminal:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>echo \"This is a sample string\"<\/code> <code>This is a sample string<\/code><\/pre>\n\n\n\n<p>To print the value of the PATH environment variable:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo $PATH<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/sbin:\/bin:\/usr\/games:\/usr\/local\/games:\/snap\/bin<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">43. shutdown, reboot Command<\/h3>\n\n\n\n<p>Use the shutdown command to gracefully and securely shut down your Linux computer.<\/p>\n\n\n\n<p>Use the reboot command to restart your Linux computer. You can also use the shutdown -r command to restart your computer using the shutdown command.&nbsp;&nbsp;<\/p>\n\n\n\n<p>To restart your system after 5 minutes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>shutdown -r +5<\/code><\/pre>\n\n\n\n<p>To immediately restart your computer:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>reboot<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">44. Alias<\/h3>\n\n\n\n<p>The Alias command allows you to define temporary aliases for current sessions. It allows you to execute one or more commands.<\/p>\n\n\n\n<p>Create a new alias named \u2018lsall\u2019, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>alias lsall=\"ls -a\"<\/code><\/pre>\n\n\n\n<p>Lists all aliases for the current session:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>alias<\/code><\/pre>\n\n\n\n<p>Note: Alias behavior may change depending on the shell you are being used. It is traditionally used in bash shell.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">45. exit<\/h3>\n\n\n\n<p>The exit command ends a shell session and closes the terminal you are using<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>exit<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">46. wget command<\/h3>\n\n\n\n<p>The wget command is used to retrieve or download content from the internet.<\/p>\n\n\n\n<p>To download WordPress using wget, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wget https:\/\/wordpress.org\/latest.tar.gz<\/code><\/pre>\n\n\n\n<p>The latest.tar.gz file will be downloaded to the current directory.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">47. clear command<\/h3>\n\n\n\n<p>The clear command is used in Linux to clear the terminal screen. This is similar to cls command in other operating systems.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>clear<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p>For a beginner to get started is to learn a few basic commands. If you are unsure about any commands always refer to its man pages.<\/p>\n\n\n\n<p>Thanks for reading, please share your favorite Linux commands in the comment section.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux is a family of open-source operating systems, which are built upon the Linux Kernel. It is derived from UNIX and is also known as a UNIX-like operating system. Linux was released in 1991 by Linus Torvalds. You can use it for free, modify and redistribute it. Linux is secure, fast, and powerful and is used by organizations to store their critical data. Most web hosting services and cloud infrastructure companies use Linux as their back-end. The good thing is you have lots of Linux distributions to choose from such as Ubuntu, Fedora, Debian, Mint, and Pop!_OS. Although Linux distributions<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"none","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":""},"categories":[27],"tags":[],"class_list":["post-1764","post","type-post","status-publish","format-standard","hentry","category-linux-command"],"_links":{"self":[{"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/posts\/1764","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/comments?post=1764"}],"version-history":[{"count":1,"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/posts\/1764\/revisions"}],"predecessor-version":[{"id":1772,"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/posts\/1764\/revisions\/1772"}],"wp:attachment":[{"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/media?parent=1764"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/categories?post=1764"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linoxide.com\/wp-json\/wp\/v2\/tags?post=1764"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}