Click any command to expand the explanation and examples.
π Navigation
cd β Change directory nav
cd /var/log # absolute path cd src/components # relative path cd .. # parent directory cd ~ # home directory cd - # previous directory
ls β List files nav
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
pwd # /home/user/projects/my-app
π File Operations
cp β Copy files files
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
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
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
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
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
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
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
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
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
ps aux # all processes ps aux | grep node # filter by name ps -ef --forest # tree view
top / htop β Monitor processes process
top # built-in monitor htop # better UI (install separately) # Press q to quit, k to kill a process
kill β Stop processes process
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
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
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
# SSH ssh user@hostname ssh -p 2222 user@hostname # custom port ssh -i ~/.ssh/key.pem user@hostname # with keySCP (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 .tar.gz tar -czf archive.tar.gz folder/Flags: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/
c=create, x=extract, z=gzip, f=file, t=list, v=verbose
zip / unzip compress
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
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
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
# Pipe output to another command cat log.txt | grep "error" | wc -lRedirect 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
# Delete all .tmp files find . -name "*.tmp" | xargs rmRun command for each line
cat urls.txt | xargs -I {} curl {}
Parallel execution
find . -name β*.jpgβ | xargs -P 4 -I {} convert {} {}.png
Quick Reference Table
| Task | Command |
|---|---|
| Go home | cd ~ |
| List all files | ls -la |
| Copy directory | cp -r src/ dest/ |
| Delete directory | rm -r dir/ |
| Create nested dirs | mkdir -p a/b/c |
| Follow log | tail -f log.txt |
| Make executable | chmod +x script.sh |
| Find files | find . -name "*.js" |
| Search in files | grep -r "text" dir/ |
| Kill process | kill -9 PID |
| Download file | curl -O url |
| SSH connect | ssh user@host |
| Create tar.gz | tar -czf out.tar.gz dir/ |
| Extract tar.gz | tar -xzf file.tar.gz |
| Pipe + count | cmd | wc -l |
| Redirect to file | cmd > file.txt |