Reputation: 795
In my production server, somebody executed rm -rf
and my important files are removed permanently. So, I thought of having a recycle bin, so if a user do rm
the file will move to RecycleBin rather than deleting from server. And i've made the below script for it. But I'm getting some error while it executed.
alias rm='/root/remove.sh'
#rm test_file
Now below script will trigger when you type the rm
command
#!/bin/bash
dir=$(pwd)
mv $dir/$1 /root/Recyclebin
when the above script is triggered i'm getting the following error.
mv:cannot move '/root/test_file' to '/root/Recyclebin': Not a directory
Now, please suggest is there anyother way to make a recycle bin concept other than this or please help to resolve the error. Thanks in advance.
I'm using CentOS 5.6
Upvotes: 3
Views: 4617
Reputation: 151
Try This At first create a folder named as MyTrash under /root ie: /root/MyTrash
Then open .bashrc file and write the below line at the bottom of the file.
alias rm='mv -t /root/MyTrash/'
Here -t
means
-t, --target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY
update .bashrc
file by running this command source .bashrc
Now if you delete any file using rm
command that file will be moved to /root/MyTrash
directory
Upvotes: 5