-
-
Save nellaivijay/2662170 to your computer and use it in GitHub Desktop.
Safe Remove
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
sleep 2 | |
args=( $@ ) | |
preserve_paths=( / /bin /boot /dev /etc /home /initrd /lib /proc /root /sbin /sys /usr /usr/bin /usr/include /usr/lib /usr/local /usr/local/bin /usr/local/include /usr/local/sbin /usr/local/share /usr/sbin /usr/share /usr/src /var /opt ) | |
preserve_keywords=( bin boot dev etc home initrd lib proc root sbin sys usr include local share src opt var ) | |
for path in "${preserve_paths[@]}" | |
do | |
for arg in "${args[@]}" | |
do | |
if [[ $arg = $path ]]; | |
then | |
echo "I refuse to delete: $path" | |
echo "It seems too important. If you want to do it anyway, use /bin/rm" | |
exit 100 | |
fi | |
done | |
done | |
counter=0 | |
matches=() | |
for keyword in "${preserve_keywords[@]}" | |
do | |
for arg in "${args[@]}" | |
do | |
if [[ $arg = $keyword ]]; | |
then | |
counter=$(($counter + 1)) | |
matches=( ${matches[@]} $keyword ) | |
fi | |
if [[ $counter -gt 1 ]]; | |
then | |
echo "I refuse to delete: ${matches[@]}" | |
echo "They seem too important. If you want to do it anyway, use /bin/rm" | |
exit 100 | |
fi | |
done | |
done | |
/bin/rm "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment