Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Most people are familiar with using find to run the same command on a number of files, e.g.:

find -type f | xargs command

or

find -type f -exec command {} \;

My question is whether it's possible to run multiple commands from find:

find [path] [expression] -exec command1 {} -exec command2 {} \;

so that the output would look like

command1: file1
command2: file1
command1: file2
command2: file2
command1: file3
command2: file3
command1: file4
command2: file4

Obviously I can write a simple shell script wrapper for this, but is it possible to do it all from the command line (perhaps using awk, tee etc.)?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Or

find . -exec echo {} \; -exec echo {} \;
share|improve this answer
add comment

You could do something simple like this.

find . -exec bash -c 'echo {} ; echo {} ' \;
share|improve this answer
    
Along with some "{}", this is perfect! –  Andrew Oct 8 '10 at 6:16
    
... ok, I'll have to give it to the other one after all; it does actually give multiple -exec options. But this is also good. –  Andrew Oct 11 '10 at 2:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.