Search This Blog

Execute a command on the results of find command

  • execute the command multiple times on each individual result file:
    find . -type f -exec echo {} \;
    The result should look like:
    ./1
    ./3
    ./2
  • execute the command only once on all result files:
    find . -type f -exec echo {} +
    The result should look like:
    ./1 ./3 ./2



Example: Remove .DS_Store and ._* files:

find . -type f -name '.DS_Store' -exec rm -f {} \;
find . -type f -name '._*' -exec rm -f {} \;

see also

No comments:

Post a Comment