3

I was trying to setup a permanent alias. but ~/.bash_aliases file not found on my system. I have checked the bashrc file and it shows bash_aliases are enabled. I tried creating a new file in the same name in home directory and putting the aliases. But it also didn't work. Any solution to set a permanent alias?

Also i would like to know whether I can set an alias for shell that I created and it is residing in some other path. Thanks in advance.

5
  • This is not a duplicate. I have seen that question earlier. But my problem is different. I am unable to locate the bashrc_aliases file. I am looking for that solution here, and not the answer for how to set the alias. Dec 5, 2014 at 9:57
  • what do you mean "bash_aliases are enabled"? How do you know the file isn't found?
    – Holloway
    Dec 5, 2014 at 10:03
  • @Trengot I have the idea that I have to keep my aliases in bash_aliases file in alias name='command' format. And in order to tell the terminal to look at this file when I request an alias, two lines of codes ( if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi ) needs to be put in bashrc. In this way I know that bash_aliases is enabled. Dec 5, 2014 at 10:08
  • Ok. Do you have a file called .bash_aliases in your home directory?
    – Holloway
    Dec 5, 2014 at 10:09
  • No. And that is my problem and I have mentioned it in the question heading already :( Dec 5, 2014 at 10:15

1 Answer 1

6

The lines

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

mean if the file .bash_aliases exists then use it. In your case it doesn't exist so it's ignored.

If you want to add to it just create the file. How you do that is up to you but I'd suggest gedit ~/.bash_aliases from the terminal. Add in any aliases you want, then save the file and open a new terminal. Your new aliases should be working.

If you want the new aliases in an existing terminal use source ~/.bash_aliases.

EDIT: I've just noticed you've referred to the file by both bash_aliases and bashrc_aliases. It doesn't matter which you use as long as the filename matches the line in .bashrc.

3
  • Thanks a lot. I didn't knew that after creating the alias I have to open a new terminal to execute it. Thanks a bundle for taking your time and mentioning it. Dec 5, 2014 at 11:14
  • Could you please tell me whether is it possible to set an alias to an sh file by specifying its path? Dec 5, 2014 at 11:18
  • 1
    Yes. For instance alias foo='~/bar/foo.sh' would let you run foo.sh just by typing foo. Note that you'd need foo.sh to be executable and to have an appropriate shebang line.
    – Holloway
    Dec 5, 2014 at 11:21

Not the answer you're looking for? Browse other questions tagged .