Linux Command Line Cheat Sheet: Files, Permissions, Processes, and Networking
Introduction
The Linux command line is a core skill for developers, testers, DevOps engineers, and security professionals. This cheat sheet groups the most useful commands by task. Commands that delete or change data are marked, so read them before you run them.
Prerequisites
- A Linux machine, WSL on Windows, or a macOS terminal (most commands match)
Step-by-Step Guide
Step 1: Navigate and manage files
Paths starting with a slash are absolute. The tilde means your home folder.
pwd # where am I
ls -la # list all files with details
cd /var/log cd ~ cd - cd ..
mkdir -p project/src
cp file.txt backup.txt
cp -r folder folder-copy
mv old.txt new.txt
rm file.txt # DANGER: no recycle bin
rm -r folder # DANGER: deletes a folder and its contents
touch newfile.txt
tree -L 2 # may need installingStep 2: View and search text
grep searches inside files, and find searches for files by name or property.
cat file.txt
less file.txt # scroll; q to quit
head -n 20 file.txt
tail -n 50 file.txt
tail -f app.log # follow a log live
grep "error" app.log
grep -rin "timeout" src/ # recursive, case-insensitive, line numbers
find . -name "*.log" -mtime -1
wc -l file.txt # count linesStep 3: Pipes, redirects, and text tools
A pipe sends one command's output to the next command. Redirects write output to files.
ls | wc -l
cat app.log | grep ERROR | sort | uniq -c | sort -rn | head
echo "hello" > out.txt # overwrite
echo "more" >> out.txt # append
command 2> errors.txt # redirect errors
cut -d, -f1,3 data.csv
sort -u names.txt
sed 's/old/new/g' file.txt
awk '{print $1, $3}' file.txtStep 4: Permissions and ownership
Permissions are read (4), write (2), and execute (1) for owner, group, and others. For example 755 means the owner can do everything and others can read and run.
ls -l # -rwxr-xr-- owner group size date name
chmod 644 file.txt # rw-r--r--
chmod 755 script.sh # rwxr-xr-x
chmod +x script.sh
chown user:group file.txt
sudo command # run as administrator
id; whoamiStep 5: Processes and system
Find what is running and stop it politely before forcing it.
ps aux | grep nginx
top # or htop
kill 1234 # ask the process to stop
kill -9 1234 # DANGER: force kill, no cleanup
pkill -f "node server.js"
df -h # disk space
du -sh * # sizes in the current folder
free -h # memory
uname -a
systemctl status nginx
sudo systemctl restart nginx
journalctl -u nginx -fStep 6: Networking
Check connectivity, listening ports, and download or call web resources.
ping -c 4 example.com
ip addr
ss -tulpn # listening ports and their processes
curl -I https://example.com # headers only
curl -s https://api.example.com/items | head
wget https://example.com/file.zip
ssh user@server
scp file.txt user@server:/tmp/
nslookup example.comStep 7: Packages, archives, and environment
On Debian and Ubuntu use apt. Environment variables configure programs without changing code.
sudo apt update && sudo apt upgrade -y
sudo apt install -y git curl
tar -czf backup.tar.gz folder/
tar -xzf backup.tar.gz
zip -r site.zip site/ ; unzip site.zip
export API_URL="https://example.com"
echo "$API_URL"
env | sort
which python3
history | grep sshFAQs
- How do I avoid deleting the wrong thing?
- Run ls with the same path or pattern first to see what matches, avoid rm with wildcards at the root of anything important, and keep backups. Be especially careful with sudo and rm -r.
Summary
Learn navigation, grep and find, pipes, permissions with chmod and chown, process and system checks, and networking tools, and check what a destructive command will touch before you run it.
Related tutorials
- Docker and kubectl Cheat Sheet: Containers, Images, Compose, and Kubernetes
- SQL Cheat Sheet: SELECT, Joins, Aggregates, and Data Changes
- Git Cheat Sheet: Everyday Commands, Branching, and Undoing Mistakes
- Langflow Cheat Sheet: Install, Components, API Calls, and Custom Components
- LangGraph Cheat Sheet: StateGraph, Routing, Memory, and Human-in-the-Loop
Comments
Log in or create a free account to join the discussion.