I'm reading how Linux works by Brian Ward and he has issued the following warning "Don't try options such as -exec before you know this form by heart" find -name file -print

Thus far, I have not understood why that form in particular is so important. Why might I not want to search for directories in a particular place regardless of their name. Also, it seems to me that -print is a default option and the manpage strongly suggests using -print0 as some file names may include new line characters.

1 Answer 1


The author cautions the reader against trying -exec without understanding the structure and approach of the find command.

There is no harm in you trying find -type d -print, for example. CAUTION But do you understand what would happen if you ran this find -depth -type d -exec mv {} {}.surprise \;?

If you want to see what would happen, replace (or supplement) the mv with a command that performs no permanent action:

find -depth -type d -exec echo mv {} {}.surprise \;

With regard to -print0, that is only of use when working within a pipeline. (But it's very useful there when your other utilities support its NUL-separated records.) If you want simply to list the find output for visual inspection, use -print instead.

PS. When you want to recover from having run the dangerous command on an important part of your filesystem you can probably run find -depth -type d -print0 | while IFS= read -r -d '' d; do mv "$d" "${d%.surprise}"; done. But it would have been better to try it in a safe part of /tmp.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .