LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 10-05-2007, 04:24 PM   #1
iAlta
Member
 
Registered: Oct 2005
Distribution: Ubuntu 7.10, OpenSUSE 10.3, Linux Mint, Arch
Posts: 92

Rep: Reputation: 15
recursively remove directories


Is there a tool that will let me recursively remove all empty directories in a directory?
 
Old 10-05-2007, 05:17 PM   #2
{BBI}Nexus{BBI}
Senior Member
 
Registered: Jan 2005
Location: Nottingham, UK
Distribution: Mageia 4
Posts: 4,296

Rep: Reputation: 205Reputation: 205Reputation: 205
No special tool required. Open a terminal and type: rm -r -f (directory name). If you want to control what directories are deleted don't add the -f option.
 
Old 10-05-2007, 05:43 PM   #3
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
Nooooooooo! rm -rf will remove EVERYTHING, not just the empty directories.
 
Old 10-05-2007, 05:48 PM   #4
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
This should do the job:
Code:
find /path/to/top/directory -depth -type d -empty -exec rmdir {} \;
Dave
 
Old 10-05-2007, 07:08 PM   #5
iAlta
Member
 
Registered: Oct 2005
Distribution: Ubuntu 7.10, OpenSUSE 10.3, Linux Mint, Arch
Posts: 92

Original Poster
Rep: Reputation: 15
LOL :-) I do believe you need root to delete all th econtent, or maybe that's just with rmdir...


I tried that, but I got this:
Code:
find: missing argument to `-exec'
 
Old 10-05-2007, 07:16 PM   #6
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
Nope, rm -rf will remove everything that you have permissions to remove under the given directory.

As for the error, I'm not sure. The command works for me. Did you type it exactly as listed?

Dave

Last edited by ilikejam; 10-05-2007 at 07:17 PM.
 
Old 10-06-2007, 12:49 AM   #7
{BBI}Nexus{BBI}
Senior Member
 
Registered: Jan 2005
Location: Nottingham, UK
Distribution: Mageia 4
Posts: 4,296

Rep: Reputation: 205Reputation: 205Reputation: 205
Quote:
Nooooooooo! rm -rf will remove EVERYTHING, not just the empty directories.
Like I said, if you want control over what directories are deleted omit the -f option.

Last edited by {BBI}Nexus{BBI}; 10-06-2007 at 12:51 AM.
 
Old 10-06-2007, 09:25 AM   #8
marco18
Member
 
Registered: Jul 2007
Location: Argentina
Distribution: Ubuntu 13.04 , Debian Lenny 5.0.7
Posts: 223

Rep: Reputation: 21
Pretty good contribution ilikejam! Useful to me too. Thanks!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove directories recursively with same name cboyd Linux - Newbie 5 01-14-2007 09:48 PM
chmod directories recursively mfilippa Linux - Newbie 3 04-17-2006 07:24 PM
Recursively traversing sub-directories ark86 Linux - Newbie 2 01-29-2006 01:15 PM
How to Recursively Set Permissions for Directories Only edwin11 Linux - Software 4 12-30-2005 09:54 AM
Can ls recursively list only directories? Vosper Linux - General 3 07-16-2005 03:57 AM


All times are GMT -5. The time now is 11:51 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration