MeshWorld India LogoMeshWorld.
CheatsheetLinuxBashShellTerminalUbuntuCommand LineDeveloper Tools10 min read

Linux & Bash Cheat Sheet: Commands Every Dev Needs

Vishnu
By Vishnu
|Updated: Mar 11, 2026
Linux & Bash Cheat Sheet: Commands Every Dev Needs
TL;DR
  • Navigation: cd, ls, pwd, find, locate — know these by heart
  • File operations: cp -r, mv, rm -rf (careful), tar, rsync
  • Text processing: grep, awk, sed, cut, sort, uniq, wc
  • Permissions: chmod 755, chown user:group, sudo
  • Processes: ps aux, top, kill -9, & (background), nohup

Quick reference tables

CommandWhat it does
pwdPrint current directory
lsList files
ls -laList all files with details (including hidden)
ls -lhHuman-readable file sizes
cd /pathChange to absolute path
cd ~Go to home directory
cd -Go to previous directory
cd ..Go up one level
treeShow directory tree
tree -L 2Tree limited to 2 levels deep

File operations

CommandWhat it does
touch file.txtCreate an empty file
mkdir dirCreate a directory
mkdir -p a/b/cCreate nested directories
cp file destCopy file
cp -r dir destCopy directory recursively
mv file destMove or rename file
rm fileRemove a file
rm -r dirRemove directory recursively
rm -rf dirForce remove (no prompts — careful!)
ln -s target linkCreate a symbolic link

Reading files

CommandWhat it does
cat filePrint entire file
less fileScroll through file (q to quit)
head fileFirst 10 lines
head -n 20 fileFirst 20 lines
tail fileLast 10 lines
tail -n 20 fileLast 20 lines
tail -f fileFollow file in real time (logs)
wc -l fileCount lines
wc -w fileCount words

Searching — grep & find

