So now is the time to look at the alias command and what a great friend this can be to us. Alias is a simple in itself with just the one option -p. So simple in fact it is not required: alias -p will print out your current aliases, but alias on its own will do this too.
Firstly we must understand what an alias is and why we need them. If we type ls at the command line in most Linux distributions we will not run the command ls directly but, usually, via and alias. Aliases exists in memory and are checked before files within the PATH variable. We can see this by typing the command:
The output will show, on most ditros that ls is aliased.
Here we can see that ls is aliased to:
This is great, as it means we can get the color listing of file types from ls without all that tiresome typing.
If we need to run ls temporarily without the alias, or the native ls command, we just preface it with the backslash, as such:
This way we run the command as Linus intended and no sacrifice of performance to color 🙂 If we would like to remove the alias from this session we can issue the command:
Or to remove all aliases:
This deletes the aliases from RAM until they are loaded again. this is normally in the login scripts, .bash_profile or .bashrc. If we want to create an alias for ourselves we can use the alias command to create aliases.
alias fd='find -maxdepth 1 -type d'
This alias, fd, would then run find listing directories only within our current directory. If wanted this to be permanent, and not just for the session, we would probably want to add it to the .bashrc file within our home folder. If for whatever reason we do not want to run aliases we can disable in the BASH shell using the command:
shopt -u expand_aliases
-u inset the option -m turns it on again. We can check the current state by running
shopt -p expand_aliases