How To Create a Permanent Bash Alias in Linux

This post will guide you how to create a permanent bash alias on your Linux operating system. How do I list all alias names in your current bash shell.

create a permanent bash alias2

List all Alias


If you want to list all alias names in your current bash shell prompt on Linux, and you can use the following alias command:

$ alias

Or

$ alias -p

Outputs:

devops@devops:~$ alias
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
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'
devops@devops:~$

Create a Permanent Bash Alias


Assuming that you want to create an alias for rm command in order to have a confirmation message after executing this command. So I need to create an alias like this “alias rm=”rm -i”. But this alias is a temporary alias and it will be removed after I reboot system. So how do I create a permanent bash alias in your current bash shell in Linux. You need to do the following steps:

#1 you need to edit the .bashrc file with your vim text editor, type:

$ sudo vim ~/.bashrc

#2 then you need to create an alias at the bottom of the .bashrc file.

alias rm="rm -i"

create a permanent bash alias1

#3 saven and close the file.

#4 you can type the following source command to activate alias, type:

$ source ~/.bashrc

Then you can run the following alias command to verify if alias name “rm” is created. type:

$ alias

Outputs:

devops@devops:~$ alias
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
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 rm='rm -i'

Conclusion


You should know that how to create a permanent bash alias by adding alias command into .bashrc file in your Linux system.

 

You might also like:

Sidebar



back to top