08-28-2020, 07:51 AM
In Linux systems there's a command called "rm" which mainly used for deleting file and directories. So why we need to disable or block the "rm" command? Because if someone by mistakenly run the "rm" command then we lose our data and there's nothing to recall if you don't have backup then you lose your data.
So for that reason we need to block or disable the "rm" command. Sadly there's no option to do this but we create an alias for "rm" command and can change the behavior of the command. We simply create a folder called "/trash" it works like windows Recycle Bin. That means if we run "rm" command then our data will move to "/trash" so it will helpful for us in future.
mkdir /trash ## For create a directory
chmod 777 /trash ##To assign full permission
After That we need to create an alias for "rm" command to do that follow the steps:
sudo su ##Login using Root account
vim /etc/bashrc ## Just add the function at the end of the file
function rm {
mv $@ /trash
}
source /etc/bashrc ## For update the file
then run 'rm' command it won't delete your data it will move the data from source to "/trash" directory.
So for that reason we need to block or disable the "rm" command. Sadly there's no option to do this but we create an alias for "rm" command and can change the behavior of the command. We simply create a folder called "/trash" it works like windows Recycle Bin. That means if we run "rm" command then our data will move to "/trash" so it will helpful for us in future.
mkdir /trash ## For create a directory
chmod 777 /trash ##To assign full permission
After That we need to create an alias for "rm" command to do that follow the steps:
sudo su ##Login using Root account
vim /etc/bashrc ## Just add the function at the end of the file
function rm {
mv $@ /trash
}
source /etc/bashrc ## For update the file
then run 'rm' command it won't delete your data it will move the data from source to "/trash" directory.