Scrips : bash one liners

Images

Convert webp to jpg

for i in *.webp ; do convert "$i" "${i%.webp}".jpg; done && rm *.webp

Convert png to jpg

for i in *.png ; do convert "$i" "${i%.png}".jpg; done && rm *.png

Crop to 1920x...

for i in *.jpg ; do convert -resize "1920" -quality 88 "$i" "$i" ; done

Crop to 1080p

for i in *.jpg ; do convert -resize "x1080" -quality 88 "$i" "$i" ; done

Chop top

for i in *.jpg ; do convert -chop 0x42 "$i" "$i" ; done

Chop bottom

for i in *.jpg ; do convert -gravity south -chop 0x42 "$i" "$i" ; done

Chop left

for i in *.jpg ; do convert -chop 42x0 "$i" "$i" ; done

Chop right

for i in *.jpg ; do convert -gravity east -chop 42x0 "$i" "$i" ; done

Renaming

Convert jpeg to jpg

for file in $(ls *.jpeg) ; do mv "$file" "${file%.*}.jpg" ; done

Convert JPG to jpg

for file in $(ls *.JPG) ; do mv "$file" "${file%.*}.jpg" ; done

Convert files with folder's name

for i in */*.* ; do fp=$(dirname "$i") ; fl=$(basename "$i") ; mv "$fp/$fl" "$fp/$fp"_"$fl"; done

Var

Espace vers underscore

for i in *\ *; do mv "$i" `echo "$i" | tr " " "_"`; done

rsync

rsync -rtvua --exclude='.Trash-1000' --exclude='lost+found' --delete-during /media/fgsfds/files/ /media/fgsfds/files-backup/ && notify-send "backup files ok"

rsync -rtvua --delete-during --exclude-from=/home/fgsfds/rsync-excludes /home/fgsfds/ /media/fgsfds/backup/

Create alphabetical subfolders

target=/media/dir/dir/dir/varalpha; mkdir "$target" && for f in /media/dir/dir/dir/* ; do if [[ -f "$f" ]]; then i=${f##*/}; i=${i:0:1} ; dir=${i^} ; if [[ $dir != [A-Z] ]]; then mkdir -p "${target}/#" && mv "$f" "${target}/#"; else mkdir -p "${target}/$dir" && mv "$f" "${target}/$dir" ; fi ; fi ; done

Arborescence et usage disque

tree -d > tree.txt && du -h | sort -h > du.txt && tac du.txt > "disk-usage.txt"

Mélanger fichier

shuf quiznw.txt > quiznwmelange.txt

Lister BD (cbr + cbz + pdf)

find . -name "*.cbr" -print > cbr.txt && find . -name "*.cbz" -print > cbz.txt && find . -name "*.pdf" -print > pdf.txt && cat cbr.txt cbz.txt pdf.txt > all.txt