Grimoire-Command.es

To content | To menu | To search

Tag - find

Entries feed

2018-01-17

Recompress images JPEG / PNG at equal quality

Recompresser des images JPEG / PNG sans perte de qualité

  • JPG monotask : find . -name \*.jpeg -exec jpegoptim -pt
  • JPE?G multitask : find . -regextype posix-extended -iregex '.*(jpeg|jpg)' -print0 | xargs -0 -P $((`nproc` / 2)) jpegoptim -pt [1]
  • PNG multitask : find . -name \*.png -print0 | xargs -0 -P $((`nproc` / 2)) -I {} zopflipng -m --lossy_8bit --lossy_transparent -y {} {} [2]

Notes

[1] find can accept regex ; See Rip music CD to MP3 or FLAC for -print0 / -0

[2] -I {} permit to choose a replacement token for file names ; here we explicitely set zopflipng calls to overwrite files

2018-01-12

Grep some text in some selected files

Trouver du texte dans une sélection de fichiers

find "$3" -name "$2" -print0 | xargs -0 grep -i -n --color $1

  • $1 : text to search
  • $2 : files to find and search in
  • $3 : where to search for files to find
  • find -print0 | xargs -0  : use zeros to separate elements, not spaces, to accept spaces in file names

2017-12-16

Rip music CD to MP3 or FLAC

Copier un CD de musique en MP3 ou Flac

CD -> WAV : cdparanoia -d /dev/hda -B
WAV -> MP3 : lame --vbr-new --preset extreme a_file.wav a_file.mp3
*.WAV -> MP3 : for x in `ls *.mp3`; do lame --vbr-new --preset extreme $x "`basename ${x} .wav`.mp3"; done; [1]
*.WAV -> MP3 in parallel : find . *.wav -print0 | xargs -0 -P $((`nproc` / 2)) -I {} lame --vbr-new --preset extreme {} {}.mp3 rename 's/\.wav\.mp3$/\.mp3/' *.mp3 [2]
*.WAV -> FLAC : flac --replay-gain --best *.wav
*.WAV -> FLAC in parallel : find . *.wav -print0 | xargs -0 -P $((`nproc` / 2)) -I {} flac --replay-gain --best "{}"

Notes

[1] --print0 / -0 options replace space by zeros at file name ends to deal with spaces in file names ; backticks call a sub-command ; basename isolate main part of name from extension

[2] $(()) for math operations ; backticks nproc for CPU number ; rename files in a second time