60 essential Linux commands
60 essential Linux commands
System administrators commonly use commands to manage Linux servers. Commands are more efficient
and allow users to automate various tasks more quickly.
In this tutorial, we will explain 60 essential Linux commands for various purposes, from navigation to
software management. To access the information offline, download our cheat sheet from the link below.
Prerequisites
To 60 essential Linux commands
Essential Linux commands FAQ
Prerequisites
Before proceeding, access the command-line interface of your Linux desktop or virtual private server
(VPS). If you use a remote system, connect to it using an SSH client like PuTTY or Terminal.
If you don’t have a Linux machine, we recommend purchasing Hostinger’s VPS hosting plan. Our
Browser terminal feature lets you connect to your server directly from the web browser to simplify the
process.
Moreover, Hostinger VPS AI Assistant can write commands based on your needs. It helps beginners
learn Linux utilities more efficiently, as they don’t need to open documentation for references.
Pro Tip
If you want to check a command’s usage, syntax, and options, use the –
help flag. For example, enter ls –help to display the ls utility guide.
1. ls command
The ls command lists the content of a folder, including files and directories. Here’s the syntax:
ls [options] [directory_or_path]
If you omit the path, the ls command will check the content of your current directory. To list items inside
subfolders, add the -R option. Meanwhile, use -a to show hidden content.
2. pwd command
To check the full path of your current working directory, use the pwd command. Its syntax is as follows:
pwd [options]
The pwd command has only two options. The -L option prints environment variable content, like
shortcuts, instead of the actual path of your current location. Meanwhile, -P outputs the exact location.
For example, /shortcut/folder is a shortcut for /actual/path, and you are currently in /actual/path/dir. If
you use the -L option, the output will be:
/shortcut/folder/dir
/actual/path/dir
3. cd command
Use cd to navigate between directories in your Linux VPS. It doesn’t have any option, and the syntax is
simple:
cd [path_or_directory]
Depending on your location, you might only need to specify the parent directory. For example, omit path
from path/to/directory if you are already inside one. The cd command has several shortcuts:
4. mkdir command
The mkdir command lets you create one or multiple directories. The syntax looks like this:
To create a folder in another location, specify the full path. Otherwise, this command will make the new
item in your current working directory.
mkdir path/to/target_folder/new_folder
By default, mkdir allows the current user to read, write, and execute files in the new folder. You can set
custom privileges during the creation by adding the -m option. To learn more about permission
management, read the chmod section below.
5. rmdir command
Run rmdir to delete empty directories in your Linux system. The command syntax looks like this:
The rmdir command won’t work if the directory contains subfolders. To force the deletion, add the –p
option. Note that you must own the item you want to remove or use sudo instead.
6. rm command
The rm command deletes files from a directory. You must have the write permission for the folder or use
sudo. Here’s the syntax:
You can add the -r option to remove a folder and its contents, including subdirectories. Use the -i flag to
display a confirmation message before the removal or -f to deactivate it completely.
Warning! Avoid using -r and -f unless necessary. Instead, add -i option to prevent accidental
deletion.
7. cp command
Use the cp command to copy files from your current directory to another folder. The syntax looks like this:
You can also use cp to duplicate the content of one file to another using this syntax. If the target is in
another location, specify the full path like so:
cp source_file /path/to/target_file
Additionally, cp lets you duplicate a directory and its content to another folder using the -R option:
cp -R /path/to/folder /target/path/to/folder_copy
8. mv command
The main usage of the mv command is to move a file or folder to another location. Here’s the syntax:
mv file_or_directory [target_directory]
For example, we will move file1.txt from another location to the /new/file/directory path using this
command:
mv /original/path/file1.txt the/target/path
You can also use the mv command to rename files in your Linux system. Here’s an example:
mv old_name.txt new_name.txt
If you specify the full path, you can simultaneously rename files and move them to a new location like this
example:
mv old/location/of/old_name.txt new/path/for/new_name.txt
9. touch command
Run the touch command to create a new empty file in a specific directory. The syntax is as follows:
touch [options] [path_and_file_name]
If you omit the path, the touch command will create a new file in your current working directory. Here’s an
example:
touch file.txt
file [file_name]
If you use this command on a symbolic link, it will output the actual file connected to the shortcut. You
can add the -k option to print more detailed information about the item.
To extract a compressed file into your current working directory, use the unzip command like so:
To create a new TAR file, you must add the -c option. Then, use the -f flag to specify the archive’s name.
If you want to enable compression, add a specific option based on your preferred method. For example,
the following will bundle file1.txt and file2.txt with the gzip compression:
Remember that the archive’s file format will differ depending on the compression method. Regardless of
the extension, you can unpack a TAR file using this syntax:
nano/vi/jed file_name
If the target file doesn’t exist, these commands will create a new one. Since your system might not have
these text processing utilities pre-installed, configure them using your package manager.
We will explain the command in the apt and dnf command section.
cat file_name
To print the content in reverse order, use tac instead. If you add the standard output operator symbol (>),
the cat command will create a new file. For example, the following will make file.txt:
You can also use cat with the operator to combine the content of multiple files into a new item. In this
command, file1.txt and file2.txt will merge into target.txt:
You can also filter data from another utility by piping it to the grep command. For example, the following
searches file.txt from the ls command’s output:
ls | grep "file.txt"
You can replace a string in multiple files simultaneously by listing them. Here’s an example of a sed
command that changes red in colors.txt and hue.txt with blue:
You can also print the first few lines of another command’s output by piping it like so:
By default, head will show the first ten lines. However, you can change this setting using the -n option
followed by your desired number.
Meanwhile, use -c to print the first few entries based on the byte size instead of the line.
18. tail command
The tail command is the opposite of head, allowing you to print the last few lines from files or another
utility’s output. Here are the syntaxes:
The tail utility also has the same option as head. For example, we will extract the last five lines from the
ping command’s output:
Although similar to sed, awk offers more operations beyond substitution, including printing, mathematical
calculation, and deletion. It also lets you run a complex task with an if statement.
You can run multiple actions by listing them according to their execution order, separated by a semicolon
(;). For example, this awk command calculates the average student score and print names that are above
that threshold:
Note that this utility doesn’t modify the actual file and only prints the rearranged content as an output.
By default, the sort command uses the alphabetical order from A to Z, but you can add the -r option to
reverse the order. You can also sort files numerically using the -n flag.
Unlike other utilities, the cut command’s options are mandatory for file sectioning. Here are some of the
flags:
By default, the diff command only shows the differences between the two files. To print all the content and
highlight the discrepancies, enable the context format using the -c option. You can also ignore case
sensitivity by adding -i.
For example, run the following to show only the differences between 1.txt and 2.txt:
If the specified file doesn’t exist, tee will create it. Be careful when using this command since it will
overwrite the existing content. To preserve and append existing data, add the -a option.
For example, we will save the ping command’s output as new entries in the test_network.txt file:
If you use the -r option to search files using regular expressions, omit the [keyword] argument. The
locate command is case-sensitive by default, but you can turn off this behavior using the -i flag.
Note that locate will look for files from its database. While this behavior speeds up the search process,
you must wait for the list to refresh before finding newly created items.
If you don’t specify the path, the find command will search your current working directory. To find files
using their name, add the -name option followed by the keyword.
You can specify the type of item you are looking for using the -type flag. The –type f option will search
files only, while -type d will find directories. For example, we will check file.txt in path/to/folder:
Unlike locate, the find command searches through folders in real time. While it slows down the process,
you can look for new items immediately without waiting for the system database to refresh.
For example, enter the following to open a file using nano as an administrator:
The Terminal will prompt you to enter the user’s password before executing the command. By default, you
must reenter it after five minutes of inactivity.
Typically, you don’t add any option to sudo, but you can check them by entering:
sudo --help
Warning! Since users with sudo privileges can change various settings of your system, use
this command with caution.
27. su and whoami commands
The su command lets you switch to another user in the Terminal session. The syntax looks as follows:
su [options] [username]
If you don’t specify any option or username, this command will switch you to the root user. In this case,
you must enter the password before changing the account.
You can check the currently logged-in user from the Linux command-line shell. Alternatively, use the
whoami command:
whoami
In Linux, there are three folder and file permissions – read (r), write (w), and execute (x). You can assign
them to three parties – the owner, a group, or other accounts belonging to neither category. Consider
this example:
The spot after the first hyphen (–) specifies the permission for the owner of file1.txt. In the previous
example, we grant them the rwx privilege.
The next spot is for groups. Since we won’t grant them any privilege, we put three hyphens to indicate
emptiness. The last slot is for other users who only have read or r permission.
If you want to assign a user as the new owner of an item, leave the group name empty. For example, we
will make admin-vps the owner of file1.txt:
Conversely, omit the username to make all group members the owner. Remember to write the colons (:)
like so:
By default, the useradd command doesn’t prompt you to give the new user a password. You can add or
change it manually later with the passwd command:
passwd new_username
To remove a user, use the userdel command followed by the account name like the syntax in the
example:
userdel new_username
Since managing other users requires a superuser privilege, run these commands as root or with the
sudo prefix.
Pro Tip
To set up a password and other details during the account creation
process, use the adduser command instead.
31. df command
The df command checks your Linux system’s disk usage, displaying the used space in percentage and
kilobyte (KB). The syntax looks like this:
Note that the df command operates at the file system level. If you don’t specify one, the utility will display
all the active file systems.
32. du command
To check the size of a directory and its content, use the du command. Here’s the syntax:
du [directory]
The command will check your working directory if you don’t specify a path or folder. By default, it breaks
down each subfolder’s disk usage, but you can add the -s option to summarize the total usage in one
output.
You can also use the -M option to change the information from KB to MB.
top [options]
The top command has various options. For example, -p lets you check a specific process by specifying its
ID. Meanwhile, add the -d flag to change the delay between screen updates.
htop [options]
htop has options similar to top, but you can add additional ones. For example, -C enables the
monochrome mode, while –-tree shows processes in a hierarchical view.
35. ps command
The ps command summarizes the status of all running processes in your Linux system at a specific time.
Unlike top and htop, it doesn’t update the information automatically. Here’s the syntax:
ps [options]
You can print a more detailed report by adding other options. For example, use -A to list all processes in
your system, -r to check only the running ones, or -u username to query those associated with a particular
account.
uname [options]
Without any option, the command will print your system’s kernel name. To check all information about your
machine, add the -a option.
hostname [options]
If you leave the option empty, the command will print your hostname. Add -i to check your server’s IP
address, -a to print the hostname alias, and -A to output the system’s fully qualified domain name (FQDN).
time command_or_script
You can measure a series of commands by separating them using double ampersands (&&) or semicolons
(;) like so:
The subcommands represent your task, like listing, restarting, terminating, or enabling the services. For
example, we will list Linux services using this:
By default, watch will run your command every two seconds, but you can change the interval using the -
n option followed by the delay. If you want to highlight changes in the output, add the -d flag.
Running this command without any argument will show all jobs running in the Terminal’s foreground and
background. If you don’t have any ongoing tasks, it will return an empty output.
You can display more detailed information about each job by adding the -l option. Meanwhile, use -n to
show only tasks whose status has changed since the last notification.
42. kill command
Use the kill command to terminate a process using its ID. Here’s the basic syntax:
ps ux
The kill command has 64 termination signals. By default, it uses the SIGTERM method that lets the
program save its progress before closing.
If you run the command without any arguments, your system will shut down immediately. You can specify
the schedule using a 24-hour format or a relative one. For example, enter +5 to shut down the system
after five minutes. To restart the machine, add the -r option.
The message argument specifies the notification other users in your system will receive before the server
shuts down.
By default, ping sends infinite packets until the user manually stops it by pressing Ctrl + C.
However, you can specify a custom number using the -c option. You can also change the interval between
transfers by adding -i.
For instance, let’s send 15 packets every two seconds to Google’s server:
ping -c 15 -i 2 google.com
45. wget command
The wget command lets you download files from the internet via HTTP, HTTPS, or FTP protocols. Here’s
the syntax:
By default, the wget command will download an item to your current working directory. For example, run
this command to retrieve the latest WordPress installer:
wget https://wordpress.org/latest.zip
Running cURL without an option will print the website’s HTML content in your Terminal. If you add the -O
or -o option, the command will download files from the specified link.
The cURL command is also helpful for testing API or server endpoints. You can do so by adding the –X
option followed by an HTTP method, depending on whether you want to fetch or upload data.
For example, the following command will retrieve data from a specific API endpoint:
If you are copying items to or from your local machine, omit the IP and path. When transferring a file or
folder from a local machine, specify its name after options.
For example, we will run the following to copy file1.txt to our VPS’ path/to/folder directory as root:
You can change the default SCP port by specifying its number after the -P option. Meanwhile, use the -l
flag to limit the transfer bandwidth and add –C to enable compression.
The source and destination can be a folder within the same system, a local machine, or a remote server. If
you are syncing content with a VPS, specify the username and IP address like so:
You can add the -a option to sync the file or folder’s attributes as well, including their symbolic links.
Meanwhile, use the -z flag to enable compression during the transfer.
49. ip command
The ip utility lets you list and manage your system’s network parameters, similar to the ifconfig command
in older Linux distros. Here’s the syntax:
Running this command without any argument will print the manual, including an explanation about
acceptable options and objects.
To manage a network parameter, specify the action in the command argument. For example, run this to
show your system’s IP address:
ip address show
netstat [options]
Add an option to query specific network information. Here are several flags to use:
Change the maximum packet hops using the -m option. To prevent traceroute from resolving IP
addresses, add -n.
You can also enable a timeout in seconds using the -w flag followed by the duration.
If you don’t specify a DNS server, nslookup will use your internet service provider’s default resolver. You
can add other options to change how this command queries an IP address or a domain.
For example, use the -type= option to specify the information you want to check, such as the DNS
records.
You can also set up automatic retry with the -retry= flag and add -port= to use a specific port.
Since some Linux distros don’t have this utility pre-installed, you might encounter the “command not
found” error. You can configure it by downloading bind-utils or dnsutils via your package manager.
dig MX domain.com
To run a reverse DNS lookup, add the –x option and use an IP address as the target.
history [options]
Add the -r option if you want to clear the Terminal history. To rerun a specific utility from the list, enter an
exclamation mark followed by its ID.
!145
If you specify only the command name, man will display the entire manual. Alternatively, you can select
one of the nine sections using their IDs to print more specific information.
For example, run the following to check the library call section of the ls command’s manual:
man 3 ls
56. echo command
Use echo to print text in your command as a Terminal output. Here’s the syntax:
You can also add the redirection symbol (>) to print the text in a file instead of Terminal. If you use two
symbols (>>), it will append the existing content. The command syntax looks like this:
If your text contains an environment or shell variable like $var, echo will display the actual value. This
command is commonly used for testing and bash scripting.
57. ln command
The ln command links files or directories with a shortcut. The syntax looks as follows:
This command will automatically create the shortcut, meaning you don’t need to make one manually. For
example, the following will enable you to open file.txt using shortcut.txt:
ln target.txt shortcut.txt
By default, ln creates a hard link, meaning changes in the source will be reflected in the linked item and
vice versa. To set up a soft or symbolic link, add the -s option.
alias name='string'
For example, the following will assign k as the alias for the kill command, allowing you to use the letter
instead of the full name.
alias k='kill'
To check a command’s alias, run alias followed by an alternative name. For example, we will check the
previous snippet:
alias k
unalias [name]
If you don’t add any argument, the command will show the current date. Alternatively, you can enter a
specific month and year in a numerical format.
You can also add the -3 option to show the current, previous, and next month.
The subcommands define the action, like updating the library, upgrading software, installing an
application, or removing a package. For example, we will install the Vim text editor:
In Linux, package management commands differ across distributions. For example, Red Hat Enterprise
Linux-based distros like CentOS and AlmaLinux use dnf. It has the same syntax and options as apt.
Running both apt and dnf requires superuser privileges, which you can only obtain with sudo or via root.
Conclusion
Linux commands enable system administrators to manage their servers more efficiently. They provide
capabilities like scripting, variables, and automation that graphical user interfaces need to improve.
In this tutorial, we have explained the 60 most commonly used Linux commands. These will be invaluable
for various tasks, including file management, user administration, navigation, and network configuration.
Take advantage of Hostinger’s VPS AI Assistant to use these commands more efficiently. It lets you use
simple prompts to write various utilities and scripts according to your task to save time and effort.
To list all Linux commands, run compgen -c, help, or man -e in your Terminal screen. Run the utility
with the –help flag to check a command’s manual and options.
Use a Linux command cheat sheet and use Terminal often. Reading VPS tutorials and practicing the
steps can also familiarize you with various utilities more quickly.
Which is the most commonly used command in Linux?
Navigation utilities like cd and su are commonly used commands since system admins often work in
different directories or use another account. File management utilities like cat, mv, or nano are also
essential for server administration tasks.
T H E AU T H O R
Aris Sentika
Aris is a Content Writer specializing in Linux and WordPress development. He has a
passion for networking, front-end web development, and server administration. By
combining his IT and writing experience, Aris creates content that helps people easily
understand complex technical topics to start their online journey. Follow him on LinkedIn.
Related tutorials
20 Aug • VPS • GAMING
Trustpilot
Vimal
July 30 2019 REPLY
GOOD
Sunny
December 20 2019 REPLY
Adrian
May 24 2020 REPLY
xmax
July 08 2020 REPLY
Tomislav T.
September 06 2020
Hasan Murtaza
August 17 2020 REPLY
Thanks
boe
August 23 2020 REPLY
thanks
happy
August 31 2020 REPLY
Mehmood Qazi
September 20 2020 REPLY
Very helpful
Tomislav T.
November 11 2020
krikor bedrossian
October 17 2020 REPLY
Excellent, thank you :-)
Vakarė
February 02 2021
Happy to help!
Ravichandran VN
November 17 2020 REPLY
dhruv
November 23 2020 REPLY
Vakarė
February 09 2021
Happy it helped!
ugesh
December 12 2020 REPLY
Thank you very much Art. Very useful. It has changed a bit my
attitude towards Linux.
Nizor
January 11 2021 REPLY
ajay
January 27 2021 REPLY
Benji
February 27 2021 REPLY
Ulita Dso'za
May 08 2021 REPLY
Bethwel Ombewa
July 07 2021 REPLY
sharfat hussain
July 07 2021 REPLY
Grammy R. Codeislow
July 11 2021 REPLY
r
August 27 2021 REPLY
for a guy starting to learn linux this is very very very helpful.
Vakarė
September 20 2021
G. Williams
August 27 2021 REPLY
Awesome tips, been too long with MS...school was a while ago
now Linux PC my gift to me, using a new OS after 40 yrs isn't easy.
I know I can swing it.
Vakarė
September 20 2021
gayle williams
September 15 2021 REPLY
Akash Jaiwal
December 11 2021 REPLY
the kid
December 20 2021 REPLY
Mark
January 06 2022 REPLY
Tamanna yadav
February 06 2022 REPLY
Hassan Raza
March 17 2022 REPLY
rotke
April 06 2022 REPLY
Thanks, there were few commands I didn't know : locate and jobs,
I used find and ps. I will tray them out, thanks.
Bill Zaffos
May 20 2022 REPLY
This is very good for me because, I don't live in Linux but only
frequent it. I catch myself thinking 'What is that command?'
However, may I suggest some very important commands (in my
opinion) that you missed. They are apt-get update & apt-get
upgrade. I was told to always include these when ever I'm in
terminal mode. If in the terminal, mount & unmount comes in
handy when deeding information from a USB drive, but then, you
would need the blkid, or maybe not.
Vakarė
May 24 2022
Leave a reply
Comment*
Name*
Email*
By using this form you agree that your personal data would be processed in
accordance with our Privacy Policy.
Submit
And More
HOSTING
Web Hosting
VPS Hosting
Cloud Hosting
WordPress Hosting
Email Hosting
CMS Hosting
Ecommerce Hosting
cPanel Hosting
Online Stores
Website Builder
Buy Hosting
DOMAINS
Domain Checker
Domain Transfer
Free Domain
XYZ Domain
99 Cent Domains
WHOIS Checker
HELP
Tutorials
Knowledge Base
Report Abuse
INFORMATION
Server Status
Affiliate Program
Payment Methods
Wall of Fame
Reviews
Pricing
COMPANY
About Hostinger
Our Technology
Career
Contact Us
Blog
LEGAL
Privacy Policy
Terms of Service