ls -ld **/*(/^F)

List empty any directories


1
By: int9h
2009-02-18 22:31:13
ls

These Might Interest You

  • 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.


    0
    for foo in <list of directories>; do while find $foo -type d -empty 2>/dev/null| grep -q "."; do find $foo -type d -empty -print0 | xargs -0 rmdir; done; done
    ClashTheBunny · 2012-05-23 08:09:16 0
  • I wanted an easy way to list out the sizes of directories and all of the contents of those directories recursively. Show Sample Output


    1
    du -h --max-depth=1 /path/folder/
    ene2002 · 2013-07-09 19:56:13 0
  • Does an 'ls' on just the files and directories in the current directory with an execute bit turned on. This version will list directories. Just tack on "-type f" to the start of the find to omit listing directories and list only files.


    1
    ls -dF `find . -maxdepth 1 \( -perm -1 -o \( -perm -10 -o -perm -100 \) \) -print`
    wam · 2009-02-05 16:59:38 0
  • If you give tar a list of filenames, it will not add the directories, so if you don't care about directory ownership or permissions, you can save some space. Tar will create directories as necessary when extracting. This command is limited by the maximum supported size of the argument list, so if you are trying to tar up the whole OS for instance, you may just get "Argument list too long".


    3
    tar -cvzf arch.tgz $(find /path/dir -not -type d)
    pysquared · 2009-12-15 13:46:54 0
  • This command would be useful when it is desirable to list only the directories. 'egrep' chooses only the lines that begin with 'd'. Show Sample Output


    3
    ls -l | egrep ^d
    ergut · 2009-02-08 22:21:55 4
  • Ever use 'locate' to find a common phrase in a filename or directory name? Often you'll get a huge list of matches, many of which are redundant, and typically the results are not sorted. This command will 'locate' your search phrase, then show you a sorted list of just the relevant directories, with no duplications. So, for example, maybe you have installed several versions of the java jre and you want to track down every directory where files matching "java" might exist. Well, a 'locate java' is likely to return a huge list with many repeated directories since many files in one directory could contain the phrase "java". This command will whittle down the results to a minimal list of unique directory names where your search phrase finds a match.


    2
    for i in $(locate your_search_phrase); do dirname $i; done | sort | uniq
    realbrewer · 2009-02-05 14:03:20 2

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

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.

Share Your Commands



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: