1

Normaly e.g. alias ll="ls -la" is stored in ~/.bashrc (or ~/.bash_profile).

But what ist the most effective way to find the location where is an alias stored? I come across this question, because alias la runs perfect, but it's not stored in the usual suspected locations.(~/.bashrc)

How can I find out where is an alias located?

echo $SHELL /bin/zsh

And yes, I know for zsh is .zshrc the usual suspect.

Teletubbi-OS X
  • 391
  • 1
  • 3
  • 13
  • Are you using a **dotfile** config ? – Thomas Ayoub Sep 19 '14 at 12:00
  • 1
    `.bashrc` isn't used by `zsh`, so there's no point looking there if you are using `zsh`. That aside, no shell I'm aware of tracks which file an alias was defined from. The best you can do is understand what files a shell will read automatically on startup, and check those first, following any references to other files (`source` or `.`) that may be executed. – chepner Sep 19 '14 at 12:02
  • Yes I know, but the "find" problem ist the same in BASH. I am looking for this command: ```show me the location/file where "la" is stored/located``` – Teletubbi-OS X Sep 19 '14 at 12:11
  • You can use type command to determine first whether that is a alias or not and then you can proceed. – Sriharsha Kalluru Sep 19 '14 at 14:52

1 Answers1

0

The alias you create on the command prompt will be valid only till the current session. Once you exit the session and re-login, it will not be preserved. So it is upto you where to store it depending on its usage. e.g. for login specific, you can store it in /etc/profile. If you want it sourced during non-login session, the use .bashrc, if you want it to be sourced always, then use bash_profile. I am assuming bash shell. Reference - http://www.linuxforums.org/forum/newbie/147054-where-alias-stored.html

So I guess the answer is that it is really upto you to manually store it. Just because you define it on the command line, will not get it stored automatically.

Sumod
  • 3,806
  • 9
  • 50
  • 69
  • 1
    That is not what the OP is asking. The question is: how is it possible to find out in which file an alias is defined? – pgl Sep 19 '14 at 12:19
  • OK :). Then @Teletubbi-osx, you can try running grep on the regular suspects or on the directories e.g. grep 'alias' ~/.bashrc /etc/profile/ ~/bash_profile. – Sumod Sep 19 '14 at 13:18