Skip to main content

Linux Commands Cheatsheet

DevOps 14 views Apr 2026

Navigation & File System

pwd                     # print working directory
ls                      # list files
ls -la                  # list all (including hidden) with details
ls -lh                  # human-readable sizes

cd /path/to/dir         # change directory
cd ~                    # home directory
cd -                    # previous directory
cd ..                   # parent directory

tree                    # display directory tree
tree -L 2               # limit depth to 2

File Operations

touch file.txt          # create empty file / update timestamp
mkdir folder            # create directory
mkdir -p a/b/c          # create nested directories

cp file.txt dest/       # copy file
cp -r src/ dest/        # copy directory recursively
mv file.txt newname.txt # move / rename
rm file.txt             # delete file
rm -rf folder/          # delete directory (careful!)

ln -s /original /link   # create symbolic link
find . -name "*.log"    # find files by name
find . -mtime -7        # files modified in last 7 days
find . -size +100M      # files larger than 100MB

Viewing & Editing Files

cat file.txt            # print file
less file.txt           # page through (q to quit)
head -20 file.txt       # first 20 lines
tail -20 file.txt       # last 20 lines
tail -f app.log         # follow log in real time

nano file.txt           # simple editor
vim file.txt            # vi editor (i=insert, :wq=save+quit, :q!=quit)

# Redirect
echo "hello" > file.txt    # overwrite
echo "world" >> file.txt   # append
command > out.txt 2>&1     # redirect stdout + stderr
command &> out.txt         # shorthand

Searching & Text Processing

grep "pattern" file.txt        # search in file
grep -r "pattern" ./folder     # recursive search
grep -i "Pattern" file.txt     # case-insensitive
grep -n "pattern" file.txt     # show line numbers
grep -v "pattern" file.txt     # invert (exclude)

awk '{print $1, $3}' file    # print columns 1 and 3
awk -F: '{print $1}' /etc/passwd  # use : as delimiter

sed 's/old/new/g' file.txt        # replace in output
sed -i 's/old/new/g' file.txt     # replace in-place

sort file.txt                   # sort lines
sort -r file.txt                # reverse sort
sort -n file.txt                # numeric sort
uniq                            # remove adjacent duplicates
sort file.txt | uniq -c         # count occurrences
wc -l file.txt                  # count lines
cut -d',' -f1 file.csv         # cut first column (CSV)

Permissions

# Format: [type][owner][group][others]  e.g. -rwxr-xr--
# r=4  w=2  x=1

chmod 755 script.sh     # rwxr-xr-x
chmod +x script.sh      # add execute
chmod -w file.txt       # remove write
chmod -R 644 folder/    # recursive

chown user:group file   # change owner
chown -R www-data:www-data /var/www

# SUID, SGID, Sticky bit
chmod u+s /usr/bin/prog   # SUID
chmod g+s /shared/        # SGID
chmod +t /tmp/            # sticky bit

umask 022               # default permission mask

Process Management

ps aux                  # all running processes
ps aux | grep nginx     # find process
top                     # interactive process viewer
htop                    # better interactive viewer

kill 1234               # kill by PID (SIGTERM)
kill -9 1234            # force kill (SIGKILL)
killall nginx           # kill by name
pkill -f "python app"   # kill by pattern

bg                      # resume in background
fg                      # bring to foreground
jobs                    # list background jobs
nohup cmd &             # run immune to hangup

# Run in background
command &
# Detach completely
screen -S mysession
tmux new -s mysession

Networking

ip addr                 # show IP addresses
ip route                # show routing table
ifconfig                # (older) network interfaces

ping google.com
ping -c 4 google.com    # 4 packets only

curl https://api.example.com
curl -X POST -H "Content-Type: application/json"      -d '{"key":"val"}' https://api.example.com/endpoint
curl -o file.zip https://example.com/file.zip

wget https://example.com/file.zip

ss -tlnp                # listening TCP ports
netstat -tlnp           # (older) listening ports

ssh user@host
ssh -i key.pem user@host
scp file.txt user@host:/path/    # copy to remote
rsync -avz src/ user@host:/dest/ # sync directories

nc -zv host 80          # test port connectivity
traceroute google.com
nslookup example.com
dig example.com

Disk & System

df -h                   # disk usage (filesystems)
du -sh folder/          # folder size
du -sh * | sort -h      # sorted sizes in current dir

free -h                 # memory usage
vmstat 1                # system stats every 1 second
iostat                  # I/O statistics

uname -a                # kernel info
hostname
whoami
id                      # current user + groups

uptime                  # system uptime + load average
history                 # command history
history | grep docker   # search history

# Environment
export VAR=value
echo $HOME $PATH
env                     # all environment variables

# Cron
crontab -e              # edit cron jobs
crontab -l              # list cron jobs
# Format: min hour day month weekday command
# 0 2 * * * /backup.sh  → daily at 2am

Found this helpful? Share it!

Tweet LinkedIn WhatsApp
Translate Page