I want to make the command shell to prompt me for confirmation before execution of certain commands like
rm -rf etc.
You can create a bash script that ask confirmation and then run the desidered program. Create a file named ask containing:
#!/bin/bash echo "Are you sure to run $1 command?" read RES if [ "$RES" = "Y" ] || [ "$RES" = "y" ] ; then echo "Running the command..." $@ else echo "Command aborted" fi
Copy ask script in /usr/bin/ and set it as executable (or add the script path tho PATH variable):
sudo mv path_to_ask_script/ask /usr/bin/ask cd /usr/bin/ sudo chmod 777 ask
Then you have to create an alias in the
alias dd='ask dd'
Now by typing dd, the ask script should be executed, ask for confirmation and eventually call the dd command.
To extend to other command just add an alias like:
alias command_name='ask command_name'
alias rm='ask rm'
For the rm command you can simply create an alias as:
alias rm='rm -i'
Script tried and fully working on 16.04 with gnome-terminal
You can do the following if you really want to use those commands only as sudo:
/bin(example, most commands are here) so:
cd /bin # example how to make dd to posibly only for root/sudo (744) sudo chmod go-x dd # or even go further restrict the access to the file fully to root (700) sudo chmod go-rx dd # to reverse that setting you did do (755) sudo chmod go+rx dd
This removes the executable flags from those commands for group and other. You can do that with almost all commands and it till tell you have no permission when not using sudo.
Disclaimer: Do not, I mean it, DO NOT change permissions on sudo or su you might lock you out of essential stuff and wwould have a hard time fixing.