Safe substitute for OS X `rm`?
For OSX, you can use safe-rm
brew install safe-rm
You need to do an extra step to prefer it over default rm
- add a symlink.
echo $PATH
For me, I have /usr/local/bin:
first, the same dir as safe-rm
install
Add symlink to safe-rm
ln -s /usr/local/bin/safe-rm /usr/local/bin/rm
To remove and restore the default rm
you can remove the symlink rm /usr/local/bin/rm
The config file can be added at /etc/safe-rm.conf
e.g:
/private
/Applications
/Developer
/Library
/Network
/System
/Users
/Volumes
/test
Test with rm -rf /test
it will deny delete from safe-rm.conf
hasseg.org/trash is an Objective-C utility like osx-trash.
I've written a shell function that doesn't overwrite files like mv * ~/.Trash
would. It always moves items to the startup volume though.
trash() {
for f in "$@"; do
bn=$(basename "$f")
while [ -e ~/.Trash/"$bn" ]; do
bn="$bn $(date +%H.%M.%S %p)"
done
mv "$f" ~/.Trash/"$bn"
done
}