Cheat sheets

Cheat sheet: Linux

The Linux commands you need most in the terminal, organized by task.

Looking around

Where am I? pwd
Show files and folders ls -lah
Go to a folder cd /path/to/folder
Go to your home folder cd ~
Show a tree structure tree -L 2
Find files by name find /path -name "*.log"
Search for text in files grep -rn "tekst" /path
The type of a file file file

Managing files

Copy a file cp source destination
Copy a folder cp -r folder destination
Move or rename mv oud nieuw
Create a folder mkdir -p path/to/folder
Delete a file rm file
Delete a folder (watch out!) rm -r folder
Create a file or update the date touch file
Create a shortcut ln -s destination name

Reading files

Show a file cat file
Read page by page less file
The first 20 lines head -n 20 file
The last 20 lines tail -n 20 file
Follow a log file live tail -f /var/log/syslog
Count lines wc -l file
Edit in the terminal nano file

Permissions

Make executable chmod +x script.sh
Set permissions (owner all, others read) chmod 644 file
Change the owner sudo chown user:group file
Change an entire folder sudo chown -R user:group folder
Who am I and in which groups? id

System

How long has the system been running? uptime
Memory usage free -h
Disk space per disk df -h
Size of folders du -sh * | sort -h
View processes live top
All processes ps aux
Stop a process kill PID
Force a process to stop kill -9 PID
The kernel and version uname -a
The Linux distribution cat /etc/os-release
Reboot sudo reboot
Shut down sudo poweroff

Network

Show IP addresses ip -br a
The default route ip route
Show listening ports sudo ss -tulpn
Ping a computer ping -c 4 1.1.1.1
The route to a computer traceroute example.com
Make a DNS query dig example.com
Fetch a page curl -I https://example.com
Download a file wget https://example.com/file.zip

Packages (Debian and Ubuntu)

Update lists sudo apt update
Update everything sudo apt full-upgrade
Install a package sudo apt install pakket
Remove a package sudo apt remove pakket
Search for a package apt search woord
Clean up unused packages sudo apt autoremove

Archives

Create a tar.gz tar -czf archief.tar.gz folder
Extract a tar.gz tar -xzf archief.tar.gz
Extract a zip unzip file.zip
Show the contents of an archive tar -tzf archief.tar.gz

Useful tricks

Repeat the previous command with sudo sudo !!
Search the history history | grep woord
Search in the history Ctrl + R
Run a command in the background nohup commando > uit.log 2>&1 &
Output to a file and the screen commando | tee output.txt
Schedule a task with cron crontab -e

Good to know

  • Use the Tab key to complete names; use the arrow keys to recall previous commands.
  • Be careful with rm -r and sudo: there is no trash bin.
  • More: systemd, SSH, rsync.

Sources and attribution

This overview is compiled in our own words. Commands and options change per version: check the official documentation when in doubt.