| 1 | # safe-rm |
| 2 | |
| 3 | prevention of accidental deletions by excluding important directories |
| 4 | |
| 5 | Copyright (C) 2008-2021 Francois Marier <[email protected]> |
| 6 | |
| 7 | This program is free software: you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation, either version 3 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 | |
| 20 | ## How to use |
| 21 | |
| 22 | Once you have installed safe-rm on your system (see `INSTALL`), you will need to |
| 23 | fill the system-wide or user-specific exclusions with the paths that you'd like |
| 24 | to protect against accidental deletion. |
| 25 | |
| 26 | The system-wide exclusions live in `/etc/safe-rm.conf` (or `/usr/local/etc/safe-rm.conf`) |
| 27 | and you should probably add paths like these: |
| 28 | |
| 29 | / |
| 30 | /etc |
| 31 | /usr |
| 32 | /usr/lib |
| 33 | /var |
| 34 | |
| 35 | The user-specific exclusions live in ~/.config/safe-rm and could include things like: |
| 36 | |
| 37 | /home/username/documents |
| 38 | /home/username/documents/* |
| 39 | /home/username/.mozilla |
| 40 | |
| 41 | ## Other approaches |
| 42 | |
| 43 | If you want more protection than what safe-rm can offer, here are a few suggestions. |
| 44 | |
| 45 | You could of couse request confirmation everytime you delete a file by putting this in |
| 46 | your /etc/bash.bashrc: |
| 47 | |
| 48 | alias rm='rm -i' |
| 49 | |
| 50 | But this won't protect you from getting used to always saying yes, or from accidently |
| 51 | using 'rm -rf'. |
| 52 | |
| 53 | Or you could make use of the Linux filesystem "immutable" attribute by marking (as root) |
| 54 | each file you want to protect: |
| 55 | |
| 56 | chattr +i file |
| 57 | |
| 58 | Of course this is only usable on filesystems which support this feature. |
| 59 | |
| 60 | Here are two projects which allow you to recover recently deleted files by trapping |
| 61 | all unlink(), rename() and open() system calls through the LD_PRELOAD facility: |
| 62 | |
| 63 | * [delsafe](https://web.archive.org/web/20081027033142/http://homepage.esoterica.pt:80/~nx0yew/delsafe/) |
| 64 | * [libtrashcan](http://hpux.connect.org.uk/hppd/hpux/Development/Libraries/libtrash-0.2/readme.html) |
| 65 | |
| 66 | There are also projects which implement the FreeDesktop.org trashcan spec. For example: |
| 67 | |
| 68 | * [trash-cli](https://github.com/andreafrancia/trash-cli) |
| 69 | |
| 70 | Finally, this project is a fork of GNU coreutils and adds features similar to safe-rm |
| 71 | to the rm command directly: |
| 72 | |
| 73 | * [rmfd](https://github.com/d5h/rmfd) |