18. alias and unalias - muneeb-mbytes/linux_course GitHub Wiki

alias and unalias

alias

In Linux, an alias is a shortcut that references a command. An alias replaces a string that invokes a command in the Linux shell with another user-defined string. Aliases are mostly used to replace long commands, improving efficiency and avoiding potential spelling errors.

Syntax: alias [alias_name] "[name]"

alias: Invokes the alias command.
[alias_name]: Defines the new shortcut that references a command.
[name]: Specifies the command the alias references.

Example: alias la "ls -la"

Here the alias command to create a temporary alias that lasts until the end of the current terminal session. For instance, creating la as an alias for ls -la.

The below figure shows the output of alias la "ls -la".

ls-laalias

                              Figure.1. Output of alias command

The below GIF shows the whole process from sourcing scripting file to till the output.

ls-laalias

                                    GIF.1. alias output GIF  

Link to GitHub lab: https://github.com/muneeb-mbytes/linux_course/blob/b7_team_kachori/alias_command/alias_command.csh


unalias

To remove an alias, use the unalias command as shown below,

Syntax: unalias [alias_name]

Example: unalias la

unalias: Invoke unalias command
[alias_name]: shortcut given while doing alias

Here unalias command removes the created alias.

The below figure displays the Output of unalias command, where the created alias la "ls -la" will be removed. The removal of alias can be verified by using which la command and it will display command not found.

unaliasls-la

                                   Figure.2. Output of unalias command

The below GIF shows the whole process of sourcing the scripting file till the output, here initially alias is created for ls -la as la and the creation of alias is checked by giving which la and to remove alias, the command - unalias la, is used. Then to verify the removal of alias, again we can use which la.

ls-launalias

                                          GIF.2. unalias gif output

Link to GitHub lab: https://github.com/muneeb-mbytes/linux_course/blob/b7_team_kachori/alias_command/unalias_command.csh


To learn environment variables: https://github.com/muneeb-mbytes/linux_course/wiki/19.-Environmental-variables