LinuxCommandLibrary
ImageImageImage
Image

One-liners

Spin up a local HTTP server

$ python3 -m http.server 8000
copy

Play ASCII Star Wars

$ telnet towel.blinkenlights.nl
copy

Play a video in terminal

$ mplayer -vo caca video.mp4
copy

Simulate slow typing

$ echo "text" | pv -qL 10
copy

Quickly backup a file

$ cp file{,.bak}
copy

Show directory sizes sorted

$ du -sh * | sort -hr
copy

Create a tar.gz backup

$ tar czf backup.tar.gz directory/
copy

Extract a tar.gz archive

$ tar xzf archive.tar.gz
copy

Kill process by name

$ pkill process_name
copy

Generate random password

$ < /dev/urandom tr -dc A-Za-z0-9 | head -c 32; echo
copy

Count lines in a file

$ wc -l file.txt
copy

Find files by name

$ find . -name "*.log"
copy

Find files larger than 100MB

$ find . -type f -size +100M
copy

Copy with progress bar

$ rsync -ah --progress src dest
copy

Mount remote directory over SSH

$ sshfs user@host:/remote /local
copy

Check if command exists

$ command -v cmd >/dev/null && echo yes
copy

Empty/truncate a file

$ > file.txt
copy

Compress with bzip2

$ tar cjf archive.tar.bz2 dir/
copy

Pretty-print XML

$ xmllint --format file.xml
copy

Convert image to different format

$ convert input.jpg output.png
copy

Create animated GIF from images

$ convert -delay 10 -loop 0 *.png animation.gif
copy

Monitor file changes

$ tail -f logfile
copy

Search and replace in files

$ sed -i 's/old/new/g' *.txt
copy

Pipe output to clipboard

$ command | xclip -sel clip
copy

Create symlink

$ ln -s target link
copy

Show current git branch

$ git branch --show-current
copy

Delete files older than 30 days

$ find . -mtime +30 -delete
copy

Find and delete empty directories

$ find . -type d -empty -delete
copy

Generate QR code

$ qrencode -t ANSI "text"
copy

Replay terminal session

$ scriptreplay -t timing.log session.log
copy

Check battery percentage

$ upower -i $(upower -e | grep BAT) | grep percentage
copy

Create RAM disk

$ mount -t tmpfs -o size=1G tmpfs /mnt/ram
copy

Split large file

$ split -b 1G largefile part-
copy

Reassemble split files

$ cat part-* > largefile
copy

Reload shell configuration

$ source ~/.bashrc
copy

Progress bar for any command

$ command | pv -s $(du -b input | cut -f1)
copy

View PDF in terminal

$ pdftotext file.pdf - | less
copy

Burn ISO to USB

$ dd if=iso.iso of=/dev/sdX bs=4M status=progress
copy

Securely wipe drive

$ dd if=/dev/urandom of=/dev/sdX
copy

Disk speed test

$ dd if=/dev/zero of=test bs=1G count=1 oflag=dsync
copy

Play beep

$ echo -e "\a"
copy

Fireworks animation

$ for i in {1..50}; do echo -e "\e[${((RANDOM%7+31))}m✨\e[0m"; sleep 0.1; done
copy

Rainbow text

$ echo "text" | lolcat
copy

Find broken symlinks

$ find . -type l -! -exec test -e {} \; -print
copy

Quick HTTP server in Ruby

$ ruby -run -e httpd . -p 8000
copy

Quick HTTP server in PHP

$ php -S localhost:8000
copy

Alias to repeat last command

$ alias r='fc -s'
copy

Show most used commands

$ history | awk '{print $2}' | sort | uniq -c | sort -nr | head
copy

Extract any archive

$ a() { case $1 in *.tar.gz) tar xzf $1;; *.zip) unzip $1;; esac; }; a file
copy

Create sparse 10GB file

$ truncate -s 10G file.img
copy

Merge multiple PDFs

$ gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=out.pdf in1.pdf in2.pdf
copy

Convert video to GIF

$ ffmpeg -i input.mp4 output.gif
copy

Batch rename files

$ for f in *.txt; do mv "$f" "${f%.txt}.bak"; done
copy

Show git status nicely

$ git status -sb
copy

One-liner web server in bash

$ while true; do echo -e "HTTP/1.1 200 OK\n\n$(date)" | nc -l 8080; done
copy
Image
Copied to clipboard
Image