System administrators often rely on commands to manage Linux servers efficiently, automating tasks quickly and effectively.
This tutorial covers 60 essential Linux commands for various purposes, including navigation and software management. For offline access, download our comprehensive Linux command cheat sheet from the link below.
Prerequisites:
Before you begin, make sure you can access the command-line interface of your Linux desktop or virtual private server (VPS). If you’re using a remote system, connect to it using an SSH client like PuTTY or Terminal.
Let’s explore the 60 most commonly used Linux commands with examples for system administration.
Pro Tip: 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, ls
will check the current directory’s content. To list items inside subfolders, add the -R
option. Use -a
to show hidden content.
2. pwd
Command
The pwd
command displays the full path of your current working directory:
pwd [options]
The -L
option prints environment variable content like shortcuts, while -P
outputs the actual path.
3. cd
Command
Use cd
to navigate between directories:
cd [path_or_directory]
cd
– returns to the home directory.cd ..
– moves one directory up.cd -
– returns to the previous directory.
4. mkdir
Command
Create one or multiple directories with mkdir
:
mkdir [options] directory_name1 directory_name2
Specify the full path to create a folder in another location.
5. rmdir
Command
Use rmdir
to delete empty directories:
rmdir [options] directory_name
Use the -p
option to force deletion, and note you must own the item or use sudo
.
6. rm
Command
The rm
command deletes files:
rm [options] file1 file2
Add -r
to remove folders and contents, -i
for confirmation messages, or -f
to force deletion.
7. cp
Command
Copy files with the cp
command:
cp file1 file2 [target_path]
Use -R
to duplicate a directory and its content.
8. mv
Command
Move or rename files and directories with mv
:
mv file_or_directory [target_directory]
9. touch
Command
Create a new empty file:
shell
touch [options] [path_and_file_name]
10. file
Command
Check a file type:
file [file_name]
Add -k
for more detailed information.
11. zip
and unzip
Commands
Compress files:
zip [options] zip_file_name file1 file2
Extract files:
unzip [options] zip_file_name
12. tar
Command
Bundle files into an archive:
tar [options] tar_file_name file1 file2
13. nano
, vi
, and jed
Commands
Edit files:
nano/vi/jed file_name
14. cat
Command
Print or concatenate files:
cat file_name
15. grep
Command
Search for specific lines:
grep [options] keyword [file]
16. sed
Command
Search and replace patterns in files:
sed [options] 'subcommand/new_pattern/target_pattern' input_file
17. head
Command
Print the first few lines of a file:
head [options] file_name
18. tail
Command
Print the last few lines of a file:
tail [options] file_name
19. awk
Command
Search and manipulate regular expression patterns:
awk '/regex pattern/{action}' input_file.txt
20. sort
Command
Sort a file’s content:
sort [options] [file_name]
21. cut
Command
The cut
command selects specific sections from a file and prints them as a terminal output:
cut [options] [file]
Mandatory options for cut
:
-f
– selects a specific row field.-b
– cuts the line by a specified byte size.-c
– sections the line using a specified character.-d
– separates lines based on delimiters.
Combine options for specific output. For example, this command extracts the third to fifth fields from a comma-separated list:
cut -d',' -f3-5 list.txt
22. diff
Command
The diff
command compares two files and highlights their differences:
diff file_name1 file_name2
By default, it shows only the differences. Use the -c
option for context format and -i
to ignore case sensitivity. For example:
diff -c 1.txt 2.txt
23. tee
Command
The tee
command outputs another command’s results to both the terminal and a file:
command | tee [options] file_name
To append existing data, use the -a
option. For example:
ping 8.8.8.8 | tee -a test_network.txt
24. locate
Command
The locate
command searches for a file and prints its location path:
locate [options] [keyword]
Use -i
to ignore case sensitivity. Refresh the locate database manually with:
updatedb
25. find
Command
The find
command searches for a file within a specific directory:
find [path] [options] [expression]
Use -name
to find files by name and -type
to specify the item type. For example:
find path/to/folder -type f -name "file"
26. sudo
Command
The sudo
command allows non-root users to execute administrative commands:
sudo [options] your_command
For example, to open a file using nano as an administrator:
sudo nano file.txt
27. su
and whoami
Commands
The su
command switches to another user:
su [options] [username]
To switch to the root user, enter su
without any options. Use whoami
to check the currently logged-in user:
whoami
28. chmod
Command
The chmod
command changes file or directory permissions:
chmod [options] [permission] [file_or_directory]
Example:
chmod -rwx---r-- file1.txt
29. chown
Command
The chown
command changes ownership of files or directories:
chown [options] newowner:newgroup file1 file2
To assign ownership:
chown admin-vps file1.txt
30. useradd
, passwd
, and userdel
Commands
Create a new account:
useradd [options] new_username
Add or change the password:
passwd new_username
Remove a user:
userdel new_username
31. df
Command
The df
command checks disk usage:
df [options] [file system]
32. du
Command
The du
command checks the size of a directory and its content:
du [directory]
33. top
Command
The top
command displays running processes and their resource usage:
top [options]
34. htop
Command
The htop
command also displays and manages running processes:
htop [options]
35. ps
Command
The ps
command summarizes the status of all running processes:
ps [options]
36. uname
Command
The uname
command displays information about your Linux system:
uname [options]
37. hostname
Command
The hostname
command checks your VPS hostname and related information:
hostname [options]
38. time
Command
The time
command measures the execution time of commands or scripts:
time command_or_script
39. systemctl
Command
The systemctl
command manages services in your Linux system:
systemctl subcommand [service_name] [options]
40. watch
Command
The watch
command continuously runs a utility at a specified interval:
watch [options] command_name
Adjust the interval with -n
and highlight changes with -d
.
41. jobs
Command
Jobs are tasks or commands running in your current shell. To check them, use:
jobs [options] [Job_ID]
Running this command without any arguments will display all jobs in the Terminal’s foreground and background. Add the -l
option for detailed information about each job, or -n
to show tasks whose status has changed since the last notification.
42. kill
Command
Use the kill
command to terminate a process using its ID:
kill [signal_option] Process_ID
To obtain the process ID, run:
ps ux
The kill
command has 64 termination signals. By default, it uses the SIGTERM method, allowing the program to save its progress before closing.
43. shutdown
Command
The shutdown
command turns off or restarts your Linux system at a specific time:
shutdown [option] [time] [message]
Without arguments, the system shuts down immediately. Use a 24-hour format or a relative time (e.g., +5
for five minutes). Add the -r
option to restart. The message
argument notifies other users before shutdown.
44. ping
Command
The ping
command sends packets to a target server and retrieves responses, useful for network diagnostics:
ping [option] [hostname_or_IP_address]
By default, ping
sends infinite packets until stopped manually (Ctrl + C). Use the -c
option to specify a number of packets and -i
to change the interval. For example:
ping -c 15 -i 2 google.com
45. wget
Command
The wget
command downloads files from the internet via HTTP, HTTPS, or FTP:
wget [options] [URL]
By default, it downloads to your current working directory. For example:
wget https://wordpress.org/latest.zip
46. cURL
Command
Use the cURL
command to transfer data from or to a server:
curl [options] URL
Without options, it prints the HTML content. Use -O
or -o
to download files. To test API endpoints, add -X
followed by an HTTP method. For example:
curl -X GET https://api.example.com/endpoint
47. scp
Command
The scp
command securely copies files and directories between systems over a network:
scp [option] [source username@IP]:/[directory and file name] [destination username@IP]:/[destination directory]
For example, to copy file1.txt
to your VPS’ path/to/folder directory as root:
scp file1.txt [email protected]:path/to/folder
48. rsync
Command
The rsync
command syncs files or folders between two locations:
rsync [options] source destination
Specify username and IP address for syncing with a VPS:
rsync /path/to/local/folder/ [email protected]:/path/to/remote/folder/
49. ip
Command
The ip
utility lists and manages your system’s network parameters:
ip [options] object command
To show your system’s IP address:
ip address show
50. netstat
Command
The netstat
command displays information about your system’s network configuration:
netstat [options]
Flags include:
-a
– displays listening and closed sockets-t
– shows TCP connections-u
– lists UDP connections-r
– displays routing tables-i
– shows information about network interfaces-c
– continuously outputs network information for real-time monitoring
51. traceroute
Command
The traceroute
command tracks a packet’s path between hosts:
traceroute [options] destination
Use -m
to change the maximum packet hops and -n
to prevent resolving IP addresses.
52. nslookup
Command
The nslookup
command requests a DNS server to check a domain linked to an IP address or vice versa:
nslookup [options] domain-or-ip [dns-server]
Use -type=
to specify the DNS records to check.
53. dig
Command
The dig
command displays information about a domain:
dig [options] [server] [type] name-or-ip
Use -x
for a reverse DNS lookup.
54. history
Command
The history
command checks previously run utilities:
history [options]
Use -r
to clear Terminal history. Rerun a specific utility with an exclamation mark and its ID. For example:
!145
55. man
Command
The man
command displays a guide for another utility:
man [options] [section_number] command_name
Specify a section for more specific information. For example:
man 3 ls
56. echo
Command
Use echo
to print text as a Terminal output:
echo [options] [text]
Redirect output to a file with >
or >>
. For example:
echo [options] [text] > [file_name]
57. ln
Command
The ln
command links files or directories with a shortcut:
ln [options] source target
For example:
ln target.txt shortcut.txt
58. alias
and unalias
Commands
The alias
command sets an alternative name for a string:
alias name='string'
For example:
alias k='kill'
Remove an alias with:
unalias [name]
59. cal
Command
The cal
command displays a calendar in your Terminal:
cal [options] [month] [year]
Use -3
to show the current, previous, and next month.
60. apt
and dnf
Commands
The apt
command manages Advanced Package Tool (APT) libraries in Debian-based systems like Ubuntu and Kali Linux:
apt [options] subcommand
Subcommands define actions such as updating libraries, upgrading software, installing applications, or removing packages. For instance, to install the Vim text editor:
apt install vim
In Linux, package management commands differ across distributions. Red Hat-based distros like CentOS and AlmaLinux use dnf
, which shares the same syntax and options as apt
. Both commands require superuser privileges, which you can obtain with sudo
or by switching to the root user.
Conclusion
Linux commands enable system administrators to efficiently manage their servers, offering capabilities like scripting, variables, and automation that surpass graphical interfaces. This tutorial has covered the 60 most commonly used Linux commands, essential for tasks like file management, user administration, navigation, and network configuration.