What is a bash alias

Yakaranda


How to use bash aliases

Most users enjoy using shortcuts to execute commands. There are many commands in Ubuntu that we need to use on a regular basis. It is very helpful to us if we can execute these general commands by entering shortcut commands. Bash aliases make it easy for Ubuntu users to create shortcut commands of the large commands that are commonly used. Bash aliases not only make the task easier, they also save users' time. The user can declare aliases temporarily or permanently., The temporary aliases can be used as long as the user's session exists. If the user wants to use shortcut commands every time the session starts, they must create a permanent alias using ~ /.bashrc and ~ / .bash_profile files. How you can create and use bash aliases in Ubuntu is shown in this tutorial using a few examples.

Example-1: Temporary bash alias declaration

Declaring a temporary bash alias is a very simple task. alias command is used to create a shortcut to a command., For example, the ls -la command is a very commonly used command to display the list of all files and folders with permission. You can create the shortcut to this command using the alias command. For example, suppose the link command is L. Run the following commands to link ls-la and test the command.,

Check the output of the ls-ls command

Create alias command for ls-la

$ alias L = "ls la"

Test the association of ls-ls

After creating the alias, the output of the commands “L” and “ls-la” will be the same.

If the user closes the session and starts a new session again, the alias command will not work.,

Example-2: Permanent bash alias declaration

To solve the above problem, you can create a permanent alias command. For example, suppose you want to link the mkdir command to the alias “C” and use it permanently. Open ~ / .bashrc file in any editor, add alias command in this file, save the file and run command to run the file again with added alias command.

Open the file in the nano editor.

Add the alias command to the file and save it.,

alias C = "mkdir"

Re-run the file to make the command active.

Test the shortcut command from "mkdir"

Example-3: Remove bash alias

the unalias command is used to remove the previously created alias command. The alias stopped working after using this command, so if you think you no longer want the link command, you can use the alias command to permanently remove it.

Run the unalias command to remove previously created shortcut commands.

Check the command works or not.

Remove or uncomment the line that is used for creating alias command ~ / .bashrc file and run it again to delete the permanent alias.,

You can use the Alias ​​command to create a shortcut between the commands for a variety of purposes. This tutorial will help you understand the basic usage of the Alias ​​command so that you can easily apply this command to creating your frequently used commands. For more information, please see the video!

Articles