Essential Linux Commands with
Subcommands
1. ls — List directory contents
Command Purpose
ls List files and directories.
ls -l List in long format (details like
permissions, owner, size, date).
ls -a Show all files including hidden files (those
starting with `.`).
ls -lh Long format with human-readable sizes (K,
M, G).
ls -R List directories and their subdirectories
recursively.
2. cd — Change directory
Command Purpose
cd /home Go to `/home` directory.
cd .. Move up one directory level.
cd ~ Go to the home directory.
cd - Go to the previous directory.
3. pwd — Print working directory
Command Purpose
pwd Show the full path of the current directory.
4. mkdir — Make directory
Command Purpose
mkdir test Create a new directory called `test`.
mkdir -p dir1/dir2 Create nested directories.
5. touch — Create a new file
Command Purpose
touch file1 Create a new empty file named `file1`.
6. cp — Copy files/directories
Command Purpose
cp file1 file2 Copy `file1` to `file2`.
cp -r dir1 dir2 Copy directory `dir1` and its contents to
`dir2`.
cp -i Prompt before overwrite.
7. mv — Move or rename
Command Purpose
mv file1 file2 Rename `file1` to `file2`.
mv file1 /path/ Move `file1` to `/path/`.
8. rm — Remove files/directories
Command Purpose
rm file1 Delete `file1`.
rm -r dir1 Delete directory `dir1` recursively.
rm -f file1 Force delete without prompt.
9. cat — View file contents
Command Purpose
cat file1 Show the content of `file1`.
cat file1 file2 Show contents of both files together.
10. chmod — Change file permissions
Command Purpose
chmod 755 file1 Set specific permissions for `file1`.
chmod +x script.sh Make a script executable.
11. chown — Change ownership
Command Purpose
chown user file1 Change owner to `user`.
chown user:group file1 Change both owner and group.
12. df — Disk space usage
Command Purpose
df -h Show disk usage in human-readable form.
13. du — Directory/file size
Command Purpose
du -h Show sizes in human-readable format.
du -sh dir1 Show total size of directory `dir1`.
14. top — System processes
Command Purpose
top Show running processes and system info in
real time.
htop (if installed) Better, interactive version of
`top`.
15. kill — Kill process
Command Purpose
kill PID Kill process by its PID.
kill -9 PID Force kill a stubborn process.
16. man — Manual page
Command Purpose
man ls Show manual for `ls` command.
17. wget — Download from web
Command Purpose
wget http://example.com/file Download a file from a URL.
18. tar — Archive
Command Purpose
tar -cvf archive.tar file1 Create a tar archive.
tar -xvf archive.tar Extract files from archive.
tar -czvf archive.tar.gz dir1 Compress directory with gzip.
19. echo — Print text
Command Purpose
echo 'Hello' Print 'Hello' to the terminal.
echo $HOME Print the value of the HOME environment
variable.
echo 'text' > file Write 'text' to a file (overwrite).
echo 'text' >> file Append 'text' to a file.
20. find — Search for files/directories
Command Purpose
find . -name '*.txt' Find all `.txt` files in the current directory
and subdirectories.
find / -type d -name 'test' Find directories named 'test' starting from
root.
find . -size +10M Find files larger than 10MB.
21. grep — Search inside files
Command Purpose
grep 'word' file Search for 'word' in file.
grep -i 'word' file Case-insensitive search.
grep -r 'word' dir Search recursively in directory.
22. ps — Show running processes
Command Purpose
ps Show processes for the current shell.
ps aux Show all running processes.
ps -ef Show full-format listing of processes.
23. ssh — Secure shell access
Command Purpose
ssh user@host Connect to a remote host via SSH.
ssh -p 2222 user@host Connect using a specific port (2222).
ssh -i key.pem user@host Connect using a private key.
24. sudo — Run as superuser
Command Purpose
sudo command Run a command with root privileges.
sudo -i Start a root shell.
sudo !! Run the last command as root.
25. apt / yum / dnf — Package managers
Command Purpose
sudo apt update Update package list (Debian-based).
sudo apt install package Install a package (Debian-based).
sudo yum install package Install a package (Red Hat-based).
sudo dnf install package Install a package (Fedora).
26. history — Command history
Command Purpose
history Show command history.
!100 Run the command with number 100 from
history.
!! Repeat the last command.
27. clear — Clear terminal
Command Purpose
clear Clear the terminal screen.
28. whoami — Show current user
Command Purpose
whoami Display the current logged-in username.