DEV Community

Hans
Hans

Posted on • Edited on

Make aliases in ubuntu

Easiest way to make aliases of often used commands is to open file manager and then hit ctrl-h to show the hidden files. Open the .bashrc file and scroll down to the bottom of the file

The syntax is: alias='commands'

For example you can combine these two commands with a simple alias

alias ago='sudo apt-get update && sudo apt-get upgrade'

Now save the file, open a terminal window and hit 'ago'

I like to hit 'ls' everytime I cd into a folder just to get a view of the newly entered folder so therefore i like to combine the cd command with a ls. However, this kind of command needs a function as opposed to an alias

Type:

function cd {
builtin cd "$@" && ls
}

hit save and open up a new terminal window and test it

Top comments (2)

Collapse
 
jmscharff2 profile image
Jon

When you have a terminal open already you can type source ~/.bashrc and it will recompile your bashrc file and you don't have to open and close the terminal. Helpful if you are using nano/vim/emacs to edit the bashrc file

Collapse
 
siscia_ profile image
Simone Mosciatti

If you work in linux long enough, eventually you will find also . file.sh (a dot and then a shell file) which is basically the same of source file.sh :)