Date created: Tuesday, February 28, 2012 9:50:34 PM. Last modified: Monday, October 14, 2024 2:34:39 PM

Random Commands

Fun / Misc:

Parrot Party:

curl parrot.live

 

The Weather:

curl wttr.in/

 

Digital clock in the terminal:

watch -t -n 1 "date +%T | figlet"

A binary clock:

watch -n 1 'echo "obase=2;`date +%s`" | bc'

 

Fork Bomb:

#/bin/bash
$0&
$0

 

Another Fork Bomb:

:(){ :|:& };:

 

Bash progress bar/indicator/spinner:

tar -cvzf ${TAR} ${DIR} | tqdm --unit_scale --total $(find ${DIR} -type f | wc -l ) > /dev/null

# Or...

for((i=0;i<120000;i++))
do
echo -ne "Progress: $[ ($i+1)*100/120000 ]%\r";
done;

# Or...

while :;do for s in / - \\ \|; do printf "\r$s";sleep .1;done;done

 

Ghostscript:

Glue multiple PDFs together:

gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=large.pdf -f small1.pdf small2.pdf small3.pdf

 

System commands:
Scrollable full `ps` output

ps awwfux | less -S


Find out how much data is waiting to be written to disk

grep ^Dirty /proc/meminfo

 

Release memory used by the Linux kernel on caches

free -m && sync && echo 3 > /proc/sys/vm/drop_caches && free -m



Handy tricks:

Export vars in .ENV file:

export $(cat .env | grep -v ^# | xargs) >/dev/null

 

Seconds to Hours:Minutes:Seconds

awk -v seconds=54321 'BEGIN {print strftime("%H:%M:%S", seconds, 1)}'

 

Epoch time to human time

date -d @1331485023

 

Sort du output by size

du -hs * | sort -rh

 

Echo with sudo

sudo 'echo "10" > /proc/sys/vm/swappiness'      # Doesn't work
sudo sh -c 'echo "10" > /proc/sys/vm/swappiness' # Works for replace, >> for append
echo "10" | sudo tee -a /proc/sys/vm/swappiness > /dev/null # Works for append, remove -a for replace

 

Recursive grep

grep -r "string" /blah/blah

 

Sort ls output by reverse modified time (so newest at bottom)

ls -ltr

Sort by size (smalllest at bottom)

ls -ls
ls -lS 

 

Start COMMAND, and kill it if still running after 5 seconds

timeout 5s COMMAND

 

Stopwatch

alias timer='echo "Timer started. Stop with Ctrl-D." && date && time cat && date'