Skip to content

Instantly share code, notes, and snippets.

@MiXaiLL76
Created September 2, 2021 14:16
Show Gist options
  • Save MiXaiLL76/7b8ce0179970eaab7e72d08910cd702a to your computer and use it in GitHub Desktop.
Save MiXaiLL76/7b8ce0179970eaab7e72d08910cd702a to your computer and use it in GitHub Desktop.
Safe replacement for rm -rf for gnome ubuntu
#!/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