Recently, I've been fiddling around with Linux's terminal commands to try and get a better feel for the system.

I was happy to know that I could give commands a different name in order to call them, using the alias command. For example,

alias print="echo"

In this case, the echo would be replaced by print.

The only problem is that it only seems to stay for one terminal session. Without the use of third party software, is there a way that I can keep these aliases permanently? If there are software alternatives, I'll be glad to hear them.

I'm just looking for a way to do this without downloading anything.

  • Sure, just save those aliases in your shell's rc file. (For bash, this is ~/.bashrc; for zsh, this is ~/.zshrc; for other shells it will be elsewhere) – HalosGhost Apr 22 '15 at 20:03

You need to put your aliases in a file that will be read upon start of all sessions.

Your ~/.bashrc file should have the following:

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

that means if you have a file ~/.bash_aliases file then it will be sourced and all the aliases defined in it will be applied in the session. It is the best practice to save your aliases in ~/.bash_aliases, if you don't have the file you can create it manually. As an alternative you can put your aliases in ~/.bashrc.

Also note that, if you want to permanently save the aliases those are defined only for current session of terminal, you can run:

alias >> ~/.bash_aliases

The common way is to set your aliases in the .bashrc file of your home directory (if you use bash as your shell of course).

.bashrc is file read by bash anytime you launch a terminal.

Just edit it (watch out, files with a name starting by a . are hidden by default) and add a line like:

alias ll='ls -l'

If you want to test it without launching a new terminal, just source it:

$ ll
bash: ll: command not found

$ source ~/.bashrc

$ ll
-rw-rw-r--  1 apaul apaul  31 Mar  7 21:51 file1.txt

Create a file .bashalias in your home directory, or edit the existing file ~/.bashalias. To have this file read every time you start a bash session, add the following to your ~/.bashrc:

source ~/.bashalias

  • Really? What Bash version do you have? – Arkadiusz Drabczyk Apr 22 '15 at 20:10
  • GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin14) So, admittedly, OS X not Mint, but I would be surprised to learn that the Bash included on Mint doesn't allow .bashalias.... – TravisThomas Apr 22 '15 at 20:38
  • Is sourcing .bashalias added to any of your Bash startup files explicitly? – Arkadiusz Drabczyk Apr 22 '15 at 20:39
  • oh, whoops, you're right. my bad! – TravisThomas Apr 22 '15 at 20:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.