Shell Commands Cheat Sheet
Search or filter 83 common shell commands by level, topic and platform, and copy a name or example. 12 are tagged as Linux tools or not on a default Mac. How it works
Use the Shell Commands Cheat Sheet
Skill Level
Topics
Platform
A fixed list of 83 common shell commands. Commands marked as not on a default macOS install are Linux tools or need a separate install.
| Command | Description | Example | Topic | Platform | Copy |
|---|---|---|---|---|---|
ls | List directory contents | ls -la /home/user | File Operations | Linux and macOS (flags can differ) | |
cd | Change current directory | cd /var/log | File Operations | Linux and macOS (flags can differ) | |
pwd | Print working directory | pwd | File Operations | Linux and macOS (flags can differ) | |
cp | Copy files or directories | cp source.txt dest.txt | File Operations | Linux and macOS (flags can differ) | |
mv | Move or rename files | mv oldname.txt newname.txt | File Operations | Linux and macOS (flags can differ) | |
rm | Remove files or directories | rm -rf tempdir/ | File Operations | Linux and macOS (flags can differ) | |
mkdir | Create a directory | mkdir -p project/src | File Operations | Linux and macOS (flags can differ) | |
touch | Create empty file or update timestamp | touch newfile.txt | File Operations | Linux and macOS (flags can differ) | |
cat | Concatenate and display file content | cat file.txt | Text Processing | Linux and macOS (flags can differ) | |
echo | Print text to stdout | echo "Hello World" | Text Processing | Linux and macOS (flags can differ) | |
less | View file content page by page | less largefile.log | Text Processing | Linux and macOS (flags can differ) | |
head | Display first lines of a file | head -n 20 file.txt | Text Processing | Linux and macOS (flags can differ) | |
tail | Display last lines of a file | tail -f app.log | Text Processing | Linux and macOS (flags can differ) | |
grep | Search text using patterns | grep -i "error" logfile.log | Text Processing | Linux and macOS (flags can differ) | |
chmod | Change file permissions | chmod 755 script.sh | Permissions | Linux and macOS (flags can differ) | |
chown | Change file owner | chown user:group file.txt | Permissions | Linux and macOS (flags can differ) | |
ps | List running processes | ps aux | Process Management | Linux and macOS (flags can differ) | |
top | Show live process activity | top -u username | Process Management | Linux and macOS (flags can differ)The example is written for Linux; on macOS the options differ. | |
kill | Terminate a process by PID | kill -9 1234 | Process Management | Linux and macOS (flags can differ) | |
df | Show disk space usage | df -h | Disk Usage | Linux and macOS (flags can differ) | |
du | Show directory space usage | du -sh /home/user | Disk Usage | Linux and macOS (flags can differ) | |
tar | Create/extract tar archives | tar -czf archive.tar.gz dir/ | Archiving | Linux and macOS (flags can differ) | |
gzip | Compress or decompress files | gzip largefile.log | Archiving | Linux and macOS (flags can differ) | |
ssh | Connect to remote host | ssh [email protected] | SSH | Linux and macOS (flags can differ) | |
git clone | Clone a repository | git clone https://github.com/user/repo.git | Git | Linux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install. | |
git add | Stage changes for commit | git add . | Git | Linux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install. | |
git commit | Commit staged changes | git commit -m "Fix bug" | Git | Linux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install. | |
git push | Push commits to remote | git push origin main | Git | Linux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install. | |
git status | Show working tree status | git status | Git | Linux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install. | |
git log | Show commit history | git log --oneline | Git | Linux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install. | |
uname | Print system information | uname -a | System Info | Linux and macOS (flags can differ) | |
whoami | Print current user name | whoami | System Info | Linux and macOS (flags can differ) | |
date | Display current date and time | date "+%Y-%m-%d" | System Info | Linux and macOS (flags can differ) | |
uptime | Show system uptime | uptime | System Info | Linux and macOS (flags can differ) | |
find | Search for files in a hierarchy | find /home -name "*.txt" | File Operations | Linux and macOS (flags can differ) | |
ln | Create hard or symbolic links | ln -s /usr/local/bin/node node | File Operations | Linux and macOS (flags can differ) | |
rsync | Sync files locally or remotely | rsync -avz src/ user@host:/dest/ | File Operations | Linux and macOS (flags can differ) | |
sed | Stream editor for text transformation | sed 's/old/new/g' file.txt | Text Processing | Linux and macOS (flags can differ) | |
awk | Pattern scanning and processing | awk '{print $1}' file.txt | Text Processing | Linux and macOS (flags can differ) | |
sort | Sort lines of text | sort -k2,2 -n data.csv | Text Processing | Linux and macOS (flags can differ) | |
uniq | Report or omit repeated lines | sort file.txt | uniq -c | Text Processing | Linux and macOS (flags can differ) | |
wc | Count lines, words, and characters | wc -l file.txt | Text Processing | Linux and macOS (flags can differ) | |
ping | Test network connectivity | ping -c 4 google.com | Networking | Linux and macOS (flags can differ) | |
curl | Transfer data from/to servers | curl -I https://example.com | Networking | Linux and macOS (flags can differ) | |
wget | Download files from the web | wget https://example.com/file.zip | Networking | Not on a default macOS install | |
ss | Show socket statistics | ss -tuln | Networking | Not on a default macOS install | |
umask | Set default file permissions | umask 022 | Permissions | Linux and macOS (flags can differ) | |
nohup | Run command immune to hangups | nohup longtask.sh & | Process Management | Linux and macOS (flags can differ) | |
nice | Set process priority | nice -n 10 slowtask.sh | Process Management | Linux and macOS (flags can differ) | |
lsblk | List block devices | lsblk -f | Disk Usage | Not on a default macOS install | |
mount | Mount a filesystem | mount /dev/sdb1 /mnt/data | Disk Usage | Linux and macOS (flags can differ)The example is written for Linux; on macOS the options differ. | |
zip | Create/extract ZIP archives | zip -r archive.zip folder/ | Archiving | Linux and macOS (flags can differ) | |
unzip | Extract ZIP archives | unzip archive.zip -d target/ | Archiving | Linux and macOS (flags can differ) | |
scp | Copy files over SSH | scp file.txt user@host:/remote/ | SSH | Linux and macOS (flags can differ) | |
ssh-keygen | Generate SSH key pairs | ssh-keygen -t ed25519 | SSH | Linux and macOS (flags can differ) | |
ssh-copy-id | Install SSH public key on remote | ssh-copy-id user@host | SSH | Linux and macOS (flags can differ) | |
git diff | Show changes between commits | git diff HEAD~1 | Git | Linux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install. | |
git branch | List or create branches | git branch feature-x | Git | Linux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install. | |
git merge | Merge a branch into current | git merge feature-x | Git | Linux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install. | |
git stash | Temporarily save changes | git stash push -m "WIP" | Git | Linux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install. | |
git reset | Reset current HEAD to a state | git reset --soft HEAD~1 | Git | Linux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install. | |
free | Show memory usage | free -h | System Info | Not on a default macOS install | |
lscpu | Show CPU architecture info | lscpu | System Info | Not on a default macOS install | |
lspci | List PCI devices | lspci -v | System Info | Not on a default macOS install | |
fdfind | Fast file search (fd alternative) | fdfind -e md -t f | File Operations | Not on a default macOS install | |
xargs | Build and execute commands from stdin | find . -name "*.log" | xargs rm | Text Processing | Linux and macOS (flags can differ) | |
jq | JSON processor for the shell | jq '.name' package.json | Text Processing | Linux and macOS (flags can differ) | |
tcpdump | Capture network traffic | tcpdump -i any port 80 | Networking | Linux and macOS (flags can differ) | |
nmap | Network exploration and scanning | nmap -sV 192.168.1.0/24 | Networking | Not on a default macOS install | |
socat | Multipurpose relay tool | socat TCP-LISTEN:8080,fork TCP:localhost:80 | Networking | Not on a default macOS install | |
strace | Trace system calls and signals | strace -e trace=openat,read ls | Process Management | Not on a default macOS install | |
perf | Performance analysis tool | perf stat ./myapp | Process Management | Not on a default macOS install | |
iostat | CPU and I/O statistics | iostat -x 2 5 | Disk Usage | Linux and macOS (flags can differ)The example is written for Linux; on macOS the options differ. | |
dd | Convert and copy files at block level | dd if=/dev/sda of=backup.img bs=1048576 | Disk Usage | Linux and macOS (flags can differ) | |
ssh tunnel | Create SSH port forwarding | ssh -L 8080:localhost:80 user@host | SSH | Linux and macOS (flags can differ) | |
ssh config | Configure SSH hosts in ~/.ssh/config | Host myserver
HostName 192.168.1.1
User admin | SSH | Linux and macOS (flags can differ) | |
git rebase | Reapply commits on top of another base | git rebase -i main | Git | Linux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install. | |
git bisect | Binary search for a buggy commit | git bisect start HEAD v1.0 | Git | Linux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install. | |
git reflog | Show reference log for recovery | git reflog show HEAD | Git | Linux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install. | |
git cherry-pick | Apply specific commits to current branch | git cherry-pick abc123 | Git | Linux and macOS (flags can differ)On a Mac, git comes with the Xcode Command Line Tools or a separate install. | |
sysctl | Configure kernel parameters at runtime | sysctl -w net.ipv4.ip_forward=1 | System Info | Linux and macOS (flags can differ)The example is written for Linux; on macOS the options differ. | |
journalctl | Query systemd journal logs | journalctl -u nginx.service -f | System Info | Not on a default macOS install | |
dmesg | Print kernel ring buffer messages | dmesg -T | tail -20 | System Info | Linux and macOS (flags can differ)The example is written for Linux; on macOS the options differ. |
About the Shell Commands Cheat Sheet
The cheat sheet holds 83 shell commands: 34 beginner, 30 intermediate and 19 advanced, in ten topics. Filter by one skill level, any topics and a platform; each row has a description, an example to copy and a platform note. 12 of the commands are tagged as not on a default macOS install, and Hide commands not on a default Mac leaves the other 71.
Commands on the cheat sheet by topic
| Topic | Commands |
|---|---|
| File Operations | 12 |
| Text Processing | 13 |
| Networking | 7 |
| Permissions | 3 |
| Process Management | 7 |
| Disk Usage | 6 |
| Archiving | 4 |
| SSH | 6 |
| Git | 15 |
| System Info | 10 |
Each command sits under one topic and one skill level, so the topic counts add up to 83. Picking several topics shows the commands under any of them.
How to use this tool
- Type a word or two in Search commands, such as disk or compress, or pick a skill level, or leave all three showing.
- Tick the topics you want. A command shows if it is under any ticked topic and at the chosen level.
- On a Mac, set Platform to Hide commands not on a default Mac to drop the 12 commands tagged as not on a default macOS install.
- Use Copy command name for the bare name, or Copy example for the example line, then read it before you run it.
Frequently asked questions
- Which shell commands are Linux-only and not on macOS?
- The tool tags 12 of its 83 commands as not on a default macOS install: ss, lsblk, free, lscpu, lspci, fdfind, strace, perf, journalctl, wget, nmap and socat. That tag is the tool’s own list. A macOS command index (ss64.com) does list mount, sysctl, tcpdump and iostat, so those four are not tagged, and macOS ships its own dmesg, which needs root and has no -T flag. Their flags can still differ from the Linux versions: the iostat, top, sysctl, mount and dmesg examples are written for Linux and say so in the table. The git rows come with the Xcode Command Line Tools on a Mac.
- What is the difference between Copy command name and Copy example?
- Copy command name copies the bare command, such as grep or git commit. Copy example copies the whole example line, such as grep -i "error" logfile.log. Both report that they copied, or that the browser blocked the clipboard.
- Are the examples safe to paste into a terminal?
- Read each one first and change the paths. The list includes rm -rf tempdir/, which deletes a folder and everything in it without asking, and kill -9 1234, which stops a process with no chance to clean up. The tool only shows and copies examples; it never runs a command.
- How many commands are on the list, and can I search or add to it?
- There are 83: 34 beginner, 30 intermediate and 19 advanced, and the list is fixed. The search box narrows it: every word you type must appear in the command, its description, its example or its topic, so disk leaves 6 rows (df, du, lsblk, mount, iostat and dd). The search works with the skill level, topic and platform filters, and the line above the table says how many commands match.
- How do I extract a tar.gz file?
- tar -xzf archive.tar.gz unpacks it into the current folder: x extracts, z reads gzip and f names the file. The sheet’s Archiving row shows the reverse, tar -czf archive.tar.gz dir/, which packs the folder dir into archive.tar.gz. Add -C target/ to unpack somewhere else. For a .zip file, the unzip row gives unzip archive.zip -d target/.
Related Tools
View all toolsGit Command Builder
Pick a git action such as merge, reset, stash or push, fill in the fields and copy the command, quoted for the shell, with warnings for risky flags.
Subnet Mask Cheat Sheet
Subnet mask table for every IPv4 prefix from /0 to /32: dotted mask, wildcard, total and usable hosts, with /31 counted as 2 (RFC 3021) and /32 as 1.
Chmod Calculator
Type a chmod mode such as 755 or 4755 to see rwxr-xr-x, or paste rwxr-xr-x or tick read, write and execute for owner, group and public to get the octal number.
Cron Job Generator
Type the five cron fields or start from a preset: each box is checked as you type, then read back in plain English with the next 5 run times.
AWS Data Transfer Cost Estimator
AWS data transfer out (egress) cost per month from GB to the internet, other Regions and the same Region, with the 100 GB free tier and volume tiers.
JS Object to JSON Converter
Paste a JavaScript object or array literal and get JSON. Unquoted keys, single quotes and trailing commas are accepted, and no code is run.