Linux & Bash Quick Reference

Linux Commands Cheat Sheet

Searchable quick reference for essential Linux commands. Find processes by port, configure file permissions (chmod), search logs with grep, and inspect system resources with one-click copy.

Make script executable (755)
permissions

Grants owner read, write, and execute permissions (rwx); group and others can read and execute (r-x).

Standard file permissions (644)
permissions

Grants owner read and write (rw-); group and others have read-only access (r--). Common for web and config files.

chmod 644 config.json
Strict private SSH key permissions (600)
permissions

Grants read and write access strictly to the current owner. Required by SSH clients to prevent key exposure.

chmod 600 ~/.ssh/id_rsa
Strict directory permissions (700)
permissions

Restricts all access to the directory exclusively to the owner. Required for ~/.ssh folders.

chmod 700 ~/.ssh
Change user and group ownership recursively
permissions

Recursively sets both owner and group to 'www-data' across all files and child directories.

chown -R www-data:www-data /var/www/html
Display file octal permission mode
permissions

Prints octal permission numbers (e.g. 755, 644) alongside each filename in the current directory.

stat -c '%a %n' *
Search recursively for text inside files
files

Recursively (-r) searches directory './src' for whole-word (-w) pattern with line numbers (-n).

grep -rnw './src' -e 'API_SECRET'
Find files modified in the last 24 hours
files

Locates all regular files in current directory and subdirectories modified within the last 1 day.

find . -type f -mtime -1
Find files by extension and delete them
files

Searches for all files ending with .log and immediately removes them.

find . -name '*.log' -type f -delete
Compress directory into tar.gz archive
files

Creates a gzip-compressed tarball (-c create, -z gzip, -v verbose, -f filename).

tar -czvf archive.tar.gz /path/to/folder
Extract tar.gz archive into folder
files

Extracts gzip archive contents into the specified destination folder (-C).

tar -xzvf archive.tar.gz -C ./target_folder
Live follow server log file
files

Streams live incoming log lines in real-time as they are written to disk.

tail -f /var/log/nginx/access.log
Truncate log file to zero bytes without deleting
files

Empties the file instantly without unlinking or restarting the running process holding the file handle.

: > /var/log/application.log
Find process listening on a specific port
system

Displays the PID, process name, and user currently binding TCP port 3000.

lsof -i :3000
Check disk usage by top directories
system

Measures human-readable directory sizes at root and sorts them in ascending order.

du -sh /* 2>/dev/null | sort -h
Check free RAM and swap memory
system

Displays total, used, free, shared, and available memory in human-readable units (GiB, MiB).

free -h
Check available disk space across partitions
system

Shows file system disk capacity, percent used, and available space on all mounted drives.

df -h
Display kernel version and architecture
system

Prints operating system kernel name, release version, and machine hardware architecture (e.g. x86_64, aarch64).

uname -srm
Find process PID by name
processes

Lists the process ID (PID) and full command line for all running processes matching 'node'.

pgrep -fl node
Gracefully stop then force kill process
processes

Sends SIGTERM (15) to allow graceful shutdown, falling back to SIGKILL (9) if unresponsive.

kill -15 <PID> || kill -9 <PID>
Check systemd service status
processes

Inspects service execution state, active uptime, memory consumption, and recent log snippets.

systemctl status nginx.service
Follow systemd service logs live
processes

Streams live stdout/stderr logs from a systemd unit starting with the last 100 lines.

journalctl -u my-app.service -f -n 100
Restart and enable service on system boot
processes

Enables service auto-start on server reboot and starts the service immediately.

sudo systemctl enable --now redis-server
Inspect HTTP response headers with timing
network

Performs HEAD HTTP request printing TLS handshake, HTTP status codes, and server response headers.

curl -Iv https://api.example.com/health
List all listening TCP and UDP sockets
network

Modern replacement for netstat. Displays all listening ports with associated PIDs and protocol names.

ss -tulpn
Quick DNS record lookup
network

Queries DNS server and returns only resolved IPv4 address without diagnostic headers.

dig +short A api.example.com
Test TCP port reachability on remote host
network

Uses Netcat to test if PostgreSQL port 5432 is open and accepting socket connections.

nc -zv 192.168.1.50 5432
Generate cryptographically secure random password
shell

Emits a 24-character random high-entropy token using cryptographic pseudorandom bytes.

openssl rand -base64 24
Run command in background unaffected by logout
shell

Executes script disconnected from terminal SIGHUP signals, redirecting all output to file.

nohup ./worker.sh > worker.log 2>&1 &

Chmod Permissions Calculator

Calculate octal numbers (755, 644) and symbolic notation visually.

Open Chmod Tool

cURL to Code Converter

Convert terminal cURL requests into JavaScript fetch, Axios, Python, and Go.

Open cURL Converter

Token & Secret Generator

Generate high-entropy random tokens, API keys, and NanoIDs client-side.

Open Token Generator

Frequently Asked Questions

How do I check which process is using a specific port in Linux?

Run 'lsof -i :<port>' or 'ss -tulpn | grep :<port>'. The output will display the Process ID (PID) and process name. To stop it, run 'kill -9 <PID>'.

What is the difference between chmod 755 and chmod 644?

Chmod 755 (rwxr-xr-x) grants the owner full read, write, and execute permissions, while group members and others can only read and execute. It is standard for directories and executable scripts. Chmod 644 (rw-r--r--) grants the owner read and write access, with read-only access for others, which is standard for static web files and documents.

How do I search for a specific string inside all files recursively?

Run 'grep -rnw "./path" -e "search_string"'. The '-r' flag enables recursive traversal, '-n' outputs matching line numbers, and '-w' matches whole words.

How can I safely run a command in the background after logging out of SSH?

Use 'nohup <command> > output.log 2>&1 &' or run it inside a terminal multiplexer like 'tmux' or 'screen'. 'nohup' intercepts SIGHUP signals sent when closing your SSH session.