SAFE-RM(1)

πŸ’– SAFE-RM(1) β€” bestie edition πŸ’–

User Contributed Perl Documentation ✨


✨ NAME ✨

safe-rm β€” it's a lil wrapper around the rm command so you stop deleting stuff you actually needed 🫢 no cap.


🌸 USAGE 🌸

safe-rm [ ... ] (same arguments as rm)

okay so literally, same arguments as rm. that's it. she's not complicated πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the vibe: safe-rm prevents the accidental deletion of important files by replacing rm with a wrapper. this wrapper checks the arguments you gave it against a configurable list of exclusions β€” files and directories that should never be removed. ever. periodt.

if you try to delete one of those protected files or directories? nope, you literally can't. instead you get a warning message. it's giving protective bestie energy fr fr 😭

safe-rm is meant to replace the rm command. the way you do that is by putting a symbolic link with the name rm in a directory that sits at the front of your path. like, for example, given this path:

PATH=/usr/local/bin:/bin:/usr/bin

you could create the following symbolic link:

ln -s /usr/local/bin/safe-rm /usr/local/bin/rm

and boom, slay, you're protected πŸ’–


πŸŽ€ CONFIGURATION πŸŽ€

protected paths can be set both at the site level and the user level. both. layers. iconic.

all of these configuration files can contain a list of important files or directories (one per line):

/etc/safe-rm.conf
/usr/local/etc/safe-rm.conf
~/.config/safe-rm

if all of these are empty, a default list of important paths will be used. so you're never out here unprotected, bestie 🫢

now this next part is the part everyone gets wrong, so listen up:

/usr/lib/*

will protect all of the files inside the /usr/lib directory if they are referred to directly, but it will not protect your system against:

rm -rf /usr/lib
⚠️ that's the sneaky one. the wildcard is not doing what you think it's doing. it's giving false sense of security πŸ’€

for full protection, you should include both of these lines:

/usr/lib
/usr/lib/*

two lines. both. that's the whole trick ✨


πŸ’œ EXIT STATUS πŸ’œ

same exit status as the real rm command. matching. consistent. we love a reliable queen πŸ‘‘

note that if all file arguments are skipped by safe-rm, then the exit status will be the same as the exit status of the real rm when no files arguments are present. iykyk 🌈


πŸ”₯ BUGS AND LIMITATIONS πŸ”₯

okay so this is where we get real, bestie. read carefully.

note that if you put the following in your protected paths list:

$ cat /etc/safe-rm.conf
/usr/lib

then safe-rm will prevent you from deleting the directory:

$ rm -rf /usr/lib
Skipping /usr/lib
/bin/rm: missing operand
Try `/bin/rm --help' for more information.

like, it literally says Skipping /usr/lib. she's doing her job πŸ’…

however β€” and this is the big however β€” it cannot protect you from the following:

$ cd /usr/lib
$ rm -f *
😭 yeah. once you cd in there and glob, the paths you're passing don't look like the protected paths anymore. the protection is about the paths you name, not the vibe of where you're standing. so... don't do that. fr fr.

🌟 AUTHOR 🌟

Francois Marier <francois@fmarier.org> πŸ‘‘


🌈 SEE ALSO 🌈


Copyright (C) 2008-2020 Francois Marier

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.


and that's the whole page, bestie 🫢 this one came from perl v5.30.3 and it's dated 2020-09-05 β€” stay safe out there and stop deleting /usr/lib πŸ’€βœ¨