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?

3 Answers3

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.

dhag
  • 15,736
  • 4
  • 55
  • 65
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

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.

ron
  • 6,575