Command Line – Best Way to Run a Command on Each File in a Directory Tree

command linedirectoryfindscripting

There appear be a number of ways to do this including loops in shell script, find and xargs. Which of these is best, and which is most portable?

Best Answer

find . -exec <command> {} \;

for the current directory as the root of the tree or in general:

find <directory> -exec <command> {} \;