Home Command line fun Type Linux Commands In Capital Letters To Run Them As Sudo User

Type Linux Commands In Capital Letters To Run Them As Sudo User

By sk
Published: Updated: 2K views

The reason I love Linux community a lot is they create so many FUN projects which you rarely find in any other propriety operating systems. A while ago, we looked at a fun project named "Hollywood" which turns the Terminal into a Hollywood technical melodrama hacker interface in Ubuntu-like systems. There are a few other utilities available, for example cowsay, fortune, sl and toilet(!) etc., to kill your free time and keep you entertained! They may not be useful, but these utilities are really entertaining and fun to use. Today, I stumbled upon yet another similar utility named "SUDO". As the name implies, whenever you type Linux commands in capital letters, the SUDO utility will run them as sudo user! Meaning, you need not to type "sudo" in-front of the Linux commands you about to run. Cool, yeah?

Install SUDO in Linux


A word of caution:

Before installing this (or any utility), take a look at the source code (Link given at the end) and see if there are suspicious/malicious code included to harm your system. Test it in a VM. If you like or found it useful, you can use it in your personal/production systems.


Git clone the SUDO repository:

$ git clone https://github.com/jthistle/SUDO.git

This command will clone the contents of SUDO GIT repository and saves them in a directory named "SUDO" in your current working directory.

Cloning into 'SUDO'...
remote: Enumerating objects: 42, done.
remote: Counting objects: 100% (42/42), done.
remote: Compressing objects: 100% (29/29), done.
remote: Total 42 (delta 17), reused 30 (delta 12), pack-reused 0
Unpacking objects: 100% (42/42), done.

Switch to SUDO directory:

$ cd SUDO/

And, install it using command:

$ ./install.sh

The command will add the following entries in your ~/.bashrc file:

[...]
# SUDO - shout at bash to su commands
# Distributed under GNU GPLv2, @jthistle on github

shopt -s expand_aliases

IFS_=${IFS}
IFS=":" read -ra PATHS <<< "$PATH"

for i in "${PATHS[@]}"; do
    for j in $( ls "$i" ); do
        if [ ${j^^} != $j ] && [ $j != "sudo" ]; then
            alias ${j^^}="sudo $j"
        fi      
    done
done

alias SUDO='sudo $(history -p !!)'

IFS=${IFS_}

# end SUDO

It will also take a backup of your ~/.bashrc and save it as ~/.bashrc.old. You can restore it if anything goes catastrophically wrong.

Finally, update the changes using command:

$ source ~/.bashrc

Type Linux Commands in Capital letters to run them as Sudo user

Usually, we execute Linux commands that requires sudo/root privileges like below.

$ sudo mkdir /ostechnix

Right? Yes! The above command will create directory named "ostechnix" in root (/). Let us cancel this command using Ctrl+c.

Once SUDO is installed, you can type any Linux command in capital without sudo and run them. So, you can run the above command like below:

$ MKDIR /ostechnix
$ TOUCH /ostechnix/test.txt
$ LS /ostechnix
Type Linux Commands In Capital Letters To Run Them As Sudo User

Type Linux Commands In Capital Letters To Run Them As Sudo User

Please note that it will not bypass the sudo password. You still need to type sudo password to execute the given command. It will only help to avoid typing "sudo" in-front of each command.


Related read:


Of course, typing "sudo" will take only a few seconds, so it is not a big deal. I must tell this is just fun and USELESS project to pass time. If you don't like it, go away and learn something useful. If you like it, give it a go and have fun!

Resource:

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

9 comments

Will July 12, 2019 - 1:59 am

uh. wow. who’d’ve thunk it? Not sure I like it, but it’s creative

Reply
Matti July 12, 2019 - 9:52 am

Thanks for the tip!
I’m just curious how this might be better than running the “sudo su” command to escalate your privileges.

Reply
Steve July 12, 2019 - 12:29 pm

A common issue for me is typing a full command, then realising i need sudo. If there was a keystroke i could enter to “add sudo” or upcase my line then this would be awesome

Reply
Marcos July 12, 2019 - 3:37 pm

You might find useful that you can run the command without sudo and after it fails type “`sudo !!“` it’ll run the last command and prepend the sudo.

Reply
sk July 12, 2019 - 3:38 pm

Good tip. Thanks.

Reply
Jesse McDonald July 12, 2019 - 11:36 pm

You can customize input handling in bash by editing ~/.inputrc, including macros like “on Alt-Enter go to the beginning of the line, insert some text, and then run the command”.

Reply
Jim July 13, 2019 - 6:16 am

Try: sudo !!
This will run the last command again

Reply
Tony July 13, 2019 - 10:22 am

Steve, I normally press the up arrow, the. Ctrl+A to go to the beginning of the line. Then type sudo and space and press enter. That was the quickest way I found but I see a comment from Marcos that says just type sudo and press enter and it will run the last command with sudo. I’m on vacation now but looking forward to trying that ? thanks Marcos

Reply
Josh July 22, 2019 - 3:50 am

If you’ve already run the command, then just use “sudo !!” to rerun the last command with sudo in front, otherwise if you haven’t run it yet, try Ctrl+A to get you to the beginning of the line and then you can add sudo yourself

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More