AdSense Placeholder
Slot: header_reference_page
These are the commands that cover most day-to-day work in a Linux, macOS or WSL terminal. Replace the placeholders in <angle brackets> with your own values. Each command was run on a real system, except those that need a network, root rights or extra software.
Commands by task
Move around
| Command |
What it does |
pwd |
Print the current directory |
ls -la |
List all files with details, hidden ones included |
cd <dir> |
Change directory (cd .. up one level, cd - back, cd home) |
tree -L 2 |
Show a folder as a tree, two levels deep (often needs installing) |
Files and folders
| Command |
What it does |
mkdir -p a/b/c |
Create a folder and any missing parents |
cp -r src dest |
Copy a file or, with -r, a whole folder |
mv old new |
Move or rename |
rm -r folder |
Delete a folder and its contents; there is no recycle bin |
touch file |
Create an empty file or update its timestamp |
ln -s target link |
Create a symbolic link |
Read files
| Command |
What it does |
cat file |
Print a whole file |
less file |
Page through a file (q quits, /text searches) |
head -n 20 file |
First 20 lines |
tail -n 20 file |
Last 20 lines (tail -f follows a growing log) |
wc -l file |
Count lines (-w words, -c bytes) |
Search
| Command |
What it does |
grep -rn "text" . |
Search files under here for text, with line numbers |
grep -i "text" file |
Case-insensitive search (-v inverts, -c counts) |
find . -name "*.log" |
Find files by name |
find . -type f -mtime -1 |
Files changed in the last day |
Process text
| Command |
What it does |
sort file | uniq -c |
Sort lines and count duplicates |
cut -d, -f1 file.csv |
Take the first comma-separated column |
sed 's/old/new/g' file |
Replace text on every line |
awk '{print $1}' file |
Print the first whitespace-separated field |
xargs |
Turn input lines into command arguments (find ... | xargs rm) |
Permissions and users
| Command |
What it does |
chmod 644 file |
Change permissions (see the chmod cheat sheet) |
chown user:group file |
Change owner and group |
sudo <command> |
Run one command as the administrator |
whoami |
Show your username |
Processes
| Command |
What it does |
ps aux |
List all running processes |
top |
Live view of CPU and memory use (q quits) |
kill <pid> |
Ask a process to stop (kill -9 forces it as a last resort) |
command & |
Run a command in the background (jobs lists, fg brings it back) |
Disk and system
| Command |
What it does |
df -h |
Free space on each disk, human-readable |
du -sh folder |
Total size of a folder |
free -h |
Memory use |
uname -a |
Kernel and system information |
Network
| Command |
What it does |
ping -c 4 host |
Check a host answers (four tries) |
curl -I https://example.com |
Fetch only the response headers |
ss -tuln |
List listening TCP and UDP ports |
ssh user@host |
Open a secure shell on another machine |
scp file user@host:/path |
Copy a file over SSH |
Archives
| Command |
What it does |
tar -czf backup.tar.gz folder |
Create a gzip-compressed archive |
tar -xzf backup.tar.gz |
Extract it |
zip -r a.zip folder |
Create a ZIP file (often needs installing) |
Pipes and redirection
command1 | command2 sends the output of the first command into the second.
command > file writes output to a file, replacing it; >> appends instead.
command 2> errors.txt redirects error messages; command > all.txt 2>&1 captures both.
command1 && command2 runs the second only if the first succeeded; || only if it failed.
Keyboard shortcuts in the shell
| Keys |
Effect |
| Tab |
Complete a file or command name |
| ↑ / ↓ |
Walk through command history |
| Ctrl+R |
Search history |
| Ctrl+C |
Stop the running command |
| Ctrl+D |
End input or log out |
| Ctrl+L |
Clear the screen |
| Ctrl+A / Ctrl+E |
Jump to the start / end of the line |
Be careful with
rm has no undo. rm -rf on the wrong path can erase a whole system; check the path with ls first, and never run rm -rf / or rm -rf ~.
sudo runs with full rights. Read a command before you put sudo in front of it.
chmod -R 777 makes everything writable by everyone; see chmod and File Permissions Cheat Sheet.
- Pasting commands from the internet. Understand what a command does, especially anything that pipes
curl into a shell.
For version control commands, see Git Cheat Sheet. For what each permission string means, see chmod and File Permissions Cheat Sheet.