How to create a permanent Bash alias on Linux/Unix

htt‮www//:sp‬.lautturi.com
How to create a permanent Bash alias on Linux/Unix

To create a permanent Bash alias on a Linux or Unix system, you can add the alias to the .bashrc file in your home directory. The .bashrc file is a script that is executed whenever you start a new Bash shell.

To create a permanent Bash alias, follow these steps:

  1. Open the .bashrc file in a text editor. For example, you can use the nano editor to open the .bashrc file:
nano ~/.bashrc
  1. Add the alias to the .bashrc file. An alias is a shortcut for a command or a series of commands. To create an alias, use the alias command followed by the desired alias and the command or commands that it should represent. For example, to create an alias called l for the ls -l command, you can add the following line to the .bashrc file:
alias l='ls -l'
  1. Save the .bashrc file and exit the text editor.

  2. Reload the .bashrc file to apply the changes. You can use the source command to reload the .bashrc file:

source ~/.bashrc

After you have reloaded the .bashrc file, you will be able to use the alias you created. For example, in the example above, you can use the l alias to list the files in the current directory with the ls -l command:

l

Keep in mind that the .bashrc file is specific to each user, so the aliases you create will only be available to the user who created them. If you want to create a global alias that is available to all users on the system, you can add the alias to the /etc/bashrc file. However, this requires root privileges and is generally not recommended unless you have a specific need for a global alias.

Note that aliases are only available in the Bash shell. If you are using a different shell, such as the zsh shell, you will need to use a different method to create permanent aliases.

Created Time:2017-10-16 14:38:45  Author:lautturi