How to create a permanent Bash alias on Linux/Unix

I need to create a bash shell alias named update as follows:
alias update='sudo -- sh -c "/root/bin/chk_disk && dnf update'
However, this update alias gets removed after I reboot the Fedora Linux box. How do I create a permanent Bash alias on a Fedora Linux or Unix-like system?

You need to put bash shell aliases in the ~/.bashrc file ($HOME/.bashrc) file executed by bash for non-login shells. On most modern Linux distro, you may want to put all your bash alias definitions into a separate file like ~/.bash_aliases, instead of adding them in the ~/.bashrc file directly. This tutorial shows how to add aliases permanently to your bash shell on Linux and Unix-like systems.

Steps to create a permanent Bash alias:

Open the Terminal app

  1. Edit ~/.bash_aliases or ~/.bashrc file using: vi ~/.bash_aliases
  2. Append your bash alias
  3. For example append: alias update='sudo yum update'
  4. Save and close the file.
  5. Activate alias by typing: source ~/.bash_aliases

Please note that ~/.bash_aliases file only works if the following line presents in the ~/.bashrc file:

if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases

Are above lines are missing in your ~/.bashrc file? Just append at the end of the ~/.bashrc, using a text editor such as vi/vim or joe.


Let us create four aliases as follows:
$ vi ~/.bash_aliases
$ joe ~/.bashrc
Append text:

# update our debian/ubuntu box
alias update='sudo -- sh -c "apt update && apt upgrade"'
# make grep output colorful 
alias grep='grep --color=auto'
# set eth0 as an interface for eth0  
alias vnstat='vnstat -i eth0'
# flush redis cache for wp
alias flush_redis='redis-cli -h FLUSHDB'

Save and close the file.

How to load aliases

All new aliases will be available next time you login using a new ssh/terminal session. To load changes immediately, type the following source command:
$ source ~/.bash_aliases
$ . ~/.bash_aliases

How to list all of my aliases

To list all aliases, run:
$ alias
Sample outputs:

alias flush_redis='redis-cli -h FLUSHDB'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
alias update='sudo -- sh -c "apt update && apt upgrade"'
alias vnstat='vnstat -i eth0'

How to use/call aliases

Just type alias name:
$ update
$ vnstat
$ flush_redis

Removing bash aliases

To remove given alias from the list of defined aliases, try the unalias command:
unalias alias_name
unalias c

Delete alias definitions by passing the -a as follows:
unalias -a

Summary of all commands

You learned how to create bash aliases using the alias command.

Command Description Example(s)
alias -p
Prints the list of aliase alias
alias name='value' Define aliase alias c='clear'
alias d='df -H'
Execute alias called c or d c
unalias NAME
unalias -a
Delete each NAME from the list of defined aliases
The -a option remove all alias definitions
unalias c
unalias -a
vi ~/.bashrc
nano ~/.bashrc
vim ~/.bashr_aliases
neovim ~/.bashr_aliases
Store your aliases permanently in bash config file
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
alias ls='ls --color=auto'
alias l.='ls -d .*'
alias vnstat='vnstat -i eth0'

See also 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X and bash command man page here.

🐧 Please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @