The following find-exec(mv) command finds a directory named say prog-3.6.9-stable-gnu and changes its name sucessfully. Yet, the command also returns:

find: './prog': No such file or directory

This is the command:

find ./ -type d -name 'prog-*' -exec mv {} prog \;

I get a similar result when find-exec(rm) that dir:

Given the find command comes before the working exec unzip (or exec rm -rf for that matter) I want to ask why would I have this stderr? I mean, if the file was found and was changed, why would the stderr be "No such file or directory" ?


The error appears because you are moving a folder "prog-*".
The actual behaviour of find is:

find analyzes first the directory itself, and then its contents.

So, find, in your example:
1. finds the directory prog-3.6.9-stable-gnu
2. renames it in prog (so now has a new name)
3. tries to access prog-3.6.9-stable-gnu
4. it gives back an error because now, it is not able to find the folder prog-3.6.9-stable-gnu

find's order of analysing first the directory, and then its contents, is known as "breadth-first traversal". The opposite is "depth-first traversal". There is an option -depth which invokes this. It is interesting to read mentions of -depth in the man page for find(1).

  • "-depth: Process each directory's contents before the directory itself."
  • "The -delete action also implies -depth."
  • "Don't forget that the find command line is evaluated as an expression, so putting -delete first will make find try to delete everything below the starting points you specified."
  • "When testing a find command line that you later intend to use with -delete, you should explicitly specify -depth in order to avoid later surprises."
  • "Because -delete implies -depth, you cannot usefully use -prune and -delete together."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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