env.dev

Linux Commands Cheat Sheet — Quick Reference

Linux commands quick reference: file management, process control, networking, permissions, systemd, and disk usage.

By env.dev Updated

A quick reference for essential Linux commands. Covers file management, process control, networking, permissions, systemd, and disk usage. Uses the modern iproute2 tooling (ip, ss) — ifconfig and netstat come from net-tools, long deprecated in favor of iproute2 and absent from minimal images.

File Management

CommandDescription
ls -laList all files with details
cp -r src/ dest/Copy directory recursively
mv old newMove or rename file/directory
rm -rf dir/Remove directory and contents
find . -name "*.log"Find files by name pattern
find . -mtime -7Find files modified in last 7 days
mkdir -p a/b/cCreate nested directories
ln -s target linkCreate symbolic link
tar -czf archive.tar.gz dir/Create gzipped tar archive
tar -xzf archive.tar.gzExtract gzipped tar archive

Process Control

CommandDescription
ps auxList all running processes
topInteractive process viewer
htopEnhanced interactive process viewer
kill <pid>Send SIGTERM to process — always try this first
kill -9 <pid>Force kill (SIGKILL) — skips cleanup handlers, last resort
killall <name>Kill all processes by name
bg / fgResume job in background / foreground
nohup cmd &Run command immune to hangups
jobsList background jobs

Networking

CommandDescription
curl -O <url>Download file from URL
curl -X POST -d @data.json <url>Send POST request with data
wget <url>Download file (with resume support)
ss -tulnpShow listening ports with process info
ip addrShow network interfaces and IPs
ping -c 4 hostSend 4 ICMP echo requests
dig example.comDNS lookup
traceroute hostTrace packet route to host
netstat -tulnpShow listening ports (legacy)

Permissions

CommandDescription
chmod 755 filerwxr-xr-x — owner full, others read/execute
chmod 644 filerw-r--r-- — owner read/write, others read
chmod +x script.shAdd execute permission
chmod -R 750 dir/Set permissions recursively
chown user:group fileChange file owner and group
chown -R user dir/Change ownership recursively
umask 022Set default permission mask
stat fileShow file permissions and metadata

Systemd

CommandDescription
systemctl start <service>Start a service
systemctl stop <service>Stop a service
systemctl restart <service>Restart a service
systemctl status <service>Check service status
systemctl enable --now <service>Enable on boot and start immediately
systemctl disable <service>Disable service on boot
journalctl -u <service> -fFollow service logs
systemctl list-units --type=serviceList all loaded services

Disk Usage

CommandDescription
df -hShow disk space usage (human readable)
du -sh dir/Show directory size
du -h --max-depth=1Show size of immediate subdirectories
lsblkList block devices
mount /dev/sda1 /mntMount a filesystem
umount /mntUnmount a filesystem
fdisk -lList disk partitions
ncduInteractive disk usage analyzer

Text Processing

CommandDescription
grep -r "pattern" .Search recursively in files
grep -i "pattern" fileCase-insensitive search
sed -i "s/old/new/g" fileFind and replace in file
awk '{print $1}' filePrint first column
sort file | uniq -cCount unique lines
wc -l fileCount lines in file
head -n 20 fileShow first 20 lines
tail -f fileFollow file output in real time

Common gotchas

  • chmod -R 777 is never the fix — it makes every file world-writable and executable. Work out the minimal mode with the chmod calculator and see the file permissions guide for the permission model.
  • rm -rf $DIR/ with an unset variable expands to rm -rf /. Quote and guard: rm -rf "${DIR:?}/" aborts if DIR is empty.
  • systemctl enable alone does not start the service — it only wires the boot symlink. Use --now, and run daemon-reload after editing unit files or changes are ignored.
  • df -h can show free space while writes fail with "No space left on device" — you may be out of inodes. Check with df -i.
  • Deleting a log file a process still has open frees no space (the inode lives until the handle closes). Truncate in place instead: : > file.log, and find the holder with lsof +L1.

Related: the Bash scripting cheat sheet for the shell side, and the SSH cheat sheet for working on remote hosts.

Was this helpful?

Frequently Asked Questions

What is the difference between chmod and chown?

chmod changes file permissions (read/write/execute). chown changes file ownership (user and group). Both require appropriate privileges — typically root or the file owner.

How do I find files in Linux?

Use find for complex searches: find /path -name "*.txt" -mtime -7. Use locate for fast name lookups (uses a database). Use which or whereis to find executables.

How do I manage services with systemd?

systemctl start/stop/restart service — manage service state. systemctl enable/disable service — control auto-start at boot. journalctl -u service — view service logs.