Files & directories
| Command | Does |
|---|---|
mkdir -p a/b/c | Create nested directories, no error if they exist. |
touch file.txt | Create an empty file or update its timestamp. |
cp -r src dest | Copy a file or directory (recursively). |
mv old new | Move or rename. |
rm -rf dir | Delete recursively, forcefully. No undo — double-check the path. |
cat file | Print a file's contents. |
ln -s target link | Create a symbolic link. |
Watch out
There is no trash can.
rm -rf is permanent — run ls on the path first if you're unsure.Permissions
Unix permissions are three groups of read/write/execute — for the owner, the group, and everyone else.
chmod anatomy
chmod 755 script.sh
# ││└─ others: r-x (5)
# │└── group: r-x (5)
# └─── owner: rwx (7)| Command | Does |
|---|---|
chmod +x file | Make a file executable. |
chown user:group file | Change file owner and group. |
sudo command | Run a single command as an administrator. |
Search & text processing
| Command | Does |
|---|---|
grep -rn "text" . | Recursively search for text, printing line numbers. |
find . -name "*.tsx" | Find files matching a name pattern. |
rg "pattern" | ripgrep — a much faster grep alternative, respects .gitignore. |
sed 's/foo/bar/g' file | Find-and-replace text in a stream. |
awk '{print $1}' file | Print a specific column of whitespace-separated data. |
wc -l file | Count lines in a file. |
Commands chain together with pipes — the output of one becomes the input of the next.
cat access.log
read the file
grep "500"
keep matching lines
wc -l
count the result
Processes
| Command | Does |
|---|---|
ps aux | List all running processes. |
top / htop | Live view of CPU and memory usage per process. |
kill -9 pid | Force-terminate a process by its ID. |
lsof -i :3000 | Find which process is using port 3000. |
command & | Run a command in the background. |
jobs / fg / bg | List, foreground, or background jobs in the current shell. |
Networking
| Command | Does |
|---|---|
curl -I https://example.com | Fetch just the response headers. |
curl -X POST -d '{}' url | Send a POST request with a body. |
ping host | Check reachability and latency. |
ssh user@host | Open a secure remote shell. |
scp file user@host:path | Copy a file over SSH. |
dig domain.com | Query DNS records for a domain. |
Package managers
| Platform | Install | Update |
|---|---|---|
| macOS (Homebrew) | brew install pkg | brew upgrade |
| Debian / Ubuntu | sudo apt install pkg | sudo apt update && sudo apt upgrade |
| Fedora / RHEL | sudo dnf install pkg | sudo dnf upgrade |
| Arch | sudo pacman -S pkg | sudo pacman -Syu |
