linux : how to configure recycle bin feature when I run shell command - $ rm -rf

we would like to configure our Linux servers in such that, if we accidentally  delete any files, those files  automatically move to some preconfigured directory.

example :  $ rm -rf file.txt

$ls -ltr   /recyclebin
output : file.txt

please advice the steps to customize the rm -rf command
mac_gAdmin - Oracle Fusion Middleware suiteAsked:
Who is Participating?
joolsConnect With a Mentor Commented:
I wouldnt modify the rm command or create an alias for it at all, it will lead to bad habits, if you rely on a recyclebin for the rm command and you go to a different server with it not set up you might have problems.

I was going to suggest creating a recycle command but andreas found a link to something suitable in his post above.
andreasConnect With a Mentor System AdminCommented:
There is no "built in" way of rm to achive this. you might use some shell scripts or software that does this.

You might look into this.
mac_gAdmin - Oracle Fusion Middleware suiteAuthor Commented:
any more inputs ?
Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

John PopeConnect With a Mentor IT ConsultantCommented:

Yes, for me too I have not seen a recycle bin implemented in a Unix system, rather a daily backup solution could possibly be an easier works for us; but of course you may have a slightly different need.

The 'rm' command could be aliased to move ('mv/mvdir') files to the /recyclebin file system and (as andreas alludes to) one could use a shell script to achieve this.

Cheers, JP.
Fadi SODAH (aka madunix)Connect With a Mentor Chief Information Security Officer, CISA, CISSP, CFR, ICATE, MCSE, CCNA, CCNP and CCIPCommented:
Unfortunately,It is not possible to configure recycle bin in Linux/Unix. As said above there is no reliable way to recover a deleted files in Linux/Unix . All the methods are just best effort. The best suggestion is to do regular BACKUP on the important files before it is deleted.
gheistConnect With a Mentor Commented:
alias rm="echo"
mac_gAdmin - Oracle Fusion Middleware suiteAuthor Commented:
i did not get u
gheistConnect With a Mentor Commented:
You cannot intercept system calls, but you can replace rm command with mv -d ~/Recycle
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.