The 40 Essential Linux Commands Every User Should Know
Linux is a family of open-source operating systems based on the Linux kernel. Distributions like Ubuntu, Fedora, Debian, and Red Hat are widely used on servers, mobile devices, and personal computers. One of the most powerful and distinctive features of Linux is its command-line interface (CLI), which allows users to interact directly with the operating system through text commands.
While graphical user interfaces (GUIs) make many tasks more accessible, mastering the command line offers deeper and more efficient control over the system. It allows you to automate processes, manage systems remotely, and perform tasks that may not be available through the GUI.
In this article, we will explore 40 essential Linux commands that every user should know. These commands will help you navigate the file system, manage processes, manipulate files, and much more. Additionally, we will provide practical examples and additional tips to get the most out of each command.
What is a Linux Command?
A Linux command is an instruction entered into the terminal to perform a specific task. The terminal is a text-based interface that allows users to interact directly and efficiently with the operating system. Through commands, you can run programs, manage files, configure systems, and perform virtually any task in Linux.
The general syntax of a Linux command is:
1
command_name [options] [arguments]
- command_name: The program or utility you want to execute.
- options: Modifiers that alter the behavior of the command. They usually start with one or two dashes (e.g.,
-a
or--all
). - arguments: Files, directories, or other data on which the command acts.
It is important to remember that Linux distinguishes between uppercase and lowercase letters, so ls
and LS
are different commands.
The 40 Most Used Linux Commands
Below is a detailed list of the most essential Linux commands, organized to facilitate understanding and use.
1. sudo
Command
Allows users to run programs with the security privileges of another user, typically the superuser (root).
Syntax:
1
sudo [command]
Example:
1
sudo apt-get update
This command updates the list of available packages on the system.
Tip: Use sudo
with caution, as it executes commands with elevated privileges.
2. pwd
Command
Displays the full path of the current working directory.
Syntax:
1
pwd
Example:
1
/home/user
3. cd
Command
Changes the current working directory.
Syntax:
1
cd [path]
Examples:
Go to the
Documents
directory:1
cd Documents
Return to the previous directory:
1
cd ..
Go to the home directory:
1
cd ~
4. ls
Command
Lists files and directories in the current directory.
Syntax:
1
ls [options] [path]
Examples:
List in detailed format:
1
ls -l
Include hidden files:
1
ls -a
List with human-readable sizes:
1
ls -lh
5. cat
Command
Displays the content of files, concatenates files, and redirects outputs.
Syntax:
1
cat [options] [file...]
Examples:
Display the content of a file:
1
cat file.txt
Combine files:
1
cat file1.txt file2.txt > combined.txt
6. cp
Command
Copies files and directories.
Syntax:
1
cp [options] source destination
Examples:
Copy a file:
1
cp file.txt /path/to/destination/
Copy a directory:
1
cp -r source_folder destination_folder
7. mv
Command
Moves or renames files and directories.
Syntax:
1
mv [options] source destination
Examples:
Move a file:
1
mv file.txt /path/to/destination/
Rename a file:
1
mv old_name.txt new_name.txt
8. mkdir
Command
Creates new directories.
Syntax:
1
mkdir [options] directory_name
Examples:
Create a directory:
1
mkdir new_folder
Create nested directories:
1
mkdir -p project/{src,bin,doc}
9. rmdir
Command
Deletes empty directories.
Syntax:
1
rmdir [options] directory_name
Example:
1
rmdir empty_folder
10. rm
Command
Deletes files and directories.
Syntax:
1
rm [options] file_or_directory
Warning: This command deletes permanently.
Examples:
Delete a file:
1
rm file.txt
Delete a directory and its contents:
1
rm -r folder
Force deletion without confirmation:
1
rm -rf folder
11. touch
Command
Creates empty files or updates the timestamp of existing files.
Syntax:
1
touch file_name
Example:
1
touch new_file.txt
12. locate
Command
Searches for files by name.
Syntax:
1
locate [options] pattern
Example:
1
locate document.pdf
13. find
Command
Searches for files and directories in a hierarchy.
Syntax:
1
find [path] [conditions]
Examples:
Search for files by name:
1
find /path -name "file.txt"
Search for files by size:
1
find /path -size +100M
14. grep
Command
Searches for text patterns within files.
Syntax:
1
grep [options] pattern [file...]
Examples:
Search for a word in a file:
1
grep "error" log.txt
Search recursively:
1
grep -r "function" /path/project
15. df
Command
Displays information about the file system usage.
Syntax:
1
df [options]
Example:
1
df -h
16. du
Command
Reports disk space usage.
Syntax:
1
du [options] [path]
Examples:
Show the size of a folder:
1
du -sh folder
List sizes of subdirectories:
1
du -h folder
17. head
Command
Displays the first lines of a file.
Syntax:
1
head [options] [file]
Example:
1
head -n 20 file.txt
18. tail
Command
Displays the last lines of a file.
Syntax:
1
tail [options] [file]
Examples:
Show the last 10 lines:
1
tail file.txt
Follow updates in real-time:
1
tail -f log.txt
19. diff
Command
Compares files line by line.
Syntax:
1
diff [options] file1 file2
Example:
1
diff original.txt modified.txt
20. tar
Command
Archives and compresses files.
Syntax:
1
tar [options] archive.tar [files]
Examples:
Create a tar archive:
1
tar -cvf archive.tar folder/
Extract a tar archive:
1
tar -xvf archive.tar
Compress with gzip:
1
tar -czvf archive.tar.gz folder/
21. chmod
Command
Changes file and directory permissions.
Syntax:
1
chmod [options] mode file_or_directory
Example:
1
chmod 755 script.sh
22. chown
Command
Changes the owner and group of files and directories.
Syntax:
1
chown [options] user[:group] file_or_directory
Example:
1
chown user:group file.txt
23. jobs
Command
Displays background jobs in the current session.
Syntax:
1
jobs [options]
Example:
1
jobs
24. kill
Command
Sends signals to processes.
Syntax:
1
kill [options] PID
Example:
1
kill 12345
25. ping
Command
Checks connectivity with a host.
Syntax:
1
ping [options] destination
Example:
1
ping www.google.com
26. wget
Command
Downloads files from the internet.
Syntax:
1
wget [options] URL
Example:
1
wget https://example.com/file.zip
27. uname
Command
Displays system information.
Syntax:
1
uname [options]
Example:
1
uname -a
28. top
Command
Monitors processes in real-time.
Syntax:
1
top
29. history
Command
Shows the command history.
Syntax:
1
history
Example:
1
history
30. man
Command
Displays the user manual of commands.
Syntax:
1
man command
Example:
1
man ls
31. echo
Command
Displays text in the standard output.
Syntax:
1
echo [options] text
Example:
1
echo "Hello World"
32. zip
and unzip
Commands
Compress and decompress files in ZIP format.
Syntax:
Compress:
1
zip [options] archive.zip files
Decompress:
1
unzip [options] archive.zip
Examples:
Compress:
1
zip files.zip file1.txt file2.txt
Decompress:
1
unzip files.zip
33. hostname
Command
Displays or sets the hostname.
Syntax:
1
hostname [new_name]
Example:
1
hostname
34. useradd
and userdel
Commands
Manage user accounts.
Syntax:
Add user:
1
sudo useradd [options] username
Delete user:
1
sudo userdel [options] username
Examples:
Add user:
1
sudo useradd john
Set password:
1
sudo passwd john
Delete user:
1
sudo userdel john
35. apt-get
Command
Manages packages on Debian-based systems.
Syntax:
1
sudo apt-get command [package]
Examples:
Update package list:
1
sudo apt-get update
Install a package:
1
sudo apt-get install package_name
36. Text Editors nano
, vi
, and gedit
Allow editing text files from the terminal or with a graphical interface.
Examples:
Use
nano
:1
nano file.txt
Use
vi
:1
vi file.txt
Use
gedit
(graphical interface):1
gedit file.txt
37. alias
and unalias
Commands
Create and remove aliases for commands.
Syntax:
Create alias:
1
alias alias_name='command'
Remove alias:
1
unalias alias_name
Example:
1
alias ll='ls -la'
38. su
Command
Switches to another user in the current session.
Syntax:
1
su [options] [username]
Example:
1
su -
Switches to the root user.
39. htop
Command
Monitors processes with an interactive interface.
Syntax:
1
htop
Note: You may need to install it:
1
sudo apt-get install htop
40. ps
Command
Displays information about active processes.
Syntax:
1
ps [options]
Example:
Show all processes:
1
ps -e
Additional Tips and Tricks
- Clear the terminal screen: Use
clear
orCtrl + L
. - Autocomplete commands and paths: Press
Tab
. - Cancel a running command: Press
Ctrl + C
. - Pause a running process: Press
Ctrl + Z
. - Resume a background process: Use
bg
. - Bring a process to the foreground: Use
fg
. - Freeze the terminal: Press
Ctrl + S
. - Unfreeze the terminal: Press
Ctrl + Q
. - Navigate to the beginning or end of the line: Use
Ctrl + A
andCtrl + E
. - Run multiple commands in one line: Separate with
;
or use&&
to execute the next only if the previous succeeds.
List of Linux Commands
Command | Usage |
---|---|
alias | Creates an alias to run a command. |
apt-get | Manages packages resolving dependencies. |
cat | Displays, combines, and creates files. |
cd | Changes directory. |
chmod | Modifies read, write, and execute permissions. |
chown | Changes the owner and group of files or directories. |
cp | Copies files or directories and their content. |
df | Reports disk space usage. |
diff | Compares files or directories. |
du | Checks how much space a file or directory occupies. |
echo | Displays a string of text. |
find | Searches for files and directories. |
grep | Searches for text strings within files. |
head | Displays the first lines of a file. |
history | Lists previously executed commands. |
hostname | Displays or sets the system’s hostname. |
htop | Monitors system resources and server processes. |
jobs | Shows background processes running in the shell. |
kill | Manually terminates a non-responsive program. |
locate | Finds files on the system. |
ls | Displays the contents of a directory. |
man | Provides a user manual of a command or utility. |
mkdir | Creates one or more directories. |
mv | Moves or renames files and directories. |
nano , vi , gedit | Text editors. |
ping | Checks network connectivity with another host. |
ps | Produces a snapshot of running processes. |
pwd | Displays the path of the current working directory. |
rm | Deletes files or directories. |
rmdir | Deletes empty directories. |
su | Allows using another user’s shell. |
sudo | Executes commands with administrative privileges. |
tail | Displays the last lines of a file. |
tar | Compresses and decompresses tar files. |
top | Displays running processes in real-time. |
touch | Creates an empty file or updates its timestamp. |
unalias | Removes an existing alias. |
uname | Prints system and hardware information. |
unzip | Decompresses zip files. |
useradd , userdel | Adds or deletes user accounts. |
wget | Downloads files from the web. |
zip | Compresses multiple files into a zip archive. |
Mastering these Linux commands will allow you to take full advantage of the power and flexibility that the operating system offers. The command line is an essential tool for system administrators, developers, and anyone looking to interact efficiently with Linux.
I recommend practicing regularly and exploring the different options each command offers. Feel free to consult the manual pages with man [command]
for detailed information.
Dive into the world of Linux and discover all you can achieve with these essential commands!