User Tools

Site Tools


ubuntu:find:run_one_or_more_commands_for_each_of_finds_results

This is an old revision of the document!


Ubuntu - Find - Run one or more commands for each of finds results

To run a single command for each file found:

find dirname ... -exec somecommand {} \;

To run multiple commands in sequence for each file found, where the second command should only be run if the first command succeeds:

find dirname ... -exec somecommand {} \; -exec someothercommand {} \;

To run a single command on multiple files at once:

find dirname ... -exec somecommand {} +

Example usage of running multiple commands against each file returned by find

find . -type f -name "*.mp3" -print0 | while IFS= read -r -d '' file; do echo "$file"; [[ $(mp3info -r m -p "%r" "$file") -gt 192 ]] && lame -b 192 "$file" "${file%.*}".192.mp3 && mv "${file%.*}".192.mp3 "$file"; done

NOTE: This searches for mp3 files, then checks if their bitrate is greater than 192 kbps; and if so then reduces the bitrate to 192 kbps.

  • This uses the mp3info command to determine the bitrate.
    • This mp3info command needs to be installed with sudo apt install mp3info.

References

ubuntu/find/run_one_or_more_commands_for_each_of_finds_results.1655108206.txt.gz ยท Last modified: 2022/06/13 08:16 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki