Delete empty folders linux
Someone asked me to remove all empty net framework 4.0 303 directories in a particular path.
Whether this is faster depends on a lot of things, including whether the whole directory hierarchy can remain in the disk cache between find runs.
Some run commands such ls or du, and check the results are what you'd expect from an empty directory, maybe using wc to check the word count.
You can do it with a single command using the -p flag: mkdir -p /a/v ery/ long /dir ecto ry/s truc ture /whi ch/n obod y/wi ll/e ver/ fin d (Incidentally, there's a command like this called mkdirhier.The glob qualifier, f matches non-empty directories, so /F matches empty directories.Which method is faster depends on how many non-empty directories you have.The GNU version of find supports the -empty test, so find.I don't expect much difference between these two.
depth -type d -exec rmdir 2 /dev/null.
I think what's happening here is that the find command is storing a list of directories up front, and then traversring the tree, running rmdir first (which fails for all parent directories, since they're not empty) followed by cd to the sub-directory (which fails for.
Option 4: find command with -depth and rmdir Fortunately, the find command has an option which lets you cd first, and then do the -exec rmdir.
Use find - or find "home" - to base the search on your home directory (if it isn't your current directory).
Option 2: rmdir -p, remember, the aim is to remove empty directories.You can't combine -empty with methods for grouping invocations, because then the directories that only contain empty directories aren't empty by the time find looks at them.Where, -empty : Only find empty files and make sure it is a regular file or a directory.type d -empty -delete.This is useful when you need to clean up empty directories and files in a single command.Redirecting only for rmdir would cause a significant slowdown as you'd need to invoke an intermediate shell.).These examples may crash your computer if executed.Use the -type d expression to tell find you're interested in finding directories only (and not plain files).