2

Whenever I start my bash terminal on Windows (git-bash) and I run alias I get the following aliases:

$ alias
alias ll='ls -l'
alias ls='ls -F --color=auto --show-control-chars'
alias ltsc='$(npm bin)/tsc'
alias lwbc='$(npm bin)/webpack'
alias node='winpty node.exe'

In my .bashrc I have only the following:

alias lwbc="\$(npm bin)/webpack"
alias ltsc="\$(npm bin)/tsc"

In my .bash_profile I have the following:

test -f ~/.profile && . ~/.profile
test -f ~/.bashrc && . ~/.bashrc

I don't have .profile file.

So where do these come from:

alias ll='ls -l'
alias ls='ls -F --color=auto --show-control-chars'
alias node='winpty node.exe'

Update:

I've found that these aliases come from /etc/profile.d/aliases.sh, now how do I know where this file is triggered from?

5
  • 2
    Possible duplicate of How to use `which` on an aliased command? – jasonwryan Feb 3 '17 at 18:33
  • 1
    @jasonwryan, how which is relevant here? – Max Koretskyi Feb 3 '17 at 18:35
  • try bash -lxv -c exit 2>&1 | grep alias – Jeff Schaller Feb 3 '17 at 20:38
  • @JeffSchaller, thanks, please see my update – Max Koretskyi Feb 4 '17 at 12:08
  • what i typically do is- I know the file aliases.sh most likely has to be called by some other file so I do a grep -l aliases.sh /etc/* then do grep -l aliases.sh /etc/*/* and so on till I hopefully track it down. worst case /etc/profile.d/aliases.sh is hard coded in some binary or kernel in which case you would not find it. – ron Feb 5 '17 at 16:01
3

Here is an excerpt from the documentation for bash:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

Since you have already checked the contents of .bashrc and .bash_profile in your home directory, it is likely for the answer to your question to lie in file /etc/profile; some distributions set up defaults for all users there, including aliases. If not, this configuration may be in one of the other files mentioned in the above excerpt.

0
2

Ask bash to print a trace of the commands it runs when it starts up.

bash -x

The trace only shows the commands as they are executed, it doesn't show which file they come from. But they have to come from a file that bash is reading: first /etc/bash.bashrc (if enabled on your system), then ~/.bashrc, plus any additional files sourced with the command . or source that, if used, appears in the trace.

If the aliases don't appear when you run plain bash, only in a login shell, then they're defined in the wrong place and you should move them to ~/.bashrc. To investigate where they're currently loaded from, run a login instance of bash with tracing on: bash -l -x

2
  • 1
    @Maximus The files in /etc/profile.d are read from /etc/profile, which is read by login shells. – Gilles 'SO- stop being evil' Feb 4 '17 at 14:27
  • thanks, got it. It's not easy to understand the contents of /etc/profile though – Max Koretskyi Feb 4 '17 at 20:26
1

I use SUSE and can tell you for this distribution those aliases are in /etc/bash.bashrc. And if you use a csh or tcsh then it would be in /etc/csh.cshrc. These are specific to your linux distribution, and it is recommended you do not modify them. Instead create and edit /etc/bash.bashrc.local as an administrator, and you will notice at the bottom of the /etc/bash.bashrc file it will do a test -s /etc/bash.bashrc.local and if the file exists it will run it.

I hate those ls aliases also. I have been commenting out alias ls='ls $LS_OPTIONS' for years in /etc/bash.bashrc. Just be aware that when you patch your system and do kernel updates, this /etc/bash.bashrc file can get overwritten, so you'll have to go back in and re-edit.

you mention you are using bash terminal on Windows (git-bash) so I don't know if /etc/bash.bashrc specifically exists for you.

0

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.