← All Developer Cheatsheets

Linux & Bash Terminal Cheatsheet

Essential command reference for Linux system administrators, DevOps, and backend engineers. Instant syntax for file operations, chmod permissions, process management, and networking diagnostics.

🔍
📁

File & Directory Navigation

ls -lah

Lists all files (including hidden dotfiles) in long format with human-readable file sizes.

Pro Tip: The -h flag formats sizes in KB, MB, and GB.

pwd

Prints the absolute path of the current working directory.

Pro Tip: Useful when verifying script execution context.

find /var/log -name "*.log" -mtime -7

Finds all files ending in .log under /var/log modified within the last 7 days.

Pro Tip: Add -delete to remove matches automatically.

grep -rnw "/etc" -e "Listen 80"

Recursively searches directory /etc for lines matching the exact whole word "Listen 80".

Pro Tip: -r is recursive, -n shows line numbers, -w is word match.

mkdir -p /path/to/nested/dir

Creates directory tree, including all parent folders that do not yet exist.

Pro Tip: Does not throw an error if directory already exists.

rm -rf /path/to/target

Recursively and forcefully deletes target directory and all contained files without confirmation.

Pro Tip: Caution: Irreversible file destruction!

📄

File Viewing, Paging & Searching

tail -f -n 100 /var/log/nginx/access.log

Outputs the last 100 lines and actively follows file updates in real time.

Pro Tip: Indispensable for monitoring live production web traffic.

head -n 20 data.csv

Displays the first 20 lines of a file.

Pro Tip: Quick way to inspect CSV headers without loading full file.

less +G output.log

Opens file in a fast terminal pager starting directly at the end (+G).

Pro Tip: Press "/" to search forward, "q" to exit.

wc -l file.txt

Counts and prints the total number of lines in a text file.

Pro Tip: Combine with pipe: ps aux | wc -l.

🔐

Permissions, Access Modes & Ownership

chmod 755 script.sh

Grants Read/Write/Execute to Owner (7), and Read/Execute to Group (5) and Others (5).

Pro Tip: Standard permission mode for web executables.

chmod 600 ~/.ssh/id_rsa

Restricts file so only the file owner has Read/Write permissions (no access for anyone else).

Pro Tip: Required by SSH client for private key security.

chmod +x script.sh

Adds execute permission to a script file for the current user.

Pro Tip: Enables direct execution via ./script.sh.

chown -R www-data:www-data /var/www/html

Recursively assigns user and group ownership of web root to the www-data user.

Pro Tip: Standard setup for Apache / Nginx PHP web servers.

⚙️

Process Monitoring & Systemd Services

htop

Interactive, real-time visual system monitor displaying per-core CPU, RAM, and process trees.

Pro Tip: Install with: sudo apt install htop.

ps aux | grep node

Lists all active processes running on the system and filters lines containing "node".

Pro Tip: Displays PID, %CPU, %MEM, and launch arguments.

kill -9 <PID>

Sends unconditional SIGKILL signal to immediately terminate a stuck or frozen process.

Pro Tip: Prefer kill -15 (SIGTERM) first for graceful exit.

systemctl status nginx

Checks the runtime status, uptime, PID, and recent journal logs of the Nginx service.

Pro Tip: Also works with restart, stop, start, reload.

systemctl enable --now mysql

Enables MySQL service to boot on startup and immediately launches it now.

Pro Tip: The --now flag saves a separate "systemctl start" step.

journalctl -u nginx -f --no-tail

Follows real-time systemd journal logs specifically emitted by the nginx service unit.

Pro Tip: Press Ctrl+C to stop following logs.

💾

Disk, Memory & Hardware Inspection

df -h

Displays available and consumed disk space across all mounted filesystem partitions in human format.

Pro Tip: Check the root / partition percentage.

