Top 50 Linux Commands you must know as a regular user
Here, let us see the top 50 linux commands, used on regular basis
- ls – The most frequently used command in Linux to list directories
- pwd – Print working directory command in Linux
- cd – Linux command to navigate through directories
- mkdir – Command used to create directories in Linux
- mv – Move or rename files in Linux
- cp – Similar usage as mv but for copying files in Linux
- rm – Delete files or directories
- touch – Create blank/empty files
- ln – Create symbolic links (shortcuts) to other files
- cat – Display file contents on the terminal
- clear – Clear the terminal display
- echo – Print any text that follows the command
- less – Linux command to display paged outputs in the terminal
- man – Access manual pages for all Linux commands
- uname – Linux command to get basic information about the OS
- whoami – Get the active username
- tar – Command to extract and compress files in Linux
- grep – Search for a string within an output
- head – Return the specified number of lines from the top
- tail – Return the specified number of lines from the bottom
- diff – Find the difference between two files
- cmp – Allows you to check if two files are identical
- comm – Combines the functionality of diff and cmp
- sort – Linux command to sort the content of a file while outputting
- export – Export environment variables in Linux
- zip – Zip files in Linux
- unzip – Unzip files in Linux
- ssh – Secure Shell command in Linux
- service – Linux command to start and stop services
- ps – Display active processes
- kill and killall – Kill active processes by process ID or name
- df – Display disk filesystem information
- mount – Mount file systems in Linux
- chmod – Command to change file permissions
- chown – Command for granting ownership of files or folders
- ifconfig – Display network interfaces and IP addresses
- traceroute – Trace all the network hops to reach the destination
- wget – Direct download files from the internet
- ufw – Firewall command
- iptables – Base firewall for all other firewall utilities to interface with
- apt, pacman, yum, rpm – Package managers depending on the distro
- sudo – Command to escalate privileges in Linux
- cal – View a command-line calendar
- alias – Create custom shortcuts for your regularly used commands
- dd – Majorly used for creating bootable USB sticks
- whereis – Locate the binary, source, and manual pages for a command
- whatis – Find what a command is used for
- top – View active processes live with their system usage
- useradd and usermod – Add new user or change existing users data
- passwd – Create or update passwords for existing users
The ls command in Linux
The ls command is used to list files and directories in the current working directory. This is going to be one of the most frequently used Linux commands you must know of.
The pwd command in Linux
The pwd command allows you to print the current working directory on your terminal. It’s a very basic command and solves its purpose very well.
The cd command in Linux
While working within the terminal, moving around within directories is pretty much a necessity. The cd command is one of the important Linux commands you must know and it will help you to navigate through directories. Just type cd followed by directory as shown below.
root@webhostc:~# cd <directory path>
As you can see in the above command, I simply typed cd /etc/ to get into the /etc directory. We used the pwd command to print the current working directory.
The mkdir command in Linux
The mkdir command allows you to create directories from within the terminal. The default syntax is mkdir followed by the directory name.
root@webhostc:~# mkdir <folder name>
The cp and mv commands
The cp and mv commands are equivalent to the copy-paste and cut-paste in Windows. But since Linux doesn’t really have a command for renaming files, we also make use of the mv command to rename files and folders.
root@webhostc:~# cp <source> <destination>
In the above command, we created a copy of the file named Sample. Let’s see how what happens if we use the mv command in the same manner. For this demonstration, I’ll delete the Sample-Copy file.
root@webhostc:~# mv <source> <destination>
In the above case, since we were moving the file within the same directory, it acted as rename. The file name is now changed.
The rm command in Linux
In the previous section, we deleted the Sample-Copy file. The rm command is used to delete files and folders and is one of the important Linux commands you must know.
root@webhostc:~# rm -f<file name> root@webhostc:~# rm -rf <folder/directory name>
The touch command in Linux
To create a new file, the touch command will be used. The touch keyword followed by the file name will create a file in the current directory.
root@webhostc:~# touch <file name>
The ln command in Linux
To create a link to another file, we use the ln command. This is one of the important Linux commands that you should know if you’re planning to work as a Linux administrator.
root@webhostc:~# ln -s <source path> <link name>
The basic syntax involves using the -s parameter so we can create a symbolic link or soft link.
The cat, echo, and less commands
When you want to output the contents of a file, or print anything to the terminal output, we make use of the cat or echo commands. Let’s see their basic usage. I’ve added some text to our New-File that we created earlier.
root@webhostc:~# cat <file name> root@webhostc:~# echo <Text to print on terminal>
As you can see in the above example, the cat command when used on our “New-File”, prints the contents of the file. At the same time, when we use echo command, it simply prints whatever follows after the command.
The less command is used when the output printed by any command is larger than the screen space and needs scrolling. The less command allows use to break down the output and scroll through it with the use of the enter or space keys.
The simple way to do this is with the use of the pipe operator (|).
root@webhostc:~# cat /boot/grub/grub.cfg | less
The man command in Linux
The man command is a very useful Linux command you must know. When working with Linux, the packages that we download can have a lot of functionality. Knowing it all is impossible.
The man pages offer a really efficient way to know the functionality of pretty much all the packages that you can download using the package managers in your Linux distro.
root@webhostc:~# man <command>
The uname and whoami commands
The uname and whoami commands allow you to know some basic information which comes really handy when you work on multiple systems. In general, if you’re working with a single computer, you won’t really need it as often as someone who is a network administrator.
Let’s see the output of both the commands and the way we can use these.
root@webhostc:~# uname -a
The parameter -a which I’ve supplied to uname, stands for “all”. This prints out the complete information. If the parameter is not added, all you will get as the output is “Linux”.
The tar, zip, and unzip commands
The tar command in Linux is used to create and extract archived files in Linux. We can extract multiple different archive files using the tar command.
To create an archive, we use the -c parameter and to extract an archive, we use the -x parameter. Let’s see it working.
root@webhostc:~# tar -cvf <archive name> <files seperated by space>
root@webhostc:~# tar -xvf <archive name>
In the first line, we created an archive named Compress.tar with the New-File and New-File-Link. In the next command, we have extracted those files from the archive.
Now coming to the zip and unzip commands. Both these commands are very straight forward. You can use them without any parameters and they’ll work as intended. Let’s see an example below.
root@webhostc:~# zip <archive name> <file names separated by space> root@webhostc:~# unzip <archive name>
The grep command in Linux
If you wish to search for a specific string within an output, the grep command comes into the picture. We can pipe (|) the output to the grep command and extract the required string.
root@webhostc:~# <Any command with output> | grep "<string to find>"
The head and tail commands
When outputting large files, the head and the tail commands come in handy. I’ve created a file named “Words” with a lot of words arranged alphabetically in it. The head command will output the first 10 lines from the file, while the tail command will output the last 10. This also includes any blank lines and not just lines with text.
root@webhostc:~# head <file name> root@webhostc:~# tail <file name>
As you can see, the head command showed 10 lines from the top of the file.
The tail command outputted the bottom 10 lines from the file.
The diff, comm, and cmp commands
Linux offers multiple commands to compare files. The diff, comm, and cmp commands compare differences and are some of the most useful Linux commands you must know. Let’s see the default outputs for all the three commands.
root@webhostc:~# diff <file 1> <file 2>
As you can see above, I’ve added a small piece of text saying “This line is edited” to the New-File-Edited file.
root@webhostc:~# cmp <file 1> <file 2>
root@webhostc:~# comm <file 1> <file2>
By the looks of it, comm command makes the most sense when we’re trying to compare larger files and would like to see everything arranged together.
The sort command in Linux
The sort command will provide a sorted output of the contents of a file. Let’s use the sort command without any parameters and see the output.
The basic syntax of the sort command is:
root@webhostc:~# sort <filename>
The export command in Linux
The export command is specially used when exporting environment variables in runtime. For example, if I wanted to update the bash prompt, I’ll update the PS1 environment variable. The bash prompt will be updated with immediate effect.
root@webhostc:~# export <variable name>=<value>
If for some reason, your bash prompt doesn’t update, just type in bash and you should see the updated terminal prompt.
The ssh command in Linux
The ssh command allows us to connect to an external machine on the network with the use of the ssh protocol. The basic syntax of the ssh command is:
root@webhostc:~#username@ipaddress or root@webhostc:~#username@ipaddress -p 22
Where -p represent the ssh port number, it is used only id default ssh port is customized for security reasons
The service command in Linux
The service command in Linux is used for starting and stopping different services within the operating system. The basic syntax of the command is as below.
root@webhostc:~# service ssh status root@webhostc:~# service ssh stop root@webhostc:~# service ssh start
As you can see in the image, the ssh server is running on our system.
The ps, kill, and killall commands
While we’re on the topic of processes, let’s see how we can find active processes and kill them. To find the running processes, we can simply type ps in the terminal prompt and get the list of running processes.
root@webhostc:~# ps root@webhostc:~# kill <process ID> root@webhostc:~# killall <process name>
For demonstration purposes, I’m creating a shell script with an infinite loop and will run it in the background.
With the use of the & symbol, I can pass a process into the background. As you can see, a new bash process with PID 14490 is created.
The df and mount commands
When working with Linux, the df and mount commands are very efficient utilities to mount filesystems and get details of the file system.
When I say mount, it means that we’ll connect the device to a folder so we can access the files from our filesystem. The default syntax to mount a filesystem is below:
root@webhostc:~ # mount /dev/cdrom /mnt root@webhostc:~ # df -h
In the above case, /dev/cdrom is the device that needs to be mounted. Usually, a mountable device is found inside the /dev folder. /mnt is the destination folder to mount the device to. You can change it to any folder you want but I’ve used /mnt as it’s pretty much a system default folder for mounting devices.
To see the mounted devices and get more information about them, we make use of the df command. Just typing df will give us the data in bytes which is not readable. So we’ll use the -h parameter to make the data human-readable.
The chmod and chown commands
The chmod and chown commands give us the functionality to change the file permissions and file ownership are the most important Linux commands you should know.
The main difference between the functions of the two commands is that the chmod command allows changing file permissions, while chown allows us to change the file owners.
root@webhostc:~ # chmod +x loop.sh root@webhostc:~ #chmod root:root loop.sh
As you will notice, the root root part is now changed to www-data which is the new user who has full file ownership.
The ifconfig and traceroute commands
Moving on to the networking section in Linux, we come across the ifconfig and traceroute commands which will be frequently used if you manage a network.
The ifconfig command will give you the list of all the network interfaces along with the IP addresses, MAC addresses and other information about the interface.
root@webhostc:~ # ifconfig
There are multiple parameters that can be used but we’ll work with the basic command here.
When working with traceroute, you can simply specify the IP address, the hostname or the domain name of the endpoint.
root@webhostc:~ # traceroute <destination address>
Now obviously, localhost is just one hop (which is the network interface itself). You can try this same command with any other domain name or IP address to see all the routers that your data packets pass through to reach the destination.
The wget command in Linux
If you want to download a file from within the terminal, the wget command is one of the handiest command-line utilities available. This will be one of the important Linux commands you should know when working with source files.
When you specify the link for download, it has to directly be a link to the file. If the file cannot be accessed by the wget command, it will simply download the webpage in HTML format instead of the actual file that you wanted.
Let’s try an example. The basic syntax of the wget command is :
root@webhostc:~ # wget <link to file> OR root@webhostc:~ # wget -c <link to file>
The -c argument allows us to resume an interrupted download.
The ufw and iptables commands
UFW(Uncomplicated Firewall – for Ubuntu) and IPTables are firewall interfaces for the Linux Kernel’s netfilter firewall. IPTables directly passes firewall rules to net filter while UFW configures the rules in IPTables which then sends those rules to netfilter.
Why do we need UFW when we have IPTables? Because IPTables is pretty difficult for a newbie. UFW makes things extremely easy. See the below example where we are trying to allow the port 80 for our webserver.
root@webhostc:~# iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT root@webhostc:~# ufw allow 80
I’m sure you now know why UFW(Uncomplicated Firewall) is created, Look at how easy the syntax becomes. Both these firewalls are very comprehensive and can allow you to create any kind of configuration required for your network. Learn at least the basics of UFW or IPTables firewall as these are the Linux commands you must know.
Package Managers in Linux
Different distros of Linux make use of different package managers. Since we’re working on a Ubuntu server, we have the apt package manager. But for someone working on a Fedora, Red Hat, Arch, or Centos machine, the package manager will be different.
- Debian and Debian-based distros – apt install <package name>
- Arch and Arch-based distros – pacman -S <package name>
- Red Hat and Red Hat-based distros – yum install <package name>
- Fedora and CentOS – yum install <package>
Getting yourself well versed with the package manager of your distribution will make things much easier for you in the long run. So even if you have a GUI based package management tool installed, try an make use of the CLI based tool before you move on to the GUI utility. Add these to your list of Linux commands you must know.
The sudo command in Linux
“With great power, comes great responsibility”
This is the quote that’s displayed when a sudo enabled user(sudoer) first makes use of the sudo command to escalate privileges. This command is equivalent to having logged in as root (based on what permissions you have as a sudoer).
non-root-user@webhostc:~# sudo <command you want to run> Password:
Just add the word sudo before any command that you need to run with escalated privileges and that’s it. It’s very simple to use, but can also be an added security risk if a malicious user gains access to a sudoer.
The cal command in Linux
Ever wanted to view the calendar in the terminal? Me neither! But there apparently are people who wanted it to happen and well here it is.
The cal command displays a well-presented calendar on the terminal. Just enter the word cal on your terminal prompt.
root@webhostc:~# cal root@webhostc:~# cal Jun 2021
Even though I don’t need it, it’s a really cool addition! I’m sure there are people who are terminal fans and this is a really amazing option for them.
The alias command
Do you have some commands that you run very frequently while using the terminal? It could be rm -r or ls -l, or it could be something longer like tar -xvzf. This is one of the productivity-boosting Linux commands you must know.
If you know a command that you run very often, it’s time to create an alias. What’s an alias? In simple terms, it’s another name for a command that you’ve defined.
root@webhostc:~# alias lsl="ls -l" OR root@webhostc:~# alias rmd="rm -r"
Now every time you enter lsl or rmd in the terminal, you’ll receive the output that you’d have received if you had used the full commands.
The examples here are for really small commands that you can still type by hand every time. But in some situations where a command has too many arguments that you need to type, it’s best to create a shorthand version of the same.
The dd command in Linux
This command was created to convert and copy files from multiple file system formats. In the current day, the command is simply used to create bootable USB for Linux but there still are some things important you can do with the command.
For example, if I wanted to back up the entire hard drive as is to another drive, I’ll make use of the dd command.
root@webhostc:~# dd if = /dev/sdb of = /dev/sda
The whereis and whatis commands
The names of the commands make it very clear as to their functionality. But let’s demonstrate their functionality to make things more clear.
The whereis command will output the exact location of any command that you type in after the whereis command.
root@webhostc:~# whereis sudo sudo: /usr/bin/sudo /usr/lib/sudo /usr/share/man/man8/sudo.8.gz
The whatis command gives us an explanation of what a command actually is. Similar to the whereis command, you’ll receive the information for any command that you type after the whatis command.
root@webhostc:~# whatis sudo
The top command in Linux
A few sections earlier, we talked about the ps command. You observed that the ps command will output the active processes and end itself.
The top command is like a CLI version of the task manager in Windows. You get a live view of the processes and all the information accompanying those processes like memory usage, CPU usage, etc.
To get the top command, all you need to do is type the word top in your terminal.
The useradd and usermod commands
The useradd or adduser commands are the exact same commands where adduser is just a symbolic link to the useradd command. This command allows us to create a new user in Linux.
root@webhostc:~# useradd webhostc -d /home/WHC
The above command will create a new user named
webhostch with the home directory as /home/WHC.
The usermod command, on the other hand, is used to modify existing users. You can modify any value of the user including the groups, the permissions, etc.
For example, if you want to add more groups to the user, you can type in:
root@webhostc:~# usermod webhost-a -G sudo, audio, mysql
The passwd command in Linux
Now that you know how to create new users, let’s also set the password for them. The passwd command lets you set the password for your own account, or if you have the permissions, set the password for other accounts.
The command usage is pretty simple:
root@webhostc:~# passwd New password:
For other user
root@webhostc:~# passwd <username> New password:
If you add the username after passwd, you can set passwords for other users. Enter the new password twice and you’re done. That’s it! You will have a new password set for the user.
To know about other important commands, click here