CommandWhat it does
grep "pattern" fileSearch for pattern in file
grep -r "pattern" dirSearch recursively in directory
grep -i "pattern" fileCase-insensitive search
grep -n "pattern" fileShow line numbers
grep -v "pattern" fileInvert — lines that don’t match
grep -l "pattern" dir/*List files containing pattern
find . -name "*.js"Find files by name pattern
find . -type f -name "*.log"Find files only (not dirs)
find . -type d -name "node_modules"Find directories by name
find . -mtime -7Files modified in last 7 days
find . -size +10MFiles larger than 10MB

Permissions

CommandWhat it does
ls -lShow permissions in listing
chmod 755 fileSet permissions (rwxr-xr-x)
chmod +x fileMake file executable
chmod -R 755 dirSet permissions recursively
chown user fileChange file owner
chown user:group fileChange owner and group
chown -R user:group dirChange ownership recursively
sudo commandRun as superuser
su - userSwitch to another user

Permission numbers:

NumberPermissions
7rwx (read + write + execute)
6rw- (read + write)
5r-x (read + execute)
4r— (read only)
0--- (no permissions)

Processes

CommandWhat it does
ps auxList all running processes
ps aux | grep nodeFind a specific process
topLive process monitor
htopBetter live process monitor
kill PIDKill a process by ID
kill -9 PIDForce kill
killall nodeKill all processes named node
pkill -f "pattern"Kill processes matching pattern
bgResume stopped job in background
fgBring background job to foreground
jobsList background jobs
nohup cmd &Run command immune to hangup

Disk & memory

CommandWhat it does
df -hDisk space usage (human-readable)
du -sh dirSize of a directory
du -sh *Size of each item in current dir
free -hRAM usage
lsblkList block devices (disks)

Networking

CommandWhat it does
ip aShow IP addresses
ip rShow routing table
ping hostPing a host
curl urlFetch a URL
curl -I urlShow HTTP headers only
curl -o file urlDownload to a file
wget urlDownload a file
ss -tulnpShow listening ports
netstat -tulnpShow listening ports (older)
ssh user@hostSSH into a remote machine
scp file user@host:/pathCopy file to remote
rsync -avz src/ dest/Sync directories

Archives & compression

CommandWhat it does
tar -czf archive.tar.gz dir/Create gzipped tar archive
tar -xzf archive.tar.gzExtract gzipped tar
tar -tzf archive.tar.gzList contents without extracting
zip -r archive.zip dir/Create zip archive
unzip archive.zipExtract zip
gzip fileCompress a file (replaces original)
gunzip file.gzDecompress

Pipes, redirects & shortcuts

SymbolWhat it does
cmd1 | cmd2Pipe output of cmd1 to cmd2
> fileRedirect stdout to file (overwrite)
>> fileRedirect stdout to file (append)
2> fileRedirect stderr to file
2>&1Redirect stderr to stdout
&> fileRedirect both stdout and stderr
/dev/nullDiscard output
< fileRead stdin from file
cmd &Run command in background

Shell keyboard shortcuts

ShortcutWhat it does
Ctrl+CKill current process
Ctrl+ZSuspend current process
Ctrl+DExit shell / EOF
Ctrl+LClear screen
Ctrl+AJump to start of line
Ctrl+EJump to end of line
Ctrl+UDelete from cursor to start of line
Ctrl+KDelete from cursor to end of line
Ctrl+WDelete word before cursor
Ctrl+RSearch command history
/ Navigate command history
!!Repeat last command
!$Last argument of previous command
!cmdRun most recent command starting with cmd

Variables & environment

CommandWhat it does
VAR=valueSet a local variable
export VAR=valueSet an environment variable
echo $VARPrint a variable
envShow all environment variables
unset VARRemove a variable
printenv PATHPrint a specific env variable
source ~/.bashrcReload shell config
which cmdShow path to a command
type cmdShow how a command is interpreted

Detailed sections

Pipes — the real power of the terminal

Pipes (|) connect commands so the output of one becomes the input of the next.

bash
# Find all .js files and count them
find . -name "*.js" | wc -l

# See the 10 largest files
du -sh * | sort -rh | head -10

# Search running processes for 'node' and kill them
ps aux | grep node | awk '{print $2}' | xargs kill

# See only unique lines in a file
cat file.txt | sort | uniq

# Count occurrences of each word
cat file.txt | tr ' ' '\n' | sort | uniq -c | sort -rn | head -20

Grep — search like a pro

bash
# Search recursively, show filename and line number
grep -rn "TODO" ./src

# Search for multiple patterns
grep -E "error|warning|critical" app.log

# Show context around matches (3 lines before and after)
grep -C 3 "error" app.log

# Count matches per file
grep -rc "TODO" ./src

# Exclude a directory
grep -r "pattern" . --exclude-dir=node_modules

Find — locate files quickly

bash
# Find and delete all .DS_Store files
find . -name ".DS_Store" -delete

# Find files modified in the last 24 hours
find . -mtime -1 -type f

# Find files larger than 100MB
find . -size +100M -type f

# Execute a command on each result
find . -name "*.log" -exec rm {} \;

# Find empty directories
find . -type d -empty

Cron — scheduled tasks

Edit the crontab:

bash
crontab -e

Format: minute hour day-of-month month day-of-week command

bash
# Every minute
* * * * * /path/to/script.sh

# Every day at midnight
0 0 * * * /path/to/script.sh

# Every Monday at 9am
0 9 * * 1 /path/to/script.sh

# Every 15 minutes
*/15 * * * * /path/to/script.sh

# First day of every month at noon
0 12 1 * * /path/to/script.sh

List cron jobs: crontab -l Remove all cron jobs: crontab -r

SSH essentials

bash
# Connect to a server
ssh [email protected]

# Connect on a non-standard port
ssh -p 2222 user@host

# Copy a file to a server
scp localfile.txt user@host:/remote/path/

# Copy a directory to a server
scp -r localdir/ user@host:/remote/path/

# Generate an SSH key pair
ssh-keygen -t ed25519 -C "[email protected]"

# Copy your public key to a server (enables passwordless login)
ssh-copy-id user@host

# SSH tunnel (forward remote port 5432 to localhost)
ssh -L 5432:localhost:5432 user@host

Writing shell scripts

bash
#!/bin/bash
set -e    # exit on any error
set -u    # error on undefined variables

# Variables
NAME="world"
echo "Hello, $NAME!"

# Conditionals
if [ -f "file.txt" ]; then
  echo "File exists"
else
  echo "File not found"
fi

# Loops
for file in *.js; do
  echo "Processing $file"
done

# Functions
greet() {
  echo "Hello, $1!"
}
greet "developer"

# Command substitution
DATE=$(date +%Y-%m-%d)
echo "Today is $DATE"

Make it executable: chmod +x script.sh Run it: ./script.sh

Related: Vim Cheat Sheet | tmux Cheat Sheet | SSH & GPG Cheat Sheet | cURL Cheat Sheet

Share_This Twitter / X
Vishnu
Written By

Vishnu

Founder & Principal Architect at MeshWorld. Senior engineer and instructor specializing in AI agent systems, scalable web architecture, and modern development workflows.

Enjoyed this article?

Support MeshWorld and help us create more technical content