• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

rm command to move to Trash folder instead?

I'm using Debian via CLI only. I have a headless server.

I didn't know debian had a trash folder, but I don't know much about debian. Nothinman can probably help you out. You could always make your own trash folder and alias rm to just move the file to your trash folder.
 
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.
 
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.

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.
 
Last edited:
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.

In crontab ('sudo crontab -e'), just put a script in there, named something like

@midnight /usr/local/bin/trashclean

and then have /usr/local/bin/trashclean be:

#!/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.
 
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 {} \;
 
find $directory -type f -mtime +7 -exec rm -f {} \;

#!/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" ] && find $trashes/* -type f -mtime +7 -exec rm -rf {} \;
done
 
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?

In the script, replace "rm $$$$" with "/bin/rm $$$$" if you have a conflict with aliases.
 
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?

I don't think cron jobs get your full environment so probably not, however I'd still recommend using full paths like PCTC2 says.
 
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?

No, cron jobs do not inherit the user environment. You would need to add anything like that specifically to the cron job.
 
Back
Top