Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 05-22-2007, 05:11 AM   #1
LQ Newbie
Registered: Mar 2006
Posts: 12

Rep: Reputation: 0
What's a safer alternative to rm -rf

When I want to delete a directory and everything in it, I usually use rm -rf

However, I have heard that that is a bad habit to get into, and I agree. If you make a mistake, you could delete your entire partition.

Is there a safer way to delete a directory and all its subdirectories and files? What's a "best practice"?
Old 05-22-2007, 05:26 AM   #2
Senior Member
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
For a start, if you drop the 'f' then at least it won't go blindly ahead and delete everything regardless of permissions etc. You can also use the -i option which prompts you for confirmation.

Deleting stuff from KDE/Gnome usually moves the file to ~/.Trash, so if you delete from a GUI rather than CLI, then you've got that safety net.

People have talked about how you could set up an alias/write a little script which replaces the rm command with a safer mv command which shifts the files to ~/.Trash, whereafter you could delete them from the trash icon on your desktop. Others warn of caution when using this approach as when you go to a new machine and start rm'ing stuff left right and centre without thinking, then you can do bad things very quickly. A compromise might be to setup the alias/script to be called safedelete (or something shorter!), that way you won't get into a bad habit.
Old 05-22-2007, 05:43 AM   #3
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,950

Rep: Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210
I'm one who thinks of it as a "learning opportunity".
You generally only do it (at most) once.
If it's (system) critical, on my systems you'd lose your access rights - simple as that.

Good backups help.



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

Similar Threads
Thread Thread Starter Forum Replies Last Post
knoppix is safer? telzey Linux - Security 2 03-14-2006 04:29 AM
safer alternative then rm -rf to remove non-empty directory? taiwf Linux - General 9 01-17-2006 09:24 PM
safer than S** mifan Linux - Newbie 7 05-29-2005 12:49 PM
how is linux safer than windows? learnfast Linux - Newbie 3 03-10-2005 11:01 AM
Can anyone help me make my computer safer please? packman Linux - General 1 10-26-2002 11:17 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:32 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration