Creating a Backup Copy Automatically When Removing a File
When we remove a file it is generally gone for good:
Code:
rm fileName Code:
rm -i fileName |
use mv instead
make a directory to put the files your not sure you want to permanently delete with mkdir "mkdir ~/trash" then use mv to move them in to ~/trash Read the Fine Manual page "man mv" |
You could also create a script which replaces or renames "rm" which makes a backup copy of your files for you and then deletes the original file at the same time. You need to make sure that the new "rm" command comes before the original "rm" command in your PATH variable so that the new command is used before the original "rm" command.
|
Perhaps an alias or function for rm in your bashrc that first makes a copy of the file somewhere and then deletes it.
eg: rm1 () { cp $1 ~/backup rm $1 } |
Creating a Function in .bashrc
Quote:
First, I forgot to update my question that I had tried using an alias in the .bashrc file and created a script which is called when rm is executed. It would create a Code:
.gz Anyways, the idea of putting a function is the .bashrc is really much better and efficient. So, I just experimented with it: Code:
[DEV@mahadeva ~]$ cat .bashrc Code:
[DEV@mahadeva ~]$ . .bashrc Code:
[DEV@mahadeva ~]$ cal > test Thanks Gurus! ;) |
All times are GMT -5. The time now is 05:27 PM. |