LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 05-22-2007, 05:11 AM   #1
dggoldst
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
pwc101
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
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,483

Rep: Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077
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.
 
  


Reply

Tags
commandline


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


All times are GMT -5. The time now is 07:53 PM.

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