I would like to create an alias of the below command with sudo like below.
alias /usr/bin/vmstat='sudo /usr/bin/vmstat'
is it possible to create something like that for a user?
I would like to create an alias of the below command with sudo like below.
alias /usr/bin/vmstat='sudo /usr/bin/vmstat'
is it possible to create something like that for a user?
In Bash, an alias is just a name, but not a path (since aliases are stored in memory).
Here are some examples from my own system:
alias cte='crontab -e'
alias scte='sudo crontab -e'
# if I wanted a separate alias for 'sudo htop' I would have called the following alias shtop
alias htop='sudo htop'
In your example, for Bash you would need to do:
alias vmstat='sudo /usr/bin/vmstat'
Then the vmstat
command would run with sudo
by default.
You just need to decide which alias name you want to allocate to which command - with or without sudo
.
man vmstat
vmstat does not require special permissions – steeldriver Sep 07 '23 at 16:01