Logo Background RSS

How do I remove all empty directories?

  • You can use program called cleanlinks. The cleanlinks program searches the directory tree descended from the current directory for symbolic links whose targets do not exist, and removes them. It then removes all empty directories in that directory tree. It was originally created for symbolic links based directories but works with normal directories too.

    For example if you want to remove all empty directories from /tmp directory, type the command:

    $ cd /tmp
    $ cleanlinks

    Please note that cleanlinks command is part of XFree86 project. Another method is to use combination of shell commands in script:

    #/bin/bash
    DIR=”$1″
    [ -d $DIR ] && [ $(ls -l $DIR | wc -l) -eq 1 ] && rmdir $DIR || :

    Save and execute a script:

    $ script.sh dir1

    You can also try out tmpreaper command which recursively searches for and removes files and empty directories which haven’t been accessed for a given number of seconds. Normally, it’s used to clean up directories which are used for temporary holding space, such as “/tmp”. Syntax is as follows:
    tmpreaper TIME-FORMAT DIRS

    Where,

    • TIME-FORMAT : Defines the age threshold for removing files. The TIME-FORMAT should be a number, defaulting to hours, optionally suffixed by one character: d for days, h for hours, m for minutes, or s for seconds.
    • DIRS : Directory name for example /tmp

    For example, remove all files accessed 24h before:

    # tmpreaper 24h /tmp

    Please note that tmpreaper command is not installed by default you may need to install it using apt-get or rpm command.

11 Comments
  1. #1 infoproservices.com
    August 4th, 2009 at 5:42 am

    Maybe if the page has good information or sticks to the topic, there is a possibility that it can have a good page rank. It might not be worth the time, but who knows what might happen?

    Post ReplyPost Reply
  2. #2 infoproservices.com
    August 4th, 2009 at 5:43 am

    I want to delete all the directories under a parent directory without deleting the parent through DOS command line. That case i don’t know how many directories exist under parent.

    Post ReplyPost Reply
  3. #3 infoproservices.com
    August 4th, 2009 at 5:43 am

    The web directories that I submited to are not Yahoo or Google directories, but those small, not that famous ones which exist thousands online.

    Post ReplyPost Reply
  4. #4 Konsole kaufen
    December 30th, 2009 at 12:31 pm

    It is great to know about cleaning the web directories. Thanks for providing this type of valuable information to others in a great manner. It will really proves to be a nice one for others to make it.

    Post ReplyPost Reply
  5. #5 SEO
    January 29th, 2010 at 11:55 am

    Pound the pavement. Go door to door explaining everything. Advertise in the business sections of newspapers and business radio stations.

    Post ReplyPost Reply
  6. #6 SEO
    February 1st, 2010 at 4:07 pm

    You can also try out tmpreaper command which recursively searches for and removes files and empty directories which haven’t been accessed for a given number of seconds. Normally, it’s used to clean up directories which are used for temporary holding space.

    Post ReplyPost Reply
  7. #7 seo
    March 3rd, 2010 at 10:36 am

    Don’t use xargs at all, just use -delete in find (available in findutils for about 2 years now, so in every ‘recent’ distro.

    Post ReplyPost Reply
  8. #8 seo
    March 30th, 2010 at 3:40 pm

    This folder may also contain certain files that allows the external hard drive to function correctly, thus why you can’t delete it. My external hard drive has autorun files and the like on it too.

    Post ReplyPost Reply
  9. #9 seo
    April 1st, 2010 at 11:13 am

    Action mentioned above by Lingerance seems to be a nonstandard extension – GNU find doesn’t know about it.

    Post ReplyPost Reply
  10. #10 seo
    May 4th, 2010 at 8:20 am

    I really enjoyed your post. It’s true that article marketing can really drive traffic to your website if you know how to. It is one of the most profitable form of advertising and what’s more it’s FREE!

    Post ReplyPost Reply
  11. #11 seo
    June 2nd, 2010 at 8:08 am

    The program has a clean, professional interface and does what it is designed to do. My guess is that the negative reviewers tried to use it on an entire hard drive – including system folders – and thus were rushing in where angels fear to tread.

    Post ReplyPost Reply
Leave a Comment