Linux Commands Cheat Sheet
Last updated
Navigation
Move around and see where you are.
| Command | What it does |
|---|---|
pwd | Print the current directory path |
ls | List files in the current directory |
ls -la | List all files (incl. hidden) with details |
cd /path/to/dir | Change to a directory |
cd .. | Go up one directory |
cd ~ | Go to your home directory |
cd - | Go back to the previous directory |
File management
Create, copy, move, and delete files and folders.
| Command | What it does |
|---|---|
touch file.txt | Create an empty file |
mkdir mydir | Create a directory |
mkdir -p a/b/c | Create nested directories |
cp src.txt dest.txt | Copy a file |
cp -r src/ dest/ | Copy a directory recursively |
mv old.txt new.txt | Move or rename |
rm file.txt | Delete a file |
rm -rf mydir | Delete a directory and its contents |
Viewing files
Read file contents in the terminal.
| Command | What it does |
|---|---|
cat file.txt | Print the whole file |
less file.txt | Scroll through a file page by page |
head file.txt | Show the first 10 lines |
head -n 20 file.txt | Show the first 20 lines |
tail file.txt | Show the last 10 lines |
tail -f log.txt | Follow a file as it grows |
wc -l file.txt | Count lines in a file |
Searching (grep & find)
Search inside files and find files by name.
| Command | What it does |
|---|---|
grep "text" file.txt | Find lines matching a pattern |
grep -r "text" . | Search recursively in a folder |
grep -i "text" file.txt | Case-insensitive search |
grep -n "text" file.txt | Show matching line numbers |
find . -name "*.js" | Find files by name pattern |
find . -type d | Find directories only |
find . -mtime -1 | Files modified in the last day |
Permissions (chmod & chown)
Control who can read, write, and execute.
| Command | What it does |
|---|---|
chmod +x script.sh | Make a file executable |
chmod 755 script.sh | Owner rwx, group/others rx |
chmod 644 file.txt | Owner rw, group/others read-only |
chmod -R 755 mydir | Apply recursively to a folder |
chown user file.txt | Change the owner |
chown user:group file.txt | Change owner and group |
ls -l file.txt | View a file's permissions |
Process management
See and control running programs.
| Command | What it does |
|---|---|
ps aux | List all running processes |
top | Live view of processes and resources |
htop | Interactive process viewer |
kill <pid> | Stop a process by its ID |
kill -9 <pid> | Force-stop a process |
pkill firefox | Stop processes by name |
jobs | List background jobs in the shell |
command & | Run a command in the background |
Networking (curl, wget, ssh, ping)
Make requests and connect to other machines.
| Command | What it does |
|---|---|
curl https://api.example.com | Fetch a URL and print the response |
curl -O <url> | Download a file keeping its name |
wget <url> | Download a file from a URL |
ssh user@host | Connect to a remote machine |
scp file.txt user@host:/path | Copy a file to a remote host |
ping example.com | Test connectivity to a host |
ip addr | Show network interfaces and IPs |
Archives & packages (tar & apt)
Bundle files and install software.
| Command | What it does |
|---|---|
tar -czf out.tar.gz mydir | Create a gzipped archive |
tar -xzf out.tar.gz | Extract a gzipped archive |
tar -tzf out.tar.gz | List archive contents |
zip -r out.zip mydir | Create a zip archive |
unzip out.zip | Extract a zip archive |
sudo apt update | Refresh package lists (Debian/Ubuntu) |
sudo apt install pkg | Install a package |
The Linux commands you reach for most, on one page. This Linux commands cheat sheet is a quick reference for working in the terminal - navigating the filesystem, managing files, searching, setting permissions, controlling processes, and basic networking.
These commands are standard on bash and zsh, so they work the same on Linux and macOS. Copy what you need, or try them live in the terminal playground - a real shell in your browser, nothing to install.
Linux commands cheat sheet FAQ
Is this Linux commands cheat sheet free?
What does chmod 755 mean?
755 means the owner gets read + write + execute (4+2+1=7), while the group and others get read + execute (4+1=5). It is the typical mode for scripts and directories that everyone should be able to run or enter but only the owner should change.What is sudo and when do I need it?
sudo runs a single command as the superuser (root), which is required for actions that affect the whole system - installing packages, editing system files, or changing ownership outside your home directory. It will usually prompt for your password. Use it only when a command fails with a permission error, and avoid running everything as root.