I want to configure rm
command. When one types rm
to delete a file, then instead of deleting it right away, the file has to be transferred to the .trash of home folder. Can someone help me ?
migrated from serverfault.com Nov 1 '12 at 10:26
A quick solution is to add the following function declaration to your
Caveats:
Just my 5 cents - use instead:
|
|||
|
On Debian, something like 'alias rm='mv -t ~/home/.trash/ ' in ~./bash_aliases should work. However, it isn't a good practice to alias rm to mv as it might affect the other users who try to delete permanently using rm. Furthermore, if you go down the aliasing route, you might have to set up a cron job to periodically empty trash. There're a bunch of alternatives given here - mostly 3rd party tools/scripts. Hope this helps... |
|||
|
You can use LD_PRELOAD with libtrash. See: http://www.techrepublic.com/article/safely-delete-linux-files-with-libtrash/5034918 You can also create hard links to your files in ~/.trash folder. When normal files (that were previously hardlinked) gets deleted, they will remain on the disk until you delete them from the "trash". To create a hard link:
|
|||
|
Keep in mind, that it's not a good idea to actually rename or move your "rm" command. A much better practice is to in your .bash_profile (assuming you're using bash as your default shell)
and then you can create the script
This is untested, but should work for your needs. There are a few caveats that should be addressed... but it's up to you to decide how it should be handled. i.e. what happens when you delete a file, create a new one with the same name and then delete it? and this script will not clean up your trash-can. Perhaps a cron-job once a week or some such? This will NOT override a script that calls |
|||
|
rm
withmv
. Without using aliasing, I would do it by taking the source forrm
from CoreUtils and modifying it into a new package that implements the required functionality. – darnir Nov 1 '12 at 10:50