Skip to main content

Bash tricks

  • Centraliser toutes les images dans un dossier récursivement sans override, sans doublons, et sans charactères étranges (en option peut aussi supprimer les originaux)
# Repeat the following process for every file format you wish (.jpg .JPG .png .PNG) 

# For each .JPG file found, copy it to temp-photos/ directory verbosely and avoid override by renaming files with a numbered backup suffix
fd \.JPG$ -X cp -v --backup=numbered "{}" temp-photos/

# Go in the directory and remove any duplicate files
cd temp-photos/
fdupes . -dI

# Rename all files to remove the weird suffix name to a proper filename (+ verbose)
rename -vo .JPG.~1~ 1.JPG *
rename -vo .JPG.~2~ 2.JPG *
rename -vo .JPG.~3~ 3.JPG *
rename -vo .JPG.~4~ 4.JPG *

# Last check to avoid weird filenames, ideally that should respond nothing
ls *~

# WARNING only do this if you're really sure → will delete all the original files after the copy (+ verbose)
cd ..
fd --exclude temp-photos/ \.JPG$ -X rm -vf "{}"
  • Convertir toutes les images d'un dossier d'un format à l'autre
# This is an example that convert all .JPG files to .avif files

# WARNING might reduce image quality or make the file unreadable by some systems
cd temp-photos # Will get back on the new directory
fd \.JPG$ -x convert -verbose "{}" "{}.avif" # Will convert all .JPG files to .avif files
rename -vo .JPG.avif .avif *.JPG.avif # Will change file extensions to something less weird
rm -vf *.JPG # Will remove all the precedent files to spare space