One-liners
Run the previous command with sudo
$ sudo !!
Repeat the last command
$ !!
Fix typo in the previous command
$ ^wrong^correct^
Search command history interactively
$ Ctrl+R
Edit current command line in your editor
$ Ctrl+X Ctrl+E
Alias to repeat last command
$ alias r='fc -s'
Show most used commands
$ history | awk '{print $2}' | sort | uniq -c | sort -nr | head
Reload shell configuration
$ source ~/.bashrc
Check if command exists
$ command -v cmd >/dev/null && echo yes
Change to the previous directory
$ cd -
Create 100 numbered directories
$ mkdir project{01..100}
Quickly backup a file
$ cp file{,.bak}
Empty/truncate a file
$ > file.txt
Batch rename files
$ for f in *.txt; do mv "$f" "${f%.txt}.bak"; done
Create symlink
$ ln -s target link
Show only directories
$ ls -d */
List files by modification time
$ ls -lt
Tree view of directory
$ tree
Show file with line numbers
$ nl file.txt
Count lines in a file
$ wc -l file.txt
Search and replace in files
$ sed -i 's/old/new/g' *.txt
Grep recursively ignoring case
$ grep -ir "text" .
Find files by name
$ find . -iname "*.log"
Find files larger than 100MB
$ find . -type f -size +100M
Delete files older than 30 days
$ find . -mtime +30 -delete
Find and delete empty directories
$ find . -type d -empty -delete
Find broken symlinks
$ find . -xtype l
Show disk usage in human-readable format
$ df -h
Monitor file changes
$ tail -f logfile
Watch command output refresh every 2 seconds
$ watch command
Display clock in terminal
$ watch -n 1 date
Create a tar.gz backup
$ tar czf backup.tar.gz directory/
Extract a tar.gz archive
$ tar xzf archive.tar.gz
Extract any archive format
$ atool -x archive
Split large file
$ split -b 1G largefile part-
Reassemble split files
$ cat part-* > largefile
Check file checksum
$ sha256sum file
Encrypt file with gpg
$ gpg -c file
Copy with progress bar
$ rsync -ah --progress src dest
Create sparse 10GB file
$ truncate -s 10G file.img
Convert DOS to Unix line endings
$ dos2unix file
Pretty-print JSON from stdin
$ jq .
Pretty-print XML
$ xmllint --format file.xml
Pipe output to clipboard
$ command | xclip -sel clip
Run command in background
$ command &
Run detached from terminal
$ nohup command &
Kill process by name
$ pkill process_name
View processes sorted by CPU
$ top
Check system uptime
$ uptime
List cron jobs
$ crontab -l
List hardware info
$ lshw -short
Monitor CPU temperature
$ sensors
Check battery percentage
$ upower -i $(upower -e | grep BAT) | grep percentage
Show current timezone
Show calendar
$ cal
Show previous, current, and next month
$ cal -3
Create RAM disk
$ mount -t tmpfs -o size=1G tmpfs /mnt/ram
Disk speed test
$ dd if=/dev/zero of=test bs=1G count=1 oflag=dsync
Burn ISO to USB
$ dd if=iso.iso of=/dev/sdX bs=4M status=progress
Securely wipe drive
$ shred -v /dev/sdX
Record terminal session
$ script --log-timing timing.log session.log
Replay terminal session
$ scriptreplay --log-timing timing.log session.log
Get your public IP address
$ curl ifconfig.me
List open network ports
$ ss -tuln
Download file with resume
$ wget -c url
Mount remote directory over SSH
$ sshfs user@host:/remote /local
Spin up a local HTTP server
$ python3 -m http.server 8000
Quick HTTP server in Ruby
$ ruby -run -e httpd . -p 8000
Quick HTTP server in PHP
$ php -S localhost:8000
Quick HTTP server in Node.js
$ npx http-server
One-liner web server in bash
$ while true; do echo -e "HTTP/1.1 200 OK\n\n$(date)" | nc -l 8080; done
Show weather in terminal
$ curl wttr.in
Get full weather report
$ curl v2.wttr.in
Generate QR code
$ qrencode -t ANSI "text"
Download YouTube video
$ yt-dlp url
Play YouTube video in terminal
$ mpv url
Play a video in terminal as ASCII
$ mplayer -vo caca video.mp4
Convert image to different format
$ convert input.jpg output.png
Create animated GIF from images
$ convert -delay 10 -loop 0 *.png animation.gif
Convert video to GIF
$ ffmpeg -i input.mp4 output.gif
Merge multiple PDFs
$ gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=out.pdf in1.pdf in2.pdf
Show current git branch
$ git branch --show-current
Show git status nicely
$ git status -sb
Rainbow text
$ echo "text" | lolcat
Simulate slow typing
$ echo "text" | pv -qL 10
Matrix digital rain
$ cmatrix
Run the train animation
$ sl
Play beep
$ echo -e "\a"