-2

Default command is:

sudo apt-get update

I want to replace command (sudo) with the user name. For eg:

username apt-get update
karan
  • 1

1 Answers1

-5

Use alias username="sudo" from the terminal to change it temporarily.

For a permanent alteration, add the same text to ~/.bashrc. You can use:

vi ~/.bashrc

Or:

nano ~/.bashrc

to do this. If you try the vi route you will need to press i before entering the text, followed by the escape key, followed by :wq to save the file. If this doesn't work you probably need to update your version of vim, which you can do with this command:

sudo apt-get install vim

If, on the other hand you want to change sudo contextually, so you instead just type in the name of the currently logged in user, try creating a "usernames.sh" file with this command:

vi usernames.sh

Or:

sudo vi usernames.sh

Depending on where you are creating it. Then enter this text:

#!/bin/bash

shopt -s expand_aliases
alias $USER="sudo"

Make it executable using chmod +x usernames.sh then run this command:

./usernames.sh

To make it run every time you start the computer, type:

cp usernames.sh /etc/init.d

Followed by:

update-rc.d usernames.sh defaults

Again let me know if this works and if it's what you had in mind since, as I said, I do not have access to an Ubuntu terminal at the present time to test. If there are problems they can be fixed if I am made aware of them.