2. File & Directory Operations
Creating, copying, moving, and deleting — the bread and butter of file management.
touch file.txt
Create an empty file, or update the modified timestamp if it already exists.
mkdir -p a/b/c
Create a directory, including any missing parent directories in the path.
cp -r src/ dest/
Copy files and directories recursively. Add -v for verbose output.
mv old.txt new.txt
Move or rename files and directories.
rm -rf dir/
Remove files or directories, forcefully and recursively. There is no undo — use with care.
rmdir empty-dir
Remove a directory, but only if it's empty — a safer alternative to rm -r.
ln -s /path/target link
Create a symbolic link — a pointer to another file or directory.
stat file.txt
Show detailed metadata: size, permissions, timestamps, inode, and more.
file mystery-file
Detect a file's type by inspecting its contents, not just its extension.
3. Viewing & Editing Files
Read and edit files without leaving the terminal — essential for remote servers.
cat file.txt
Print an entire file's contents to the terminal.
less file.txt
Page through a large file without loading it all at once. /pattern searches, q quits.
head -n 20 file.txt
Show the first N lines of a file (default is 10).
tail -f app.log
Follow a file in real time as new lines are appended — perfect for watching logs.
nano file.txt
A beginner-friendly terminal text editor with on-screen shortcut hints.
vim file.txt
A powerful modal editor. Press i to insert, Esc then :wq to save & quit.
echo "hi" | tee out.txt
Write output to a file and print it to the terminal at the same time.
4. Text Processing & Search
The tools that make Linux a superpower for parsing logs and data on the fly.
grep -rn "TODO" .
Recursively search for a pattern, printing matching line numbers.
sed 's/foo/bar/g' file.txt
Stream-edit text: find & replace every occurrence of "foo" with "bar".
awk '{print $1}' file.txt
Pattern-scan and process structured text, column by column.
cut -d',' -f2 data.csv
Extract a specific column from delimited data, like a CSV file.
sort file.txt | uniq -c
Sort lines, then count how many times each unique line appears.
wc -l file.txt
Count lines in a file. Drop -l for word and byte counts too.
diff file1.txt file2.txt
Compare two files line by line and show what's different.
cat urls.txt | xargs -n1 curl -O
Build and execute a command for each line of input — great for batch operations.
5. Permissions & Ownership
Who can read, write, and execute what — and how to run commands as another user.
chmod 755 script.sh
Set exact read/write/execute permissions numerically (owner: rwx, group/others: r-x).
chmod +x deploy.sh
Make a script executable — the most common permissions fix you'll ever run.
chown user:group file.txt
Change the owning user and group of a file or directory.
umask 022
View or set the default permission mask applied to newly created files.
sudo systemctl restart nginx
Run a single command with elevated (typically root) privileges.
su - deploy
Switch to another user's shell entirely, loading their environment.
6. Process Management
Inspect, control, and kill running programs.
ps aux
List every running process on the system with CPU/memory usage.
htop
An interactive, colorized process viewer — a friendlier upgrade over top.
kill -9 1234
Force-terminate a process by its PID. Try kill (no -9) first for a graceful shutdown.
killall node
Kill all processes matching a name instead of hunting down PIDs one by one.
jobs
List background and suspended jobs started from the current shell.
fg %1
Bring a background job back to the foreground. Use bg to resume one in the background.
nice -n 10 ./build.sh
Launch a process with a lower CPU scheduling priority so it doesn't hog the machine.
nohup ./server &
Keep a process running in the background even after you close the terminal session.
7. System Monitoring & Info
Understand what your machine or server is actually doing right now.
uname -a
Print kernel name, version, and architecture — useful for compatibility checks.
uptime
Show how long the system has been running plus the load average.
df -h
Show disk space usage across mounted filesystems, in human-readable units.
du -sh ./node_modules
Show the total size of a directory — great for tracking down disk hogs.
free -h
Show total, used, and free RAM and swap memory.
vmstat 1
Stream memory, CPU, and I/O stats every second — good for spotting bottlenecks live.
lsblk
List all block devices (disks, partitions) in a readable tree.
dmesg | tail -n 50
Show recent kernel messages — the first place to look after a crash or hardware issue.
8. Networking
Diagnose connections, transfer files, and manage remote servers over SSH.
ping -c 4 devmocks.com
Test connectivity and latency to a host with 4 packets.
curl -I https://example.com
Fetch just the response headers from a URL — perfect for quick API/status checks.
wget https://example.com/file.zip
Download a file directly from the command line.
ss -tulpn
Show listening ports and the processes using them — the modern replacement for netstat.
ip a
Show all network interfaces and their assigned IP addresses.
traceroute devmocks.com
Show every network hop a packet takes to reach its destination.
dig devmocks.com
Query DNS records for a domain — A, MX, TXT, and more.
ssh user@server.com
Open a secure remote shell on another machine.
scp file.txt user@host:/path
Securely copy a file to (or from) a remote host over SSH.
rsync -avz src/ user@host:dest/
Efficiently sync files, only transferring the parts that actually changed.
9. Package Management
Installing and updating software differs by distro — here's the cheat sheet for each.
sudo apt update && sudo apt upgrade
Refresh package lists and upgrade installed packages (Debian/Ubuntu).
sudo apt install nginx
Install a package on Debian/Ubuntu-based systems.
sudo dnf install nginx
Install a package on Fedora and modern RHEL-based systems.
sudo yum install nginx
Install a package on older RHEL/CentOS systems.
sudo pacman -S nginx
Install a package on Arch Linux and its derivatives (Manjaro, EndeavourOS).
dpkg -l | grep nginx
List installed .deb packages and check whether a specific one is present.
sudo snap install code --classic
Install a distro-agnostic Snap package, sandboxed and auto-updating.
10. Archiving & Compression
Package up files for deployment, backups, or sharing.
tar -czvf archive.tar.gz dir/
Create a gzip-compressed tarball of a directory (c=create, z=gzip, v=verbose, f=file).
tar -xzvf archive.tar.gz
Extract a gzip-compressed tarball into the current directory.
zip -r archive.zip dir/
Create a .zip archive from a directory, recursively.
unzip archive.zip
Extract the contents of a .zip archive.
gzip file.txt / gunzip file.txt.gz
Compress or decompress a single file with gzip.
11. User & Group Management
Managing who has access to a system, particularly on shared servers.
whoami
Print the current logged-in username.
id
Show your UID, GID, and every group you belong to.
sudo adduser newdev
Create a new user account, prompting for a password and details.
sudo usermod -aG docker newdev
Add a user to an existing group without removing them from others.
passwd
Change the password for the current user (or another, if run as root).
groups
List the groups the current user belongs to.
12. Disk & Storage
Mounting drives, checking partitions, and formatting filesystems.
sudo mount /dev/sdb1 /mnt
Attach a filesystem (like a USB drive) to a directory in the tree.
sudo umount /mnt
Safely detach a mounted filesystem before removing the drive.
sudo fdisk -l
List all disks and partitions on the system with their sizes and types.
sudo mkfs.ext4 /dev/sdb1
Format a partition with the ext4 filesystem. This erases all data on it.
lsblk -f
Show block devices along with their filesystem type and UUID.
13. Job Scheduling & Automation
Automate recurring tasks like backups, cleanups, and health checks.
crontab -e
Edit the current user's cron jobs — recurring commands run on a schedule.
0 3 * * * /home/user/backup.sh
A cron line: run backup.sh every day at 3:00 AM (minute hour day month weekday).
crontab -l
List all scheduled cron jobs for the current user.
echo "./task.sh" | at 22:00
Schedule a one-time job to run later, instead of a recurring cron entry.
14. System Services (systemd)
Start, stop, and inspect background services on modern Linux distros.
systemctl status nginx
Check whether a service is running, and view its recent log output.
sudo systemctl restart nginx
Start, stop, or restart a service (swap the verb as needed).
sudo systemctl enable nginx
Make a service start automatically on every boot.
journalctl -u nginx -f
Follow the live logs for a specific systemd service.
15. Environment & Shell
Configure your shell environment and speed up repetitive commands.
export NODE_ENV=production
Set an environment variable available to the current shell and child processes.
echo $PATH
Print the value of an environment variable.
alias ll='ls -la'
Create a shortcut for a longer command. Add to ~/.bashrc to make it permanent.
which node
Locate the executable a command name resolves to on your $PATH.
env
List every environment variable currently set in the shell.
history | tail -20
Show your recent command history.
source ~/.bashrc
Reload your shell config file without opening a new terminal.
16. Keyboard Shortcuts & Shell Tricks
Small tricks that add up to a much faster terminal workflow.
Ctrl + C
Cancel / interrupt the currently running command.
Ctrl + Z
Suspend the current process, sending it to the background (resume with fg).
Ctrl + R
Reverse-search your command history — start typing to find a past command.
Ctrl + A / Ctrl + E
Jump the cursor to the start or end of the current line.
Ctrl + L
Clear the terminal screen (same as typing clear).
!!
Repeat the last command — handy for retrying with sudo !!.
!$
Reuse the last argument of the previous command.
Tab
Autocomplete file paths, commands, and flags. Double-tap to list all options.
17. Useful One-Liners
Combining commands with pipes is where Linux really shines. A few we reach for constantly.
find . -name "*.log" -mtime +7 -delete
Delete log files older than 7 days — a classic disk-cleanup cron job.
du -sh * | sort -rh | head -10
List the 10 largest files or folders in the current directory.
ps aux --sort=-%mem | head -10
Show the top 10 processes by memory usage — the fastest way to spot a memory leak.
grep -rn "TODO" --include=*.js .
Find every TODO comment across a JavaScript codebase.
history | awk '{print $2}' | sort | uniq -c | sort -rn | head -10
Rank your 10 most-used shell commands of all time.
Bookmark This Guide
Whether you're setting up a server, debugging a deployment, or just leveling up your terminal skills — keep this page handy. And if you need a hand building or shipping your next project, we're here for that too.