du -sh /var/www/* | sort -hr

Calculates folder sizes in /var/www and sorts them from largest to smallest.

Pro Tip: Identifies which directory is hoarding disk storage.

free -m

Displays available, used, shared, and cached physical RAM and Swap memory in megabytes.

Pro Tip: Focus on the "available" column.

uname -a

Prints complete Linux kernel version, machine architecture (x86_64/arm64), and hostname.

Pro Tip: Confirms OS kernel release.

🌐

Networking, Ports & File Transfer

ss -tulpn

Displays all active listening TCP and UDP sockets along with their bound port numbers and process IDs.

Pro Tip: Modern replacement for legacy netstat.

curl -I https://www.hifitoolkit.com

Sends an HTTP HEAD request and prints only the response headers (status code, server, cache).

Pro Tip: Quick way to test SSL and CDN headers.

tar -czvf backup.tar.gz /var/www/html

Compresses /var/www/html into a gzip-compressed tar archive named backup.tar.gz.

Pro Tip: -c is create, -z is gzip, -v is verbose, -f is filename.

tar -xzvf backup.tar.gz -C /opt

Extracts a compressed tar.gz archive into the target destination directory /opt.

Pro Tip: -x is extract, -C specifies destination path.

rsync -avzP /local/dir user@server:/remote/dir

Transfers and synchronizes files over SSH with archive permissions (-a), compression (-z), and progress (-P).

Pro Tip: Resumes broken transfers seamlessly.

Understanding the Linux Filesystem Hierarchy Standard (FHS)

Unlike Windows which organizes files across drive letters (e.g. C:\, D:\), Linux unifies all files, storage devices, and virtual hardware into a single root tree (/). Understanding standard top-level directories is critical for system administration:

  • /etc: Host-specific system-wide configuration files (e.g. Nginx conf, sshd_config, hosts).
  • /var: Variable data that changes during system operation (e.g. /var/log logs, /var/www web roots, /var/lib/mysql database data).
  • /opt: Optional add-on third-party application software packages.
  • /proc & /sys: Virtual pseudofilesystems generated dynamically by the Linux kernel presenting system hardware and running process states in RAM.

Octal File Permissions Breakdown Table

Linux file modes are grouped into three triads: Owner (User), Group, and Others (World). Each permission is calculated by adding its binary weight: Read (4), Write (2), and Execute (1).

Octal ModeSymbolicPermissions GrantedCommon Real-World Usage
755rwxr-xr-xOwner: Read/Write/Exec; Group/Others: Read/ExecExecutable scripts, public web server directories
644rw-r--r--Owner: Read/Write; Group/Others: Read onlyStandard static files (.html, .css, .js, .png)
600rw-------Owner: Read/Write; Group/Others: Zero accessSSH private keys, password credentials, .env files
700rwx------Owner: Read/Write/Exec; Group/Others: Zero accessPrivate personal directories (e.g. ~/.ssh/)

Frequently Asked Questions (FAQs)

What is the difference between chmod 755 and chmod 644?

In octal permission notation, 7 represents Read (4) + Write (2) + Execute (1), while 6 represents Read (4) + Write (2) = 6, and 5 represents Read (4) + Execute (1) = 5. Therefore, chmod 755 gives the owner full access (7) and others read+execute (5), making it standard for directories and executable scripts. chmod 644 gives the owner read+write (6) and others read-only (4), making it standard for static files like HTML, CSS, images, and config files.

Why should I use 'ss' instead of 'netstat' on modern Linux systems?

The legacy 'netstat' command queries /proc filesystem tables slowly and is deprecated in modern Linux distributions. 'ss' (Socket Statistics) communicates directly with the Linux kernel via Netlink sockets, returning socket states, listening ports, and established TCP connections orders of magnitude faster with lower CPU consumption.

What is the difference between SIGTERM (kill -15) and SIGKILL (kill -9)?

SIGTERM (15) is a polite termination request sent to the process, allowing it to close database connections, flush memory buffers to disk, and remove temporary PID files. SIGKILL (9) bypasses the process entirely; the Linux kernel immediately terminates the process task without giving it an opportunity to clean up.

What does the -p flag in mkdir do?

The -p (parents) flag tells mkdir to create any missing intermediate directories in the specified path without throwing an error if the folder already exists. For example, 'mkdir -p /a/b/c' creates folder a, folder b, and folder c in a single command.

Explore Related Tools

Hand-picked utilities and calculators related to this tool.

Related Tools