W Command line snippets


Useful command line snippets

Rename file in bash

Renames foo-bar-baz.txt to foo-bar-quux.txt Source: https://news.ycombinator.com/item?id=22859935

mv foo-bar-{baz,quux}.txt

Reduce PDF size

Source: https://askubuntu.com/questions/207447/how-to-reduce-the-size-of-a-pdf-file

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

Copy directory structure without files

rsync -av -f"+ */" -f"- *" "$source" "$target"

Make a slideshow with ffmpeg

Source: https://news.ycombinator.com/item?id=22028319

cat *.jpg *.JPG *.jpeg | ffmpeg -r .5 -i - -vf "scale=w=1280:h=720:force_original_aspect_ratio=2,crop=1280:720" -y slideshow.mp4

Change video speed in browser

setInterval(() => {document.querySelectorAll('video').forEach(v => v.playbackRate = 1.7)}, 10000)

SQL Join two csv files

Source: https://www.johndcook.com/blog/2019/12/31/sql-join-csv-files/

xsv join ID person.csv ID weight.csv

Conver excel to csv

Source: https://linoxide.com/linux-how-to/methods-convert-xlsx-format-files-csv-linux-cli/

ssconvert book.xlsx file.csv

Show list of available wifi networks

nmcli dev wifi

Create new dart package

stagehand package-simple

Hranoprovod consumed food for a year

hranoprovod-cli csv -b 2019/01/01 -e 2020/01/01 | awk -F";" '{a[$2]+=$3;}END{for(i in a)print a[i]/10"\t"i;}' | grep 100g| sort -n | less

Restart sound

pulseaudio -k && sudo alsa force-reload

List input devices

xinput list

Enable/disable input device

xinput --disable 11
xinput --enable 11

Vim - create new buffer in vertical split

:vnew

Sqlite - Show columns

.headers on
.mode column

Number of files by extension

find . -type f | sed -n 's/..*\.//p' | sort | uniq -c

Execute a command when a file is created

inotifywait -r -m /tmp/ | while read a b file; do [[ $b == *CREATE* ]] && echo $a$file && sleep 1 && img2ascii -converter=24bit2x -width=120 "$a$file"; done

Manage python apps

pipx - like apt for pip installable apps