Create permanent bash alias

Create permanent bash alias

In our day-to-day work, we need to enter the same long commands frequently (and will always make typo mistakes :(). The #alias?command lets you create shortcuts for these commands, making them easier to remember and use.

But this alias command is also short-lived and valid for that particular session. How can we make it persistent?

Create ~/.bash_aliases file

  1. vi ~/.bash_aliases and edit
  2. Add your alias commands. i.e., alias k=kubectl?, alias h=helm
  3. Save & exit

Update ~/.bashrc file to load the aliases

  1. vi ~/.bashrc file and edit
  2. Upend below lines to load the aliases from ~/.bash_aliases file

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

To load it immediately, use the source command : source ~/.bash_aliases

To list all aliases

Use alias command to see the list.

Akintayo Tolani

Senior DevOps Engineer ? DevOps Advocate ? (Docker, Kubernetes, CI/CD Automation, Infrastructure as Code, Ansible, Scripting (Bash & Python), Cloud Platforms - AWS) ? Technical Writer ? Resume Writer ? SDG 4 Advocate??

4 个月

Amazing One, This just helped me out

回复

要查看或添加评论,请登录

社区洞察

其他会员也浏览了