Jump to content

How To Use alias Command in Linux


Linux Hint

Recommended Posts

In Linux, commands help you achieve tasks like troubleshooting network issues, executing scripts, organizing system structure, and more. Moreover, some situations require you to run lengthy commands repeatedly, and typing them consumes much of your time. In this case, the alias command is the savior, creating shortcuts for long commands or a sequence of commands. It also improves productivity and reduces errors.

However, many users and even Linux experts have yet to learn how to use the alias command correctly. So, this short tutorial will quickly explain how to use the alias command in Linux without any hassles.

The alias Command with Examples

The alias command is simple, and you can use it as:

alias alias_name='command'

creating-alias-for-update-command-in-linux

Please replace the ‘alias_name’ and ‘command’ with the name of the alias and the target command, respectively. In simple words, alias means the shortcut command you want to create. For instance, you can create the following alias if you frequently use the ‘sudo apt update && upgrade’ command to update the system:

alias update='sudo apt update && upgrade'

Now, whenever you type and run ‘update’ in the terminal, the system will automatically start updating:

alias-command-example

The above aliases last only for the current terminal session. However, if you want to make a persisting alias, add it to your shell’s configuration file. Typically, for Bash, it is the ‘.bashrc’ file. Let’s retake the above example to convert ‘update’ to a permanent alias. First, you have to open the configuration file with a text editor:

nano ~/.bashrc

After that, add the aliases in the following manner:

alias update='sudo apt update && upgrade'

sudo-update-upgrade-command-in-alias

Finally, save the file and run the ‘source ~/.bashrc’ command to apply the changes.

sudo-update-upgrade-command-in-linux

A Quick Wrap-up

The alias command in Linux empowers a user to customize the command line experience and enhance productivity. By creating personalized shortcuts, you can easily streamline your workflow and navigate your system. Here, we discussed the method to create temporary and permanent aliases. Furthermore, remember all the mentioned tips to maintain clarity and efficiency.

View the full article

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...