Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I was wanting to run a find and then execute a script on each match; however, I was wanting to print the name of the matched file above the output from each exec. How can I produce the following output:

$ find . -name 'something' -exec sh {} \;
output from something_1
output from something_2

I am currently only getting the output from I tried -exec echo {} && sh {} \; with no success.

I would prefer a solution using -exec or xargs -print0, i.e., not prone to problems with white space.

share|improve this question
If you can modify, the do so to make it emit the file it operates on just as it start. If you can not, make a which emits the output and calls If your script can take multiple file names as arguments then you should investigate xargs, eg find -find_options | xargs – Johan Mar 1 '13 at 5:17

2 Answers 2

find prints all matching files by default if you don't specify any other action.

When you do -exec ..., it replaces the -print.

When you put two actions next to each other, it means AND.

So just do both:

$ find . -name 'something' -print -exec sh {} \;
share|improve this answer

Try doing this :

$ find . -name 'something' -exec sh {} \; | |
share|improve this answer

Your Answer


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.