The alias command to me is the most powerful command in the Linux system. From saving you time by substituting complex commands, to not so funny pranks the alias command lives up to the Unix philosophy of doing one thing and doing it well.
Perhaps you would like to slightly alter the definition of a command, or maybe you always want to use a particular option on a command. The alias command enables the replacement of any command by another string.
To create an alias, the user supplies name/value pairs as arguments for the alias command.
When the command
h is read in the shell, it will be substituted with
ls $HOME and that command will be executed. The substitution occurs very early in the cli processing, so all other variables will be evaluated after.
To view all applied aliases , just type in the command
If you don’t like what your alias does and want to get rid of it, just use
unalias and the name of the alias that you no longer want. For example:
To use alias on my system, I firstly make them permanent by creating
Secondly I add the following code to the
~/.bashrc file :
remember to reload your shell to load the changes you made to
.bashrc, you can do this with the following command:
All thats left is to then come up with memorable aliases for long and complex commands I use often.
Here is a list of aliases currently configured I my system.
Shorten searching commands on history.
Left provides a convenient way of checking which files you worked on last.
If you use python for development you will definitely relate to the neck breaking work of typing python3 each time you want to run a python script.
A handy way of showing todays date.
Updates on linux (unlike other systems) are a regular thing , you can easily make work easier:
When using sudo, use alias expansion (otherwise sudo ignores your aliases)
Bash only checks the first word of a command for an alias, any words after that are not checked. Note the trailing space after the value sudo.
I find cat awkward to use, I find pr more intuitive and memorable.
I use jekyll for my blog and shortening regular commands saves me a lot of time
You can also make not so safe commands unavailable
Whether you are a system administrator, a programmer, or an end user, there are certainly occasions where a simple (or perhaps not so simple) shell hacking can save you time and effort, or facilitate consistency and repeatability for some important task.
Even using an alias to change or shorten the name of a command you use often can have a significant effect.
You can find out more on alias and other commands on these resources: