问题
I am writing a ShellScript that deletes every found.??? folders with its contents. I wrote this:
find $DRIVE -name 'found.???' -type d -exec rm -r {} \;
It does what I want, but gives this error:
find: „/media/.../found.000”: No such file or directory
find: „/media/.../found.001”: No such file or directory
What can I do with this? Thanks!
回答1:
This isn't really an issue. find is going to pre-process some results and when it tries to delete some directories which have already been deleted, you will get the stderr.
You can either ignore the error messages, use -depth to make it traverse in DFS, or force it to -prune the directories. i.e.
find "$DRIVE" -mindepth 1 -depth -name 'found.???' -type d -exec rm -r {} \;
or
find "$DRIVE" -mindepth 1 -name 'found.???' -type d -prune -exec rm -r {} \;
Note, mindepth 1 is important so you don't accidentally delete "$DRIVE"
回答2:
I'll guess that you're trying to populate a FAT-based fs. Try presenting the real case of those filenames instead:
find "$DRIVE" -name 'FOUND.???' -type d -exec rm -r {} \;
And quote your variable too.
来源:https://stackoverflow.com/questions/24723499/remove-a-directory-with-all-of-its-contents-using-find-under-unix