Operating System - Linux
1819794 Members
3374 Online
109607 Solutions
New Discussion юеВ

How to remove files and directories recursively

 
SOLVED
Go to solution
Vernon Brown_4
Trusted Contributor

How to remove files and directories recursively

The man page for rm says the command rm -r should remove files recursively and that rm -d should remove directories. I'm a little embarrassed that I've never been able to get that to work.

I need to remove a user's home directory that contains fifty or so sub directories with a thousand or so files. What is the easiest way to do that ???

Vern

12 REPLIES 12
Mark Grant
Honored Contributor

Re: How to remove files and directories recursively

change directory to the directory above the user directory and go "rm -r user".

For example, if the user's home is "/home/mary" do

cd /home
rm -r mary
Never preceed any demonstration with anything more predictive than "watch this"
Umapathy S
Honored Contributor

Re: How to remove files and directories recursively

rm -rf will do. Check your permissions to do that.

Umapathy
Arise Awake and Stop NOT till the goal is Reached!
Vernon Brown_4
Trusted Contributor

Re: How to remove files and directories recursively

Thanks guys; I've been doing what you suggest. It doesn't work. rm -r comes back with

[root@linda /home]# rm -r vern
rm: descend into directory `vern'? y
rm: remove `vern/.bash_logout'? y
rm: remove `vern/.bash_profile'?

Surely there is a better way than to enter y return over a thousand times ??

Vern

Mark Grant
Honored Contributor
Solution

Re: How to remove files and directories recursively

Ahh, Red Hat for you!

try "rm -rf"
Never preceed any demonstration with anything more predictive than "watch this"
Mark Grant
Honored Contributor

Re: How to remove files and directories recursively

Actually Vernon, I just noticed that this is exactly what Umapathy said!

Apologies Umapathy.
Never preceed any demonstration with anything more predictive than "watch this"
Vernon Brown_4
Trusted Contributor

Re: How to remove files and directories recursively

rm -rf works !!!!

BTW I get a 404 file not found error when I try to submit points. Something is amiss but I see that the points were assigned :o)
Vernon Brown_4
Trusted Contributor

Re: How to remove files and directories recursively

Sorry Umpathy; I didn't see the -rf; short changed you 5 points; I'll try to make it up !

Vern
Seth Parker
Trusted Contributor

Re: How to remove files and directories recursively

Vern,

Just as an FYI, RedHat enables the -i (interactive) option on the rm command by default. That's why you got all the questions. The same thing will happen if you do an 'rm *' in a directory. You'll get prompted to delete each file.

Hehe, you either get used to it, or always put the -f in the command. It's safer to get used to it and only use -f when you're *really* sure!

Regards,
Seth
Mark Grant
Honored Contributor

Re: How to remove files and directories recursively

Alternatively, rather than get used to it (I never did. I don't like my unix commands behaving like MS/DOS commands) just use some alias that suits you.
Never preceed any demonstration with anything more predictive than "watch this"
dirk dierickx
Honored Contributor

Re: How to remove files and directories recursively

in fact the 'rm' command in redhat is just an alias that is set when root logs in. you can view them with the 'alias' command. you can change 'rm' into whatever you want so that it will not ask you confirmation every time.
Vernon Brown_4
Trusted Contributor

Re: How to remove files and directories recursively

Thanks; good to know this stuff. I had been going into directories I wanted to delete, changing the owner of each file to a regular user then deleting them with the wildcard.

I'm still getting the "404 File Not Found" error when I try to submit points in this forum. It is a stickey error message; only way I've found out of it is to log out then reconnect.

Vern
Mark Grant
Honored Contributor

Re: How to remove files and directories recursively

Vernon,

That 404 error is being worked on at the moment. What is happening is the page showing an aknowledgemnt for your point assignment is missing. The points are actually assigned and all is well with the world. You just need to "back" your browser a bit to get back to where you want to be.
Never preceed any demonstration with anything more predictive than "watch this"