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"?
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.
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.
|All times are GMT -5. The time now is 04:35 PM.|