Command Line: Useful Snippets

These random commands are related to the bash tricks, but are less specific to bash, so they may (or may not - haven’t tried) work on other shells. Credit goes - at least partially - to commandlinefu.com

Create a pdf from a man page:

$ man -t topic | ps2dpf - output.pdf

Globbing with exclusions. Delete all but the txt files:

$ rm !(*.txt)

Exclude a process from receiving SIGHUP on logout (e.g. when working remote)

$ disown [-ar] [-h] [jobspec ... | pid ... ]

e.g.

$ disown %2

Show command output (here date) in upper right corner. The ampersand in the end makes this run in the background while you do your regular stuff. Attention, though: If you happen to type a character at the wrong time (between tput cup and tput rc), it might end up in said corner. The more likely, the longer the command takes.

while sleep 1; do
  tput sc #save cursor
  tput cup 0 $(($(tput cols)-29)) #goto upper right
  date
  tput rc #restore cursor
done &

Very simple screen recording. Requires to install slop (apt get slop), which allows to select the area to be recorded with the mouse.

$ read -r o g < <(slop -f '+%x,%y %wx%h'); ffmpeg -f x11grab -framerate 15 -video_size "$g" -i "${DISPLAY}${o}" output.mp4


Home