0

I executed the following command to create an alias file in CentOS 7.9:

echo 'alias ll="ls -alhF --color=auto"' > /etc/profile.d/alias-ll.sh

Then once I restarted the shell, "type ll" indicated that this alias did not work. I thought this may have been due to another file in /etc/profile.d overwriting the alias, so I renamed the file to "z-alias-ll.sh". Then I restarted shell and this time, "type ll" indicated that the alias had worked successfully.

However when I do the same in Ubuntu 20.04, "type ll" indicates that it does not work. There were some filenames like "Z99-cloud-locale-test.sh" and "Z99-cloudinit-warnings.sh" in /etc/profile.d in Ubuntu, so I tried these:

echo 'alias ll="ls -alhF --color=auto"' > /etc/profile.d/Z99-alias-ll.sh
echo 'alias ll="ls -alhF --color=auto"' > /etc/profile.d/ZZ99-alias-ll.sh
echo 'alias ll="ls -alhF --color=auto"' > /etc/profile.d/Z99-z-alias-ll.sh
echo 'alias ll="ls -alhF --color=auto"' > /etc/profile.d/ZZ99-z-alias-ll.sh
echo 'alias ll="ls -alhF --color=auto"' > /etc/profile.d/Z99Zalias-ll.sh

However, when I restart the terminal, "type ll" still says, "ll is aliased to `ls -alF'".

If I make another alias file:

echo 'alias lltest="ls -alhF --color=auto"' > /etc/profile.d/alias-lltest.sh

Then after I restart the terminal, "type lltest" indicates that this file is being sourced. So, I think the alias files in /etc/profile.d are being sourced, but the alias for "ll" is being overwritten somehwere.

Since I tried prefixing with "ZZ99" etc. I don't think it's an string sorting issue, like with CentOS 7.9, where I had to add the "z-" prefix to the filename to prevent another /etc/profile.d file from taking precedence. However, I am not 100% sure.

What file, script, etc., might be taking precedence over the alias files I created in /etc/profile.d? What takes precedence over /etc/profile.d in Ubuntu, in terms of defining environment variables?

I tried on both Ubuntu 20.04 and Ubuntu 22.10, using fresh Digital Ocean droplets.

3
  • 2
    If "the terminal" means a terminal emulator, such as gnome-terminal, then by default in Ubuntu it likely starts an interactive non-login shell - which reads /etc/bash.bashrc and ~/.bashrc rather than the various profile files Commented Apr 25, 2023 at 23:30
  • Thank you. By terminal, I meant the Digital Ocean droplet console. I did a test where I placed different aliases for the same command in /etc/bash.bashrc and /root/.bashrc, and a file in /etc/profile.d. It seems that the order of precdence is ~/.bashrc > /etc/profile.d > /etc/bash.bashrc. There was already an alias for "ll" in /root/.bashrc, that was the cause of my issue. Thank you very much for your assistance!
    – Tristan
    Commented Apr 26, 2023 at 2:20
  • It's not a precedence, rather, whatever comes last wins. And bash does read system-wide configuration before user configuration and it does read profile before bashrc for interactive login shells.
    – muru
    Commented Apr 26, 2023 at 4:09

1 Answer 1

2

Generally, user settings have precedence over system wide settings. This is also valid for aliases. User defined aliases have precedence over aliases defined at the system level. By default on Ubuntu, alias ll='ls -alF' is defined in the user's .bashrc file, thus overriding any alias you may have set elsewhere.

1
  • and alias ls='ls -ALf' will overide the default system ls command.
    – pierrely
    Commented Apr 30, 2023 at 1:46

You must log in to answer this question.

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