LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-10-2003, 10:16 PM   #1
noisybastard
Member
 
Registered: May 2003
Distribution: RedHat 9
Posts: 32

Rep: Reputation: 15
how do I remove all empty directories?


I'm trying to figure out how to recursivly remove all of the empty directories on my computer.

I have many cases where a directory contains another directory which is empty, so I'm trying to figure out a way to delete all of the empty child folders, and then delete any of the empty parent folders after that.

I've tried looking at the man pages for rmdir, and toying around with grep, but I can't seem to figure this one out.
 
Old 08-10-2003, 11:18 PM   #2
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Rep: Reputation: 31
If it's just a few directories that you can delete the parent by hand, just do rm -rf dirname where dirname is the directory name. Otherwise, this might be something you want to script. There might be a fancy find way of doing it, but I can't think of a way to do it with find that would be any easier than doing it in a script.
 
Old 08-10-2003, 11:47 PM   #3
ramram29
Member
 
Registered: Jul 2003
Location: Miami, Florida, USA
Distribution: Debian
Posts: 848
Blog Entries: 1

Rep: Reputation: 47
Be careful! Some empty directories are needed for file locking and several other things. Some of your programs may not work correct if you remove certain subdirectories such as the ones in /proc or /var.

As root you can try the following command:

du -h / > d1.txt ; sort -g d1.txt > d2.txt
less d2.txt

The command above will run du (disk usage), reporting all files and directories and their size. It will store the output to d1.txt. Afterward you can sort d1.txt onto d2.txt in numerical order that way you can look at all the files and folders that have 0 size with the less command.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
finding empty directories with bash Iriel Solaris / OpenSolaris 10 02-18-2016 03:59 AM
how to search for and delete empty directories? BrianK Programming 4 06-03-2005 07:24 AM
ProFTPD - deleting non-empty directories? orange400 Linux - Software 1 05-28-2004 03:36 AM
Removing non-empty directories brunnopessoa Linux - Newbie 8 11-13-2003 07:56 PM
finding empty directories... PokerFace Linux - General 2 10-16-2002 08:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration