VinylxScratches
Golden Member
I recall learning how to do this in a *nix course but I can't figure it out now. Does anyone know?
I recall learning how to do this in a *nix course but I can't figure it out now. Does anyone know?
I'm using Debian via CLI only. I have a headless server.
Well. I beleive Gnome has a trashfolder but through CLI, rm just removes the file.... I want it to instead do a mv FILENAME /trash_can/FILENAME or something... I recall doing it in the course, I'm gonna have to look through my notes.
Something like 'alias rm='mv -t ~/home/.trash/ ' in ~./bash_aliases should work.
Yes, that's exactly what I suggested.
You might want a cron job that periodically empties your trash folder. Another solution would be to use a copy on write snapshot, as long as you're using logical volumes.
@midnight /usr/local/bin/trashclean
#!/bin/bash
if [[ "$UID" != "0" ];then
exit 1
fi
#This finds the trash folders in home folders and deletes them
trash="$(find "/home" -name .trash -type d)"
for trashes in "$trash"; do
[ -x "$trashes" ] && rm -rf $trashes/*
done
and then have /usr/local/bin/trashclean be:
You might want to add some age check too, so it only empties files more than, for example, 7 days old. It would take me a while figure out the scipting in Bash, I switch to Ruby once it gets that complicated.
find $directory -type f -mtime +7 -exec rm -f {} \;
Any issues with aliasing rm to not actually rm anything anymore, and then writing a cronjob that does an rm? Does the cron job pick up your aliases if you're the one running it?
Any issues with aliasing rm to not actually rm anything anymore, and then writing a cronjob that does an rm? Does the cron job pick up your aliases if you're the one running it?
find $directory -type f -mtime +7 -exec rm -f {} \;
Any issues with aliasing rm to not actually rm anything anymore, and then writing a cronjob that does an rm? Does the cron job pick up your aliases if you're the one running it?
Except that may still delete the file placed in the trash folder the same day it was moved there because the mv command maintains the files modified time from its previous location.