bashgnu-parallel

How to run command only when parallel processing is successful


I am using parallel GNU to process thousands of files and the conversion is successful, I am unable to delete the processed file once it's done.

I know I can use parallel --halt now,fail=1 to stop parallel when a command fails but that's not what I am looking for.

find . -maxdepth 1 -type f -iname "*.wav" | parallel -j+0 ffmpeg -threads 0 -hide_banner -loglevel error -i {} -movflags use_metadata_tags -c:a libmp3lame -q:a 2 ./converted/{.}.mp3 && rm {}

Thanks

I tried using && rm {} as part of the parallel process but the file was not deleted.


Solution

  • One potential solution is:

    find . -maxdepth 1 -type f -iname "*.wav" |\
    parallel -j+0 --halt now,fail=1 'ffmpeg -threads 0 -hide_banner -loglevel error -i {} -movflags use_metadata_tags  -c:a libmp3lame -q:a 2 ./converted/{.}.mp3; rm {}'
    

    (making sure to quote commands)