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