by mmh0000 · 4y ago · 0 comments
function rm {
for file in $@; do
mv -t ~/.local/share/Trash/files/ -- "${file}"
cat <<FROG > ~/.local/share/Trash/info/"$(basename ${file})".trashinfo
[Trash Info]
Path=$(realpath "${file}")
DeletionDate=$(date "+%FT%T")
FROG
done
}What kind of ancient environment is it without a trash capability? That's pre Windows 95. How are people handling the mistake of "rm *" in a wrong folder?
Added benefit of trash-put is, you don't need "-r" to delete a folder. It's just an annoyance from user's perspective.
If you think there's a compatibility problem in a script, just use /bin/rm and stop wasting time pulling hairs on unrecoverable deletion.
"@daily trash-empty 30"
Put this in cron to purge trashes older than 30 days daily.
It is written in a compiled language and appears to be faster on my old computer.
In Bash that didn't work on files with spaces or funky characters. But, I never noticed because in Zsh, my primary shell, it works fine with all filenames.
Here's an updated one which incorperates the advice from several posts to also work in Bash:
function rm {
for file; do
mv -t ~/.local/share/Trash/files/ -- "${file}"
cat << FROG > ~/.local/share/Trash/info/"$(basename
"${file}")".trashinfo
[Trash Info]
Path=$(realpath "${file}")
DeletionDate=$(date "+%FT%T")
FROG
done
}At least with bash.