You can also use, $ find . -depth -type d -exec rmdir {} \; 2>/dev/null
It only works in zsh
Removes all directories on given path, working from right to left, and stops when reaching a non-empty directory
Counterpart of
mkdir -p new/directory/path
Shortcut (must be issues as next command immediately after mkdir):
^mk^rm
( see http://www.commandlinefu.com/commands/view/19/runs-previous-command-but-replacing )
Avoid clobbering files by either overwriting due to name collisions or by assuming the command worked and deleting the target directory.
This will check if there are any empty directories, or newly emptied directories, in a list of directories. It will then delete all of those directories. It works with gnu find and OSX/BSD find.
It starts in the current working directory.
It removes the empty directory and its ancestors (unless the ancestor contains other elements than the empty directory itself).
It will print a failure message for every directory that isn't empty.
This command handles correctly directory names containing single or double quotes, spaces or newlines.
If you do not want only to remove all the ancestors, just use:
find . -empty -type d -print0 | xargs -0 rmdir
This version handles directory names with spaces properly
commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for: