I need to find a way to remove sub-directories from within a particular directory without receiving an error if no sub-directories exist. This command will successfully remove sub-directories if they exist
find /path/to/dir/* -maxdepth 1 -type d -exec rm -rf {} \;
But if none exist I will get this error:
find: /path/to/dir/*: No such file or directory
Also, I am using the find
instead of just plain rm
because there are too many directories for rm
to handle and they must be handled individually with find
.
Also I noticed that find /path/to/dir/ -maxdepth 1 -type d -exec rm -rf {} \;
with no wildcard actually removes the dir directory as well.
rm
isARG_MAX
from the glob, find is going to have the same problem since that is a global limitation.