Take the 2-minute tour ×
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 thought the flags I mentioned in the question are the same, but I get the following message with the former, but nothing with the latter:

$ find . -mindepth 1 -type d -exec rm -rf {} \;
find: `./practice4': No such file or directory
find: `./practice10': No such file or directory
find: `./practice7': No such file or directory
find: `./practice9': No such file or directory
find: `./practice1': No such file or directory
find: `./practice5': No such file or directory
find: `./practice3': No such file or directory
find: `./practice6': No such file or directory
find: `./practice2': No such file or directory
find: `./practice8': No such file or directory

Extra questions I have are:, is there an simpler code to delete all subdirectories? Is the order of deletion random? I created the directories using

$ mkdir practice{1..10}
share|improve this question
    
You could use the BASH construct for iterating over files: for dir in practice{1..10}; do rm -rf $dir; done. –  Herman Torjussen Feb 20 '13 at 22:23
1  
Even simpler: rm -rf practice{1..10} –  laebshade Feb 21 '13 at 2:16

2 Answers 2

up vote 5 down vote accepted

From the GNU find manual:

If your find' command removes directories, you may find that you get a spurious error message whenfind' tries to recurse into a directory that has now been removed. Using the `-depth' option will normally resolve this problem.

Other questions:

  • The simplicity of the command depends on your situation, which in the listed case would be: rm -rf practice*.
  • IIRC, the processing order of the files depends on the file system.
share|improve this answer

Thor has already explained why you're getting this error and how to fix it when using find.

Calling find with -mindepth 1 is pointless unless you have additional conditions that can't be expressed in a shell script. What you're trying to do can be written

rm -rf */

as long as the current directory doesn't contain any directory whose name begins with . (which wouldn't be matched by *) or symbolic links to directories (which your find command excludes but the shell snippet above includes).

share|improve this answer
1  
In bash you can include .* (without . and ..) by setting GLOBIGNORE=. –  Hauke Laging Feb 21 '13 at 1:38

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.