I am trying to create an alias for the rm command in the /root/.bashrc file on a VirtualBox Redhat VM (running RHEL 9). I cannot get it to work properly. This is an excerpt of my .bashrc file:
alias rm='printf "rm: cannot remove %s: Permission denied\n" "$@" && w >> /tmp/logfile_20090204_001.log'
sudo() {
if [[ "$1" == "rm" ]]; then
for file in "${@:2}"; do
printf "rm: cannot remove %s: Permission denied\n" "$file"
done
w >> /tmp/logfile_20190204_002.log
else
command sudo "$@"
fi
}
I reload it with . /root/.bashrc
. The result I get when using rm
is : cannot remove : Permission denied
(no file name). I have tried replacing printf with echo, switching the single and double quotes and modifying the bash_aliases file instead of the .bashrc file, and nothing seems to work. How can I get this alias to print my file name (with and without sudo)?
Thank you in advance for your help!
Asked by minionsaregreat
(3 rep)
Jul 10, 2025, 12:42 PM
Last activity: Jul 10, 2025, 01:02 PM
Last activity: Jul 10, 2025, 01:02 PM