How to modify rm command ?
Dear Friends,
When we execute rm command then the target files or directories are permanently removed from our computer. Is there any way my which when we execute rm command then the files or directories moved to Trash. please help me, its very important for me. Thanks in advance |
Hi,
You can create a script rm.sh (and put it for example in /usr/bin): Code:
#!/bin/sh Code:
alias rm='/usr/bin/rm.sh' |
Following the suggestion by bathory, you may want to be able to move more files at once (for example when using wildcards). In this case better to use $@ to catch all the command line arguments:
Code:
mv "$@" ~/.Trash |
Sometimes that's not a good idea though since there are some system scripts like boot scripts that may also use the rm command to permanently delete files like temporary files. It's probably better to create another similar script utility with different filename like /usr/bin/trash.
|
Quote:
|
Moved: This thread is more suitable in Linux-Newbie and has been moved accordingly to help your thread/question get the exposure it deserves.
|
Quote:
|
Quote:
|
thanks for your questions, but I am quite confuse.
Please provide a viable solution to do this. |
sorry for spelling mistake
thanks for your answers, but I am quite confuse. Please provide a viable solution to do this. |
Solution is in posts #2 and #3. Put the alias in your .bash_profile
1. Create the command /usr/bin/rm.sh as follow (as root): Code:
cat >/usr/bin/rm.sh <<EOF Code:
echo "alias rm='/usr/bin/rm.sh'" >> ~/.bash_profile |
Quote:
Also I suggest that it's better to have functions instead of aliases since sometimes aliases do not work the way they should be. Perhaps at least on the earlier versions of bash? Edit: Oh I forgot. Yeah right. Functions and aliases are not exported so this can be safely done. |
Quote:
|
Quote:
Edit: Or maybe you meant a different angle.. well ok. Actually we don't even have to think about it since sometimes .bashrc is not also called. What really mattered was the effect after a new virtual version of rm is created. |
All times are GMT -5. The time now is 11:34 PM. |