Last active
December 29, 2018 08:27
-
-
Save bloatfan/a3f9c870687d0307087e302b49a4de62 to your computer and use it in GitHub Desktop.
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 | |
# https://www.linuxidc.com/Linux/2017-12/149752.htm | |
TRASH_DIR="/root/.trash" | |
basepath_array=( | |
/ | |
) | |
realpath_array=( | |
"/bin" | |
"/boot" | |
"/dev" | |
"/etc" | |
"/home" | |
"/lib" | |
"/lib64" | |
"/media" | |
"/lost+found" | |
"/mnt" | |
"/proc" | |
"/root" | |
"/run" | |
"/sbin" | |
"/snap" | |
"/srv" | |
"/sys" | |
"/tmp" | |
"/usr" | |
"/var" | |
) | |
for i in $* | |
do | |
STAMP=`date +"%Y-%m-%d-%H:%M:%S"` | |
fileName=`basename $i 2> /dev/null` | |
if [ ! "$?" = "0" ]; then | |
continue | |
fi | |
realpath=`realpath $i` | |
if [[ $realpath == $TRASH_DIR* ]]; then | |
`/bin/rm -R $i` | |
if [ "$?" = "0" ]; then | |
echo '( ' $i ' ) has been deleted!' | |
fi | |
continue | |
fi | |
for forbidden in ${basepath_array[@]} | |
do | |
if [ "$forbidden" = "$fileName" ]; then | |
echo $forbidden . " is forbiddened delete" | |
exit 2 | |
fi | |
done | |
for forbidden in ${realpath_array[@]} | |
do | |
if [ "$forbidden" = "$realpath" ]; then | |
echo $forbidden . " is forbiddened delete" | |
exit 2 | |
fi | |
done | |
mv $i $TRASH_DIR/$fileName.$STAMP | |
if [ "$?" = "0" ]; then | |
echo '( ' $i ' ) has been moved to ' $TRASH_DIR | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment