Linux cheat sheet
96 one-line examples for Linux. Open it while you code, or print it and keep it near the keyboard. Free, with no signup and no ads.
Files and Folders
| Code | What it does |
|---|---|
ls | List files in the current folder. |
ls -l | List files with details and permissions. |
ls -a | Show hidden files that start with a dot. |
cd /home | Change to the /home folder. |
cd .. | Go up one folder level. |
pwd | Print the full path of the current folder. |
mkdir notes | Create a new folder named notes. |
cp a.txt b.txt | Copy a.txt to b.txt. |
mv a.txt b.txt | Rename a.txt to b.txt. |
rm a.txt | Delete the file a.txt. |
rm -r old | Delete the folder old and its contents. |
touch new.txt | Create an empty file named new.txt. |
View and Edit Files
| Code | What it does |
|---|---|
cat file.txt | Print the whole file to the screen. |
less file.txt | Open a file one page at a time. |
head -n 5 log.txt | Show the first five lines of a file. |
tail -n 5 log.txt | Show the last five lines of a file. |
tail -f log.txt | Follow a file as it grows. |
nano file.txt | Open a simple text editor. |
vim file.txt | Open the vim text editor. |
wc -l file.txt | Count the lines in a file. |
grep error log.txt | Find lines that contain the word error. |
grep -i error log.txt | Find lines and ignore letter case. |
grep -r todo . | Search for todo in all files here. |
sort file.txt | Print the lines in sorted order. |
Permissions
| Code | What it does |
|---|---|
chmod +x run.sh | Make run.sh executable. |
chmod 644 file.txt | Set owner write and others read only. |
chmod 755 script.sh | Set owner full access and others read and run. |
chown ana file.txt | Change the owner of file.txt to ana. |
chown ana:dev file.txt | Change the owner and group of a file. |
umask | Show the default permission mask. |
id | Show your user and group IDs. |
whoami | Print your current user name. |
groups | List the groups you belong to. |
sudo command | Run one command as the root user. |
sudo -i | Start a root shell. |
passwd | Change your own password. |
Processes
| Code | What it does |
|---|---|
ps aux | List all running processes. |
top | Show live process and CPU usage. |
htop | Show a friendly live process viewer. |
kill 1234 | Stop the process with PID 1234. |
kill -9 1234 | Force stop the process with PID 1234. |
pkill firefox | Stop all processes named firefox. |
jobs | List jobs started in this shell. |
sleep 60 & | Run a command in the background. |
fg | Bring a background job to the front. |
Ctrl+C | Stop the running command. |
Ctrl+Z | Pause the running command. |
uptime | Show how long the system has run. |
Search and Find
| Code | What it does |
|---|---|
find . -name '*.txt' | Find all text files under this folder. |
find . -type d | Find all folders under this folder. |
find . -size +10M | Find files larger than ten megabytes. |
find . -mtime -1 | Find files changed in the last day. |
locate report.pdf | Find a file by name in the index. |
which python3 | Show the path of a command. |
whereis ls | Show binary and manual paths for ls. |
type cd | Show what kind of command cd is. |
grep -n error log.txt | Find lines and show line numbers. |
grep -c error log.txt | Count lines that contain error. |
grep -v error log.txt | Show lines that do not contain error. |
history | Show your recent commands. |
Disk and System
| Code | What it does |
|---|---|
df -h | Show free space on all disks. |
du -sh folder | Show the total size of a folder. |
free -h | Show memory use in easy units. |
lsblk | List block devices such as disks. |
mount | Show mounted file systems. |
uname -a | Show kernel and system details. |
hostname | Show the name of this machine. |
date | Show the current date and time. |
cal | Show a calendar for this month. |
lscpu | Show CPU details. |
uptime -p | Show system run time in words. |
dmesg | tail | Show the last kernel messages. |
Network
| Code | What it does |
|---|---|
ip addr | Show network interfaces and addresses. |
ip route | Show the routing table. |
ping -c 4 example.com | Send four test packets to a host. |
curl https://example.com | Fetch a web page to the screen. |
curl -O https://x.com/f.zip | Download a file and keep its name. |
wget https://x.com/f.zip | Download a file with wget. |
ssh ana@server | Open a secure shell on a server. |
scp a.txt ana@server: | Copy a file to a remote server. |
ss -tuln | Show listening network ports. |
host example.com | Look up the IP address of a name. |
dig example.com | Query DNS records for a name. |
traceroute example.com | Show the path packets take to a host. |
Packages and Help
| Code | What it does |
|---|---|
sudo apt update | Refresh the package list on Debian systems. |
sudo apt install git | Install the git package. |
sudo apt remove git | Remove the git package. |
sudo apt upgrade | Install newer versions of packages. |
sudo dnf install git | Install git on Fedora systems. |
sudo pacman -S git | Install git on Arch systems. |
man ls | Open the manual page for ls. |
man -k copy | Search manual pages for the word copy. |
ls --help | Show a short help text for ls. |
help cd | Show help for a shell builtin. |
tar -czf a.tar.gz dir | Make a compressed archive of a folder. |
tar -xzf a.tar.gz | Extract a compressed archive. |