Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. 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.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

Stay in the loop…

Follow the Tweets.

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

Subscribe to the feeds.

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands using rmdir from sorted by
Terminal - Commands using rmdir - 14 results
find . -empty -type d -print0 | xargs -0 rmdir -p
2013-07-01 02:44:57
User: rafar
Functions: find rmdir xargs
0

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
rmdir -p new/directory/path
2013-05-21 12:34:55
User: r3tro
Functions: rmdir
Tags: mkdir rmdir
0

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 )

rmdir --ignore-fail-on-non-empty -p **/*(/^F)
2012-09-18 20:28:46
User: xro
Functions: rmdir
0

recursively delete empty directories and directories which only contain empty directories using zsh globbing syntax. ** is for recursive globbing. *(/^F) matches all entries that are directories which are not full.

If you only want to delete empty directories and not those directories which contained only empty directories and will be empty afterwards, just leave out the options to rmdir:

rmdir **/*(/^F)
mv .git .. && rm -rf * && mv ../.git . && mv .git/* . && rmdir .git && git config --bool core.bare true
2011-02-28 17:58:14
User: dinomite
Functions: mv rm rmdir
1

If you want to turn a Git repo into the origin that folks can push to, you should make it a bare repository. See: http://stackoverflow.com/questions/2199897/git-convert-normal-to-bare-repository

find . ! -name "." -print0 | xargs -0 -I '{}' mv -n '{}' ..; rmdir "$PWD"
2010-12-15 22:12:06
User: bartonski
Functions: find mv rmdir xargs
1

Robust means of moving all files up by a directory. Will handle dot files, filenames containing spaces, and filenames with almost any printable characters. Will not handle filenames containing a single-quote (but if you are moving those, it's time to go yell at whoever created them in the first place).

mv -n * ../; cd ..; rmdir $OLDPWD
2010-11-12 20:22:50
User: kevingranade
Functions: cd mv rmdir
Tags: mv rmdir
0

Avoid clobbering files by either overwriting due to name collisions or by assuming the command worked and deleting the target directory.

find . -depth -type d -empty -exec rmdir -v {} \;
find . -type d | tac | xargs rmdir 2> /dev/null
2010-03-23 11:54:38
User: drmaciver
Functions: find rmdir tac xargs
-1

Remove all empty directories below the current directory. If directories become empty as the results of this, remove those too.

rmdir **/*(/^F)
find . -depth -type d -empty -exec rmdir -v {} +
2009-08-05 13:48:13
User: syssyphus
Functions: find rmdir
Tags: find
7

this will show the names of the deleted directories, and will delete directories that only no files, only empty directories.

find . -empty -type d -exec rmdir {} +
2009-08-04 16:55:34
User: jsiei97
Functions: find rmdir
14

A quick way to find and delete empty dirs, it starts in the current working directory.

If you do find . -empty -type d you will see what could be removed, or to a test run.

find . -type d -exec rmdir {} \;
2009-05-19 08:59:15
User: sharfah
Functions: find rmdir
Tags: find rm
1

Deletes empty directories and prints an error if directory is not empty.

find . -regex "[^.]*" -depth -empty -type d -mtime +1 -exec rmdir -v {} \;
find <top_level_dir> -depth -type d -empty -exec rmdir -v {} \;