Find with nested commands

If you want to run nested commands on the results of a ‘find’, then you’ll have to stop bash expansion running before the find command.

E.g. This won’t work because the shell expansion will happen before the find has set the {} to the filename:

find . -type f -name "*.html.bak6" -exec mv {} `basename "{}" .bak6` \;

This will work because the shell expansion will happen after {} is populated:

find . -type f -name "*.html.bak6" -exec sh -c 'mv {} `basename "{}" .bak6`' \;

Last modified: 09/11/2011 Tags:

This website is a personal resource. Nothing here is guaranteed correct or complete, so use at your own risk and try not to delete the Internet. -Stephan

Site Info

Privacy policy

Go to top