40 Essential Linux Commands For Every User
The average Linux user knows almost all the basic Linux daily use commands to perform basic tasks like install any application, copy files from one directory to another, etc. But in this article, I will list 40 essential Linux commands that can be useful for every Linux user right from the average person to professional Linux developers and system administrators. So, before wasting any time, let’s start with this huge list of essential Linux commands.
1. sudo
Short for superuser do, sudo is one of the most popular basic Linux commands that lets you perform tasks that require administrative or root permissions.
When using sudo, the system will prompt users to authenticate themselves with a password. Then, the Linux system will log a timestamp as a tracker. By default, every root user can run sudo commands for 15 minutes/session.
If you try to run sudo in the command line without authenticating yourself, the system will log the activity as a security event.
Here’s the general syntax:
sudo (command)
You can also add an option, such as:
- -k or –reset-timestamp invalidates the timestamp file.
- -g or –group=group runs commands as a specified group name or ID.
- -h or –host=host runs commands on the host.
2. pwd
Use the pwd command to find the path of your current working directory. Simply entering pwd will return the full current path – a path of all the directories that starts with a forward slash (/). For example, /home/username.
The pwd command uses the following syntax:
pwd [option]
3. cd
The cd command helps you to access specific directory or directory from the file system. You can also use the cd .. command to go back to the root directory.
Syntax:
cd <directory name>
4. Ls
The ls command lists files and directories within a system. Running it without a flag or parameter will show the current working directory’s content.
To see other directories’ content, type ls followed by the desired path
Here are some options you can use with the ls command:
- ls -R lists all the files in the subdirectories.
- ls -a shows hidden files in addition to the visible ones.
- ls -lh shows the file sizes in easily readable formats, such as MB, GB, and TB.
5. cat
Concatenate, or cat, is one of the most frequently used Linux commands. It lists, combines, and writes file content to the standard output. To run the cat command, type cat followed by the file name and its extension. For instance:
cat filename.txt.
Here are other ways to use the cat command:
- cat > filename.txt creates a new file.
- cat filename1.txt filename2.txt > filename3.txt merges filename1.txt and filename2.txt and stores the output in filename3.txt.
- tac filename.txt displays content in reverse order
6. cp
The cp command is used to copy a file or directory.
Syntax:
To copy in the same directory:
cp <existing file name> <new file name>
To copy in a different directory:
7. mv
The mv command is used to move a file or a directory form one location to another location
Syntax:
mv <file name> <directory path>
8. mkdir
The mkdir command is used to create a new directory under any directory.
Syntax:
mkdir <directory name>
9. rmdir
The rmdir command is used to delete a directory
Syntax:
rmdir <directory name>
10. rm
The rm command is used to remove a file.
Syntax:
rm <file name>
11. touch
The touch command is used to create empty files. We can create multiple empty files by executing it once
Syntax:
touch <file name> touch <file1> <file2> ....
12. locate
The locate command is used to search a file by file name. It is quite similar to find command; the difference is that it is a background process. It searches the file in the database, whereas the find command searches in the file system. It is faster than the find command. To find the file with the locates command, keep your database updated.
Syntax:
locate <file name>
13. find
The find command is used to find a particular file within a directory. It also supports various options to find a file such as byname, by type, by date, and more.
The following symbols are used after the find command:
(.) : For current directory name
(/) : For root
Syntax:
find . -name "*.pdf"
14. grep
The grep is the most powerful and used filter in a Linux system. The ‘grep’ stands for “global regular expression print.” It is useful for searching the content from a file. Generally, it is used with the pipe.
Syntax:
command | grep <searchWord>
15. df
The df command is used to display the disk space used in the file system. It displays the output as in the number of used blocks, available blocks, and the mounted directory.
16. du
If you want to check how much space a file or a directory takes up, use the du command. You can run this command to identify which part of the system uses the storage excessively.
Remember, you must specify the directory path when using the du command. For example, to check /home/user/Documents enter:
du /home/user/Documents
Adding a flag to the du command will modify the operation, such as:
- -s offers the total size of a specified folder.
- -m provides folder and file information in MB
- k displays information in KB.
- -h informs the last modification date of the displayed folders and files.
17. head
The head command is used to display the content of a file. It displays the first 10 lines of a file.
Syntax:
head <file name>
18. tail
The tail command is similar to the head command. The difference between both commands is that it displays the last ten lines of the file content. It is useful for reading the error message.
Syntax:
tail <file name>
19. diff
The command diff <file name1> <file name2> will compare two directories and will show the difference between them as shown in the following screenshot.
20. tar
The tar command archives multiple files into a TAR file – a common Linux format similar to ZIP, with optional compression.
Here’s the basic syntax:
tar [options] [archive_file] [file or directory to be archived]
For instance, you want to create a new TAR archive named newarchive.tar in the /home/user/Documents directory:
tar -cvf newarchive.tar /home/user/Documents
The tar command accepts many options, such as:
- -x extracts a file.
- -t lists the content of a file.
- -u archives and adds to an existing archive file.
21. chmod
chmod is a common command that modifies a file or directory’s read, write, and execute permissions. In Linux, each file is associated with three user classes – owner, group member, and others.
Here’s the basic syntax:
chmod [option] [permission] [file_name]
For example, the owner is currently the only one with full permissions to change note.txt. To allow group members and others to read, write, and execute the file, change it to the -rwxrwxrwx permission type, whose numeric value is 777:
chmod 777 note.txt
This command supports many options, including:
- -c or –changes displays information when a change is made.
- -f or –silent suppresses the error messages.
- -v or –verbose displays a diagnostic for each processed file.
22. chown
The chown command lets you change the ownership of a file, directory, or symbolic link to a specified username.
Here’s the basic format:
chown [option] owner[:group] file(s)
For example, you want to make linuxuser2 the owner of filename.txt:
chown linuxuser2 filename.txt
23. jobs
A job is a process that the shell starts. The jobs command will display all the running processes along with their statuses. Remember that this command is only available in csh, bash, tcsh, and ksh shells.
This is the basic syntax:
jobs [options] jobID
To check the status of jobs in the current shell, simply enter jobs to the CLI.
Here are some options you can use:
- -l lists process IDs along with their information.
- -n lists jobs whose statuses have changed since the last notification.
- -p lists process IDs only.
24. kill
You can use this command to manually kill currently ongoing processes that form the Terminal shell. You need unique PID i.e. process identifier to terminate the process.
25. ping
If you want to check if your system is connected to a router or the internet then PING (Packet INTERnet Groper) is the command for you. It uses ICMP protocol to connect with other devices.
There are several options to use with the ping command, ping shows addresses as hostnames, so if you want to see them as numbers then use the ping -n command. Ping -I to specify the interval between transmissions as it is 1 second by default.
26. wget
wget <file path> is a very useful command to download any file from the internet and the best part is that the download works in the background so you can keep working on your task.
27. uname
uname is another useful Linux command to have because it displays Linux system information when executed in the Terminal shell.To view all system information, type uname -a in Terminal.
For kernel release related information, just type uname -r.
And for OS info, type uname -o in Terminal shell
28. top
top is simple but useful command to monitor all the processes going on on Linux system with username, priority, unique process id and shared memory per task
29. history
When activated into the Terminal shell, the history command will list all the commands you use in serialized form. Use exclamation point ! and the command’s serial number will help you to execute that particular command without having to write the whole command in terminal.
30.man
The man command provides a user manual of any commands or utilities you can run in Terminal, including the name, description, and options.
It consists of nine sections:
- Executable programs or shell commands
- System calls
- Library calls
- Games
- Special files
- File formats and conventions
- System administration commands
- Kernel routines
- Miscellaneous
To display the complete manual, enter:
man [command_name]
For example, you want to access the manual for the ls command:
man ls
Enter this command if you want to specify the displayed section:
man [option] [section_number] [command_name]
For instance, you want to see section 2 of the ls command manual:
man 2 ls
31. echo
The echo command is a built-in utility that displays a line of text or string using the standard output. Here’s the basic syntax:
echo [option] [string]
For example, you can display the text Hostinger Tutorials by entering:
echo “Hostinger Tutorials”
This command supports many options, such as:
- -n displays the output without the trailing newline.
- -e enables the interpretation of the following backslash escapes:
- \a plays sound alert.
- \b removes spaces in between a text.
- \c produces no further output.
- -E displays the default option and disables the interpretation of backslash escapes.
32. zip, unzip
- zip command to compress one or more files as you can see in the screenshot below. This is a simple but useful command to compress any number of files while moving
- To extract files from a zip archive, use the unzip <filename> command in the Terminal shell. You can also use this command to extract files from multiple archives from specific directory.
33. hostname
Run the hostname command to know the system’s hostname. You can execute it with or without an option. Here’s the general syntax:
hostname [option]
There are many optional flags to use, including:
- -a or –alias displays the hostname’s alias.
- -A or –all-fqdns displays the machine’s Fully Qualified Domain Name (FQDN).
- -i or –ip-address displays the machine’s IP address.
For example, enter the following command to know your computer’s IP address:
hostname -i
34. useradd, userdel
- The useradd
command is used to add or remove a user on a Linux server.
Syntax:
useradd username
- The userdel [option] command will allow you to remove any user account from the system.
35. apt-get
apt-get is a command line tool for handling Advanced Package Tool (APT) libraries in Linux. It lets you retrieve information and bundles from authenticated sources to manage, update, remove, and install software and its dependencies.
Running the apt-get command requires you to use sudo or root privileges.
Here’s the main syntax:
apt-get [options] (command)
These are the most common commands you can add to apt-get:
- update synchronizes the package files from their sources.
- upgrade installs the latest version of all installed packages.
- check updates the package cache and checks broken dependencie
36. nano, vi, jed
Linux allows users to edit and manage files via a text editor, such as nano, vi, or jed. nano and vi come with the operating system, while jed has to be installed.
The nano comand denotes keywords and can work with most languages. To use it, enter the following command:
nano [filename]
vi uses two operating modes to work – insert and command. insert is used to edit and create a text file. On the other hand, the command performs operations, such as saving, opening, copying, and pasting a file.
To use vi on a file, enter:
vi [filename]
jed has a drop-down menu interface that allows users to perform actions without entering keyboard combinations or commands. Like vi, it has modes to load modules or plugins to write specific texts.
To open the program, simply enter jed to the command line.
37. alias, unalias
alias allows you to create a shortcut with the same functionality as a command, file name, or text. When executed, it instructs the shell to replace one string with another.
To use the alias command, enter this syntax:
alias Name=String
For example, you want to make k the alias for the kill command:
alias k=’kill’
On the other hand, the unalias command deletes an existing alias.
Here’s what the general syntax looks like:
unalias [alias_name]
38. su
- The su
command provides administrative access to another user. In other words, it allows access of the Linux shell to another user.
Syntax:
su <user name>
39. htop
The htop command is an interactive program that monitors system resources and server processes in real time. It is available on most Linux distributions, and you can install it using the default package manager.
Compared to the top command, htop has many improvements and additional features, such as mouse operation and visual indicators.
To use it, run the following command:
htop [options]
You can also add options, such as:
- -d or –delay shows the delay between updates in tenths of seconds.
- -C or –no-color enables the monochrome mode.
- -h or –help displays the help message and exit.
40. ps
If you want to see a list of currently running processes for your session or for other users on the system then the ps command is for you as it shows the processes with their process identifiers and details. as well as when you use the ps -u command
The process status or ps command produces a snapshot of all running processes in your system. The static results are taken from the virtual files in the /proc file system.
Executing the ps command without an option or argument will list the running processes in the shell along with:
- The unique process ID (PID)
- The type of the terminal (TTY)
- The running time (TIME)
- The command that launches the process (CMD)
Here are some acceptable options you can use:
- -T displays all processes associated with the current shell session.
- -u username lists processes associated with a specific user.
- -A or -e shows all the running processes.
Bonus Tips and Tricks
Here are some tips and tricks you can use to manage the Linux system:
- Enter the clear command to clean the Terminal screen.
- Press the Tab button to autofill after entering a command with an argument.
- Use Ctrl + C to terminate a running command.
- Press Ctrl + Z to pause a working command.
- Use Ctrl + S to freeze your Terminal temporarily.
- Press Ctrl + Q to undo the Terminal freeze.
- Use Ctrl + A to move to the beginning of the line.
- Press Ctrl + E to bring you to the end of the line.
- When executing multiple commands in a single line, use (;) to separate them. Alternatively, use && to only allow the next command to run if the previous one is successful.