How to delete nonempty directory? | Unix Linux Forums | UNIX for Advanced & Expert Users

  Go Back    


UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

How to delete nonempty directory?

UNIX for Advanced & Expert Users


Tags
delete, directory

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 05-01-2003
xli3 xli3 is offline
Registered User
 
Join Date: Apr 2002
Last Activity: 23 August 2006, 8:39 PM EDT
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
How to delete nonempty directory?

How to delete nonempty directory?
Thanks
Sponsored Links
    #2  
Old 05-01-2003
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
 
Join Date: Aug 2002
Last Activity: 3 October 2004, 6:07 PM EDT
Location: Cleveland, OH
Posts: 804
Thanks: 0
Thanked 6 Times in 5 Posts
The directory has to be empty to use the rmdir command.. you can use rm yourdir/*; rmdir yourdir

Or you can use rm -r yourdir, but be careful. This is recursive, so all the files in yourdir will be deleted, then yourdir will be deleted, and if the directory yourdir was in is now empty, that will get deleted too. Read the rm man page for more info.

Last edited by oombera; 05-01-2003 at 02:32 AM..
The Following 2 Users Say Thank You to oombera For This Useful Post:
saps19 (07-04-2011), Yerod (10-16-2012)
Sponsored Links
    #3  
Old 05-01-2003
lairc lairc is offline
Registered User
 
Join Date: Jan 2002
Last Activity: 21 October 2004, 5:23 PM EDT
Location: Arlington, TX
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
I'd suggest using rm -r ./yourdir from one dir level higher just so you're sure that deleting the correct directory. rm -r isn't very forgiving.

If you don't want it to ask you for confirmations you can use rm -rf ./yourdir.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to delete some of the files in the directory, if the directory size limits the specified size shaal89 Shell Programming and Scripting 0 02-10-2012 09:22 AM
print all nonempty pipe nimesh Programming 3 11-18-2011 11:06 AM
use awk to replace empty fields with the latest nonempty field grossgermany Shell Programming and Scripting 1 10-27-2009 10:21 AM
count number of nonempty columns in row grossgermany Shell Programming and Scripting 2 01-09-2009 05:35 AM
remove a nonempty directory babayeve UNIX for Dummies Questions & Answers 2 08-26-2002 12:34 PM



All times are GMT -4. The time now is 11:43 AM.