Linux Commands Cheat Sheet
Essential Linux commands for files, permissions, processes, networking, disk usage, and shell scripting in one quick-reference page.
8 sections 23 snippets
Files and Directories
Navigate
pwd # print working directory
ls -la # list all with details
cd /var/log # change directory
cd ~ # home directory
cd - # previous directory Create and remove
mkdir -p src/components # create nested dirs
touch file.txt # create empty file
rm file.txt # remove file
rm -rf directory/ # remove dir recursively Copy and move
cp file.txt backup.txt
cp -r src/ src-backup/
mv old.txt new.txt # rename
mv file.txt /tmp/ # move Find files
find . -name '*.log'
find /var -size +100M
find . -mtime -7 -name '*.py' File Contents
View files
cat file.txt
less file.txt # paginated
head -20 file.txt # first 20 lines
tail -50 file.txt # last 50 lines
tail -f /var/log/app.log # follow in real-time Search with grep
grep 'error' app.log
grep -r 'TODO' src/ # recursive
grep -i 'warning' log.txt # case-insensitive
grep -c 'error' app.log # count matches Text processing
sort file.txt | uniq # unique sorted lines
wc -l file.txt # count lines
cut -d',' -f1,3 data.csv # extract columns
sed 's/old/new/g' file.txt # find and replace Permissions
Change permissions
chmod 755 script.sh # rwxr-xr-x
chmod +x script.sh # add execute
chmod -R 644 docs/ # recursive Change ownership
chown user:group file.txt
chown -R www-data:www-data /var/www/ Permission numbers
# r=4 w=2 x=1
# 755 = rwxr-xr-x (owner:all, group:rx, other:rx)
# 644 = rw-r--r-- (owner:rw, group:r, other:r)
# 700 = rwx------ (owner only) Processes
View processes
ps aux # all processes
ps aux | grep node # filter
top # real-time
htop # interactive (if installed) Manage processes
kill 1234 # graceful stop (SIGTERM)
kill -9 1234 # force kill (SIGKILL)
killall node # kill by name Background jobs
command & # run in background
nohup command & # survives terminal close
jobs # list background jobs
fg %1 # bring job 1 to foreground Networking
Connectivity
ping google.com
curl -I https://example.com # headers only
curl -X POST -d '{"a":1}' -H 'Content-Type: application/json' url
wget https://example.com/file.tar.gz Ports and connections
ss -tlnp # listening TCP ports
netstat -tlnp # alternative
lsof -i :3000 # what's using port 3000 DNS
dig example.com
nslookup example.com
host example.com Disk and Memory
Disk usage
df -h # filesystem usage
du -sh * # directory sizes
du -sh /var/log # specific directory
ncdu / # interactive (if installed) Memory
free -h # RAM usage
vmstat 1 # virtual memory stats Archives and Compression
tar
tar -czf archive.tar.gz src/ # create gzipped
tar -xzf archive.tar.gz # extract gzipped
tar -tf archive.tar.gz # list contents zip
zip -r archive.zip src/
unzip archive.zip Useful One-liners
Pipe and redirect
command > out.txt # overwrite
command >> out.txt # append
command 2>&1 # stderr to stdout
command1 | command2 # pipe xargs
find . -name '*.log' | xargs rm
cat urls.txt | xargs -I {} curl {} Watch a command
watch -n 5 'df -h' # run every 5 seconds