Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.


Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.


Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.


Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Commands & Shells

A Faster Way to Delete Many Folders

Submitted by on October 24, 2012 – 11:00 pm 4 Comments

This issue is particularly annoying when dealing with expansive directory structures mounted via NFS. Let’s say you have a directory with ten thousand folders and each of them has more subfolders and files. And you need to delete all of them. Running the usual “rm -rf *” at the top of the directory structure will take a very, very long time. There is a faster way.

The idea is to use the “find” command with the “maxdepth” parameter to locate directories one or two levels deep and to run “rm” on each of those directories in the background. In my experience, this approach cuts the required time many-fold . Here is an example:

find . -maxdepth 1 -type d -print | grep -v "^.$" | while read dir ; do nohup /bin/rm -rf "${dir}" &

Note: he entering this command, make sure to hit enter after the ampersand and then enter “done”.

Print Friendly, PDF & Email


  • EzioAuditore1459 says:

    I can do this with other email but haven’t been able to do this with Yahoo. Deleting item by item would take forever. I’d like to be able to save some selected items but this is not an absolute necessity.

  • blarg blarg says:

    My yahoo mail box contains more than 40.000 mails. I am looking for an easy way to delete all and start from scratch. It seams impossible to delete them page by page.

  • arronwrath says:

    I think it needs to open some folder called %temp% , but I can’t open it, can anyone help me?
    I have to go to some folder called %temp% how can i get there? I know how todelete it from IE. It’s in the computer.
    I have to go to some folder called %temp% how can I get there? I know how todelete it from IE. It’s in the computer.

  • ibjammin44 says:

    I just recently got back online after about 3years and have over 90,000 emails that i want to delete all at once instead of page by page. Can i reset my email and delete them all? or is there another way? or am i just stuck deleting page by page?

Leave a Reply

%d bloggers like this: