Create Linux Permanent Aliases for All Users


This guide intends to teach you to Create Linux Permanent Aliases for All Users with Examples. In simple words, the alias command allows you to create a shortcut for long commands. It makes it easy to remember and use the commands. Also, it has the same functionality as the whole command. Now follow the steps below to see how you can make a permanent alias for a specific user and all users.

Steps To Create Linux Permanent Aliases for All Users

To complete this guide, you must have SSH access to your server as a root or non-root user with sudo privileges. Then, follow the steps below to complete this guide.

To show you the guide steps we use Ubuntu 22.04 server. You can use any Linux distro you want.

Step 1 – Create Permanent Aliases for a Specific User in Linux

First, we will show you how to create a permanent alias for a specific user. This can be done by defining your alias in the bashrc profile in Linux. For example, open the bashrc file with your desired text editor like vi editor or nano editor:

vi ~/.bashrc

At the end of the file, we want to define an alias for the apt update and apt upgrade commands. This will be like the following:

alias update="apt update && apt upgrade"

You can create your desired aliases like the above syntax in Linux. When you are done, save and close the file.

Load Aliases in Linux

Then, you need to load the bash aliases with the command below:

source ~/.bashrc

List Aliases in Linux

Now you can use the command below to list your aliases:

alias
Example Output
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l="ls -CF"
alias la="ls -A"
alias ll="ls -alF"
alias ls="ls --color=auto"
alias update="apt update && apt upgrade"

Run Aliases in Linux

At this point, you can call and run your alias just by the name you have defined for it. For example:

update

This will run the system update and upgrade.

Step 2 – Create Permanent Aliases for All Users in Linux

The above method is just for a specific user, you can’t use it for all the users. To make it permanent for all users, you can follow the steps below.

To make permanent aliases for all users, you need to define a file in /etc/profile.d/ directory. For example, we create the following file:

vi /etc/profile.d/myalias.sh

At the file, define your desired aliases. For example:

alias update="apt update && apt upgrade"

When you are done, save and close the file.

Make Alias File Executable

Now set the correct permissions for your created alias file and make it executable with the command below:

chmod 755 /etc/profile.d/myalias.sh

Load and Run Alias File for All Users

Next, you must load your alias file. To do this, you can use the command below:

source /etc/profile.d/myalias.sh

At this point, all the users can run the aliases commands in Linux. For example:

update

Step 3 – Remove or Unset Aliases in Linux

If you want to remove the aliases you have defined, you can use the command below:

unalias alias-name

For example:

unalias update

If you want to delete all aliases, you can use the command below:

unalias -a

Conclusion

You may be interested in these articles:

Use Autojump Advanced Navigation in Linux Examples

Exclude Matches, Directories, Or Files with Grep

Leave a Comment

Scroll to Top