Operating System - HP-UX
1832960 Members
3097 Online
110048 Solutions
New Discussion

Re: Is there a way to remove a lot of directories at once w/out having to empty them first

 
mike worrell
Regular Advisor

Is there a way to remove a lot of directories at once w/out having to empty them first

Is there a way to remove a directory that has tons of directories beneath it with files in each directory? This would really help out our DBA if I could do it.
Any ideas of away to remove without having to go to each individual directory and remove the contents?

Your help is most appreciated.
Have a great day
Mike
11 REPLIES 11
James R. Ferguson
Acclaimed Contributor

Re: Is there a way to remove a lot of directories at once w/out having to empty them first

Hi Mike:

Yes.

# rm -rf /thedir

Be *very* careful using the '-f' (force) option. Make sure you know what you are doing and where you are!

Regards!

...JRF...
Brian Bergstrand
Honored Contributor

Re: Is there a way to remove a lot of directories at once w/out having to empty them first

rm -rf

This will recurse and delete all files and sub-directories.

HTH.
Pete Randall
Outstanding Contributor

Re: Is there a way to remove a lot of directories at once w/out having to empty them first

Mike,

If you can get a list of the directories, you could do something like this (as root, preferably):

for dir in `cat dir_list`
do
rm -rf dir
done


Pete


Pete
Robert-Jan Goossens
Honored Contributor

Re: Is there a way to remove a lot of directories at once w/out having to empty them first

Hi Mike,

# find /dir -exec rm -f {} \;

Robert-Jan.
sysadm_1
Valued Contributor

Re: Is there a way to remove a lot of directories at once w/out having to empty them first

Hi,

Try
rm -rf /directory
Shaji
ALPER ONEY
Advisor

Re: Is there a way to remove a lot of directories at once w/out having to empty them first

Hi Mike,
I think that the best solution is what some other experts also suggested above:
rm -Rf /thedir
Regards
ALPER ONEY
never ever give up.
mike worrell
Regular Advisor

Re: Is there a way to remove a lot of directories at once w/out having to empty them first

thanks to all, that got me going.
Geoff Wild
Honored Contributor

Re: Is there a way to remove a lot of directories at once w/out having to empty them first

Well....if those directories are the only ones in say the Logical Volume, you could just lvremove it - or re newfs it.

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Patrick Wallek
Honored Contributor

Re: Is there a way to remove a lot of directories at once w/out having to empty them first

Geoff,

That's kind of like curing a cold by chopping of your head isn't it? While that would work, it's a bit drastic. It would be MUCH faster than 'rm' would be though.
Geoff Wild
Honored Contributor

Re: Is there a way to remove a lot of directories at once w/out having to empty them first

Patrick,

Yes - it is drastic :)

Just on MC/SG II course - and we just did it to clear our vg's.

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Robert A. Pierce
Frequent Advisor

Re: Is there a way to remove a lot of directories at once w/out having to empty them first

An addendum:

You may want to add

`pwd`

and maybe

`ls -ld ./dir`

before

`rm -rf ./dir`

just to make sure you are where you think you are.

(A foaf tried to rm all files in a subdirectory, but ran into permission problems -- so he did `su - ` (instead of `su`) followed by `rm -rf *` -- ouch.)

Rob