Top 60 Linux commands
Top 60 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
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’s Kodee 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:
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:
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
10. file command
The file command checks a file type, such as TXT, PDF, or other. The syntax is as follows:
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.
14. cat command
The concatenate or cat command has various usages. The most basic one is printing the content of a file.
Here’s the syntax:
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:
command | head [options]
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.
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:
You can combine multiple options for a more specific output. For example, this command extracts the third
to fifth field from a comma-separated list:
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:
diff -c 1.txt 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:
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.
updatedb
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.
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.
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:
Note that this command might not work with older distributions since they use another service manager.
40. watch command
The watch command lets you continuously run a utility at a specific interval to monitor changes in the
output. Here’s the basic syntax:
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.
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
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
50. netstat command
The netstat command displays information about your system’s network configuration. The syntax is simple:
netstat [options]
Add an option to query specific network information. Here are several flags to use:
You can use a hostname, domain name, or IP address as the destination. If you don’t specify an option,
traceroute will run the test using the default settings.
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.
Running dig without an argument will check A records of the specified domain using the operating system’s
default resolver. You can query a particular record by specifying it in the [type] argument like the following
example:
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
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 the Kodee 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.
THE AUTHOR
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.
Excellent
Comments
Vimal
July 30 2019 REPLY
GOOD
Sunny
December 20 2019 REPLY
Adrian
May 24 2020 REPLY
xmax
July 08 2020 REPLY
Man, you're a lifesaver! REALLY helpful to see all useful commands with their switches all in one place.
Tomislav T.
September 06 2020
Sina
August 17 2020 REPLY
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
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
kamyogi
December 23 2020 REPLY
Thank you very much Art. Very useful. It has changed a bit my attitude towards Linux.
Nizor
January 11 2021 REPLY
This was very helpful. Thanks
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
Your documentation is incredibly useful. Thanks for taking the time to make this.
r
August 27 2021 REPLY
for a guy starting to learn linux this is very very very helpful.
Vakarė
September 20 2021
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
Great, all commands are useful. Thanks a lot to given description of all commands
the kid
December 20 2021 REPLY
Mark
January 06 2022 REPLY
Tamanna yadav
February 06 2022 REPLY
Hassan Raza
March 17 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
Hi there! This is a good point - apt-get update and apt-get upgrade are commonly used before installing any application. If
you're simply editing some files or navigating your server, it's not that important, but surely won't hurt ?
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
We accomplish this by continuously developing server technology, giving expert assistance, and ensuring a flawless online website hosting
experience.
And More
HOSTING
Web Hosting
VPS Hosting
CyberPanel Hosting
Cloud Hosting
Business Email
CMS Hosting
Ecommerce Hosting
Website Builder
AI Website Builder
AI Logo Generator
DOMAIN
Domain Transfer
Cheap Domains
Domain Extensions
WHOIS Lookup
HELP
Tutorials
Knowledge Base
INFORMATION
Migrate to Hostinger
System Status
Affiliate Program
Payment Methods
Rewards
Hostinger Reviews
Pricing
Sitemap
COMPANY
About Hostinger
Our Technology
Roadmap
Customer Care
Blog
LEGAL
Privacy Policy
Terms of Service