Skip to content

Cheatsheets & Reference

Linux / Bash One-Liners

Common shell one-liners for find, grep, sed, awk and more.

native Client-side

Finding Files & Searching Text

6
find . -type f -name "*.log"

Find all .log files in the current directory and subdirectories.

find . -type f -mtime -7

Find files modified within the last 7 days.

find . -type f -size +100M

Find files larger than 100 MB.

grep -rnw "." -e "pattern"

Search recursively for "pattern" in text files, showing line numbers.

grep -v "^#" file.txt | grep -v "^$"

Read file excluding comment lines (starting with #) and blank lines.

find . -name "*.txt" -exec grep -H "search_term" {} +

Run grep on all matching files found by find.

Text Processing (sed, awk, cut)

6
sed -i "s/old/new/g" file.txt

Replace all occurrences of "old" with "new" in file.txt in-place.

awk '{print $1, $3}' file.txt

Print the 1st and 3rd columns of a whitespace-delimited file.

awk -F"," '{print $2}' file.csv

Print the 2nd column of a CSV file.

sort file.txt | uniq -c | sort -nr

Count unique lines in a file and output sorted by frequency.

cut -d: -f1 /etc/passwd

Extract system usernames from /etc/passwd.

tr '[:lower:]' '[:upper:]' < file.txt

Convert text in a file from lowercase to uppercase.

File & Disk Management

6
df -h

Display disk space usage in human-readable format.

du -sh * | sort -hr

Show size of files and folders in current directory, sorted largest first.

tar -czvf archive.tar.gz /path/to/folder

Compress a folder into a gzip tarball.

tar -xzvf archive.tar.gz

Extract a gzip tarball in the current directory.

ls -la --sort=size

List all files with details, sorted by size.

rsync -avzP source/ destination/

Sync files between directories with progress and compression.

Permissions & Ownership

4
chmod -R 755 /path/to/directory

Set read/write/execute for owner, read/execute for others recursively.

chmod -R 644 /path/to/files

Set read/write for owner, read-only for others recursively.

chown -R user:group /path/to/directory

Change owner and group recursively.

chmod +x script.sh

Make a script file executable.

Process & System Monitoring

7
ps aux | grep process_name

Find running process information by name.

kill -9 <PID>

Forcefully terminate a process by Process ID.

pkill -f process_name

Kill all processes matching a name pattern.

lsof -i :8080

Find which process is using port 8080.

free -h

Display total, used, and free RAM/swap space.

journalctl -u service_name -f

Stream live systemd logs for a specific service.

uptime

Show system uptime and current load averages.

Networking & Transfer

6
curl -I https://example.com

Fetch HTTP response headers for a URL.

curl -X POST -H "Content-Type: application/json" -d '{"key":"val"}' URL

Send a JSON POST request with curl.

wget -c https://example.com/file.zip

Download a file with resume support.

netstat -tulnp

List all listening TCP/UDP ports and associated processes.

dig +short example.com

Look up DNS IP address for a domain.

ssh-copy-id user@hostname

Copy public SSH key to a remote host for passwordless login.

Essential Linux & Bash One-Liners Cheatsheet

Working on the Linux command line efficiently relies on knowing the right one-line commands for file searching, text processing, process management, networking, and system diagnostics. This Linux one-liners cheatsheet organizes essential terminal snippets for grep, find, sed, awk, chmod, tar, and lsof. Each entry features a concise description so you can copy-paste verified terminal commands into your terminal session immediately. Search through categories or use the instant filter to find specific commands for shell scripting and system administration.

Frequently Asked Questions

How do I find which process is listening on a specific port?

Use lsof -i :PORT (e.g. lsof -i :8080) or netstat -tulnp | grep PORT. You can also use ss -tulpn on modern Linux distributions.

What is the difference between find and grep?

find searches for files and directories based on attributes like name, size, type, or modification date. grep searches for text patterns inside files. You often combine them, such as find . -name "*.log" -exec grep "error" +.

How do I recursively change file permissions in Linux?

Use chmod -R 755 /path for directories and chmod -R 644 /path for files. To apply permissions only to files or only to directories separately, use find . -type d -exec chmod 755 + or find . -type f -exec chmod 644 +.