Created
September 2, 2021 14:16
-
-
Save MiXaiLL76/7b8ce0179970eaab7e72d08910cd702a to your computer and use it in GitHub Desktop.
Safe replacement for rm -rf for gnome ubuntu
This file contains 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 | |
trash_dir=/home/rdl/.local/share/Trash | |
trash_files="${trash_dir}/files" | |
trash_info="${trash_dir}/info" | |
echo "Save remove files" | |
if [ $1 ]; then | |
if [ $1 == "--help" ]; then | |
echo "Usage: rm [path/filename]" | |
echo "Is a safer alternative to rm (remove), as Delete will send your file to the Trash dir." | |
else | |
for i in $@ | |
do | |
if [[ "${i}" != "-rf" ]] | |
then | |
filename=$(realpath "${i}") | |
parentdir=$(dirname "${filename}") | |
move_dir=$(echo "${trash_files}${parentdir}" | sed 's:/*$::') | |
echo "move file ${filename} to ${move_dir}" | |
mkdir -p -m777 ${move_dir} | |
mv ${filename} ${move_dir} | |
{ | |
echo "[Trash Info]" | |
echo "Path=${filename}" | |
echo "DeletionDate=$(date +'%Y-%m-%dT%H:%M:%S')" | |
} > ${trash_info}/$(basename ${filename}).trashinfo | |
fi | |
done | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment