Linux Commands Cheatsheet
Essential Linux commands for file management, process control, permissions, and system administration.
Useful Linux Resources
- Linux man pages - Official manual pages
- tldr pages - Simplified command examples
- ExplainShell - Explain shell commands
- LinuxCommand.org - Learning the shell
File Navigation
pwd
Print current working directory
ls
List directory contents
ls -la
List all files with details (including hidden)
ls -lh
List files with human-readable sizes
cd <directory>
Change directory
cd ~
Go to home directory
cd -
Go to previous directory
cd ..
Go up one directory
File Operations
touch <file>
Create an empty file or update timestamp
cp <source> <dest>
Copy file
cp -r <source> <dest>
Copy directory recursively
mv <source> <dest>
Move or rename file
rm <file>
Remove file
rm -r <directory>
Remove directory recursively
rm -rf <directory>
Force remove directory (use with caution!)
mkdir <directory>
Create directory
mkdir -p <path/to/directory>
Create nested directories
rmdir <directory>
Remove empty directory
ln -s <target> <link>
Create symbolic link
File Content
cat <file>
Display file contents
less <file>
View file with pagination
head <file>
Show first 10 lines
head -n 20 <file>
Show first 20 lines
tail <file>
Show last 10 lines
tail -f <file>
Follow file updates in real-time
wc <file>
Count lines, words, and characters
wc -l <file>
Count lines only
diff <file1> <file2>
Compare two files
sort <file>
Sort file contents
uniq <file>
Remove duplicate lines
Search & Find
find <path> -name "<pattern>"
Find files by name
find . -type f -name "*.txt"
Find all .txt files
find . -type d -name "logs"
Find directories named "logs"
find . -mtime -7
Find files modified in last 7 days
grep "<pattern>" <file>
Search for pattern in file
grep -r "<pattern>" <directory>
Recursive search in directory
grep -i "<pattern>" <file>
Case-insensitive search
grep -n "<pattern>" <file>
Show line numbers with matches
grep -v "<pattern>" <file>
Show lines NOT matching pattern
which <command>
Show path of command
locate <file>
Find file using database (faster than find)
Permissions
chmod 755 <file>
Set permissions (rwxr-xr-x)
chmod +x <file>
Add execute permission
chmod -w <file>
Remove write permission
chmod u+x <file>
Add execute for owner only
chown <user>:<group> <file>
Change file owner and group
chown -R <user> <directory>
Recursively change owner
chgrp <group> <file>
Change file group
Process Management
ps
Show current processes
ps aux
Show all processes with details
ps aux | grep <name>
Find specific process
top
Interactive process viewer
htop
Enhanced process viewer (if installed)
kill <pid>
Terminate process by ID
kill -9 <pid>
Force kill process
killall <name>
Kill processes by name
pkill <pattern>
Kill processes matching pattern
bg
Resume job in background
fg
Bring job to foreground
jobs
List background jobs
nohup <command> &
Run command that persists after logout
Disk & Storage
df -h
Show disk space usage (human-readable)
du -sh <directory>
Show directory size
du -sh *
Show size of all items in current directory
mount
Show mounted filesystems
fdisk -l
List disk partitions
Network
ping <host>
Test network connectivity
curl <url>
Make HTTP request
wget <url>
Download file from URL
ifconfig
Show network interfaces (deprecated)
ip addr
Show network interfaces (modern)
netstat -tuln
Show listening ports
ss -tuln
Show listening ports (modern)
ssh <user>@<host>
Connect to remote host
scp <file> <user>@<host>:<path>
Copy file to remote host
rsync -avz <source> <dest>
Sync files with compression
Archive & Compression
tar -cvf archive.tar <files>
Create tar archive
tar -xvf archive.tar
Extract tar archive
tar -czvf archive.tar.gz <files>
Create gzipped tar archive
tar -xzvf archive.tar.gz
Extract gzipped tar archive
zip -r archive.zip <directory>
Create zip archive
unzip archive.zip
Extract zip archive
gzip <file>
Compress file with gzip
gunzip <file.gz>
Decompress gzip file
System Information
uname -a
Show system information
hostname
Show hostname
uptime
Show system uptime
whoami
Show current user
id
Show user and group IDs
free -h
Show memory usage
lscpu
Show CPU information
lsblk
List block devices
env
Show environment variables
echo $PATH
Show PATH variable
Text Processing
echo "text"
Print text to stdout
echo "text" > file
Write text to file (overwrite)
echo "text" >> file
Append text to file
cat file1 file2 > combined
Concatenate files
sed 's/old/new/g' <file>
Replace text in file
awk '{print $1}' <file>
Print first column
cut -d',' -f1 <file>
Cut first field (comma delimiter)
tr 'a-z' 'A-Z' < file
Translate lowercase to uppercase
Pipe & Redirection
command > file
Redirect stdout to file
command >> file
Append stdout to file
command 2> file
Redirect stderr to file
command &> file
Redirect both stdout and stderr
command1 | command2
Pipe output to another command
command < file
Read input from file
command1 && command2
Run command2 if command1 succeeds
command1 || command2
Run command2 if command1 fails



