πŸ“‹ Cheat Sheets

Linux Terminal Cheat Sheet β€” Essential Commands for Developers


Click any command to expand the explanation and examples.

πŸ“‚ Navigation

cd β€” Change directory nav
Move between directories.
cd /var/log          # absolute path
cd src/components    # relative path
cd ..                # parent directory
cd ~                 # home directory
cd -                 # previous directory
ls β€” List files nav
List directory contents.
ls                   # basic listing
ls -la               # long format + hidden files
ls -lh               # human-readable sizes
ls -lt               # sort by modification time
ls -lS               # sort by size
ls *.js              # glob pattern
pwd β€” Print working directory nav
Show the full path of the current directory.
pwd
# /home/user/projects/my-app

πŸ“„ File Operations

cp β€” Copy files files
Copy files and directories.
cp file.txt backup.txt          # copy file
cp -r src/ src-backup/          # copy directory recursively
cp -i file.txt dest/            # prompt before overwrite
cp file1.txt file2.txt dest/    # copy multiple files
mv β€” Move / rename files
Move or rename files and directories.
mv old.txt new.txt              # rename
mv file.txt ~/Documents/        # move to directory
mv -i src.txt dest.txt          # prompt before overwrite
rm β€” Remove files files
Delete files and directories. No undo β€” be careful.
rm file.txt                     # delete file
rm -r directory/                # delete directory recursively
rm -i file.txt                  # prompt before delete
rm -f file.txt                  # force (no prompt)
mkdir / touch β€” Create dirs & files files
Create directories and empty files.
mkdir new-folder                # create directory
mkdir -p a/b/c                  # create nested directories
touch file.txt                  # create empty file (or update timestamp)
cat / head / tail β€” View files files
Display file contents.
cat file.txt                    # print entire file
head -n 20 file.txt             # first 20 lines
tail -n 20 file.txt             # last 20 lines
tail -f /var/log/app.log        # follow log in real time
less file.txt                   # scrollable viewer (q to quit)

πŸ” Permissions

chmod β€” Change permissions perms
Modify file permissions.
chmod 755 script.sh             # rwxr-xr-x
chmod 644 file.txt              # rw-r--r--
chmod +x script.sh              # add execute
chmod -w file.txt               # remove write
chmod u+x,g+r file.txt         # user +exec, group +read
# Permission numbers:
# r=4  w=2  x=1
# 7 = rwx, 6 = rw-, 5 = r-x, 4 = r--
# First digit: owner, second: group, third: others
chown β€” Change ownership perms
Change file owner and group.
chown user file.txt             # change owner
chown user:group file.txt       # change owner and group
chown -R user:group directory/  # recursive

πŸ” Search

find β€” Find files search
Search for files by name, type, size, date, etc.
find . -name "*.js"                    # by name
find . -type f -name "*.log"           # files only
find . -type d -name "node_modules"    # directories only
find . -size +10M                      # larger than 10MB
find . -mtime -7                       # modified in last 7 days
find . -name "*.tmp" -delete           # find and delete
grep β€” Search file contents search
Search for text patterns in files.
grep "error" log.txt                   # search in file
grep -r "TODO" src/                    # recursive search
grep -i "hello" file.txt               # case-insensitive
grep -n "function" app.js              # show line numbers
grep -l "import" src/*.ts              # list matching files only
grep -c "error" log.txt               # count matches
grep -E "error|warning" log.txt        # regex (extended)

βš™οΈ Processes

ps β€” List processes process
View running processes.
ps aux                          # all processes
ps aux | grep node              # filter by name
ps -ef --forest                 # tree view
top / htop β€” Monitor processes process
Real-time process monitoring.
top                             # built-in monitor
htop                            # better UI (install separately)
# Press q to quit, k to kill a process
kill β€” Stop processes process
Send signals to processes.
kill 1234                       # graceful stop (SIGTERM)
kill -9 1234                    # force kill (SIGKILL)
killall node                    # kill all by name
pkill -f "node server.js"      # kill by pattern

🌐 Networking

curl β€” HTTP requests network
Make HTTP requests from the terminal.
curl https://api.example.com              # GET
curl -o file.zip https://example.com/f.zip # download
curl -X POST -H "Content-Type: application/json" \
  -d '{"name":"Alice"}' https://api.example.com/users
curl -I https://example.com               # headers only
curl -s https://api.example.com | jq .    # pipe to jq
wget β€” Download files network
Download files from the web.
wget https://example.com/file.zip
wget -O output.zip https://example.com/file.zip
wget -q https://example.com/file.zip     # quiet mode
ssh / scp β€” Remote access & copy network
Connect to remote servers and copy files.
# SSH
ssh user@hostname
ssh -p 2222 user@hostname                # custom port
ssh -i ~/.ssh/key.pem user@hostname      # with key

SCP (secure copy)

scp file.txt user@host:/path/ # upload scp user@host:/path/file.txt ./ # download scp -r folder/ user@host:/path/ # directory

πŸ“¦ Compression

tar β€” Archive files compress
Create and extract tar archives.
# Create .tar.gz
tar -czf archive.tar.gz folder/

Extract .tar.gz

tar -xzf archive.tar.gz

List contents

tar -tzf archive.tar.gz

Extract to specific directory

tar -xzf archive.tar.gz -C /dest/

Flags: c=create, x=extract, z=gzip, f=file, t=list, v=verbose

zip / unzip compress
Create and extract zip archives.
zip archive.zip file1.txt file2.txt
zip -r archive.zip folder/
unzip archive.zip
unzip archive.zip -d /dest/
unzip -l archive.zip              # list contents

πŸ“₯ Package Managers

apt (Debian/Ubuntu) packages
Manage packages on Debian-based systems.
sudo apt update                  # update package list
sudo apt upgrade                 # upgrade all packages
sudo apt install nginx           # install package
sudo apt remove nginx            # remove package
apt search keyword               # search packages
apt list --installed             # list installed
brew (macOS) packages
Homebrew package manager for macOS.
brew install node                # install
brew uninstall node              # remove
brew update                      # update Homebrew
brew upgrade                     # upgrade all packages
brew list                        # list installed
brew search keyword              # search

πŸ”€ Pipes & Redirection

| > >> < β€” Pipes & redirects pipes
Chain commands and redirect output.
# Pipe output to another command
cat log.txt | grep "error" | wc -l

Redirect output to file (overwrite)

echo β€œhello” > file.txt

Append to file

echo β€œworld” >> file.txt

Redirect stderr

command 2> errors.log

Redirect both stdout and stderr

command > output.log 2>&1

Input from file

sort < unsorted.txt

xargs β€” Build commands from input pipes
Convert input into arguments for another command.
# Delete all .tmp files
find . -name "*.tmp" | xargs rm

Run command for each line

cat urls.txt | xargs -I {} curl {}

Parallel execution

find . -name β€œ*.jpg” | xargs -P 4 -I {} convert {} {}.png


Quick Reference Table

TaskCommand
Go homecd ~
List all filesls -la
Copy directorycp -r src/ dest/
Delete directoryrm -r dir/
Create nested dirsmkdir -p a/b/c
Follow logtail -f log.txt
Make executablechmod +x script.sh
Find filesfind . -name "*.js"
Search in filesgrep -r "text" dir/
Kill processkill -9 PID
Download filecurl -O url
SSH connectssh user@host
Create tar.gztar -czf out.tar.gz dir/
Extract tar.gztar -xzf file.tar.gz
Pipe + countcmd | wc -l
Redirect to filecmd > file.txt