LinHES Forums
http://forum.linhes.org/

Deleting a non-empty directory
http://forum.linhes.org/viewtopic.php?f=5&t=12753
Page 1 of 1

Author:  ihatetivo [ Mon Nov 27, 2006 6:10 pm ]
Post subject:  Deleting a non-empty directory

Each time I attempt to recursively delete a non-empty directory, I am asked to dive into the directory and delete each file. There must be an easier way.

Question: Is the following command inappropriate for deleting a non-empty directory?

Code:
 rm -r directory

Author:  khrusher [ Mon Nov 27, 2006 7:12 pm ]
Post subject: 

sure it is.

also
Code:
rm -rf
may be useful. the -f is 'force' which disables all prompts and just does the rm (where permissions allow)

Author:  mjl [ Mon Nov 27, 2006 8:44 pm ]
Post subject: 

Hi,

I use the rm -rf frequently myself, HOWEVER, do be careful as it does what you tell it. There are NO questions like "are you sure, really sure?" and then put it a recycle bin.

Mike

Author:  ihatetivo [ Tue Nov 28, 2006 4:44 pm ]
Post subject: 

mjl wrote:
Hi,

I use the rm -rf frequently myself, HOWEVER, do be careful as it does what you tell it. There are NO questions like "are you sure, really sure?" and then put it a recycle bin.

Mike


Understood. It is a powerful command; not one to be taken lightly. However, if I need to delete a folder with hundreds of files, it seems the only way.

Author:  crasarx [ Fri Dec 01, 2006 5:28 pm ]
Post subject: 

You could always

Code:
rm /dir/* -i;rmdir /dir


Or leave out the -i if you don't want to be prompted for confirming deletion of each file.

Author:  abigailsweetashoney [ Tue Dec 05, 2006 1:49 pm ]
Post subject: 

Linux quite annoyingly aliases "rm" to "rm -i" so it prompts you for confirmation. I usually remove the alias.

Author:  cesman [ Tue Dec 05, 2006 7:25 pm ]
Post subject: 

You could also change it to "rm -fr". :)

Author:  mjl [ Tue Dec 05, 2006 7:41 pm ]
Post subject: 

Hi cesman,

Does the order of the switches actually play a part in the rm command? Also is there limit to the number of files in a directory that can be removed in this manner?

Reason for the question is when using motion, I had to use a special script as the quanity of files reached a certain level. tjc was very kind and provided that script for us (in the motion thread) which would empty the directory and not remove it.

Thanks
Mike

Author:  cesman [ Tue Dec 05, 2006 7:50 pm ]
Post subject: 

Hello mjl,

I don't know if the order matters. Yes, there is a limit, however I don't know what that is...

Author:  mjl [ Tue Dec 05, 2006 8:05 pm ]
Post subject: 

Hi,

Thank you cesman.

I think that ihatetivo may want to search for tjc's motion clean up script as it sounds like that may serve his needs better than the rm command.

It takes a couple of minutes for the script to clean out my motion folder each day however never fails to do exactly that task. A good test is to input tv into motion and let it run for a while. You can gather a lot of files rather quickly to play with :) Takes forever if you wait for the paperboy.

Mike

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/