0

I've been trying to add global use of aliases on my Debian 10 instance with no luck.

What I've already attempted is adding my aliases to /etc/bash.bashrc as well as adding this snippet to /etc/profile to source it without it working.

if [ -f /etc/bash.bashrc ]; then . /etc/bash.bashrc fi

In my bash.bashrc:

#Aliases 
alias l='ls -la' 
alias ll='ls -l' 
alias la='ls -a'

EDIT*

How do I create an alias for "ls." For example, ls='ls -CF'. As when I use it as an alias it doesn't work?

  • How are the aliases defined, how did you attempt to load them (restarting shell, sourcing /etc/bash.bashrc, other), and what is the exact output when you try? – l0b0 Aug 17 '20 at 00:06
  • I added my aliases in my OP. I just restarted the shell by logging in/out. I put the above snippet in profile which sources it from bash.bashrc. – CranberryPie Aug 17 '20 at 01:39

2 Answers2

0

Debian should work with /etc/bash.bashrc. Check /etc/passwd and make sure the user is using bash shell.

user1:x:1000:1000:User 1:/home/user1:/bin/bash
user2:x:1001:1001:User 2:/home/user2:/bin/zsh

By default, adding users with useradd or adduser will create them with bash as a shell, but this might have been modified to other shell (zsh is very popular). In the sample above, user1 is using bash shell and user2 is using zsh. User2 will not run /etc/bash.bashrc on login.

LincolnP
  • 207
  • 2
  • 7
0

Looking at my ~/.bashrc I can see ls is already defined as alias ls='ls --color=auto'.

Adding a new ls alias definition to /etc/bash.bashrc as alias ls='ls -CF' doesn't help because, I assume, the definition in ~/.bashrc is overriding.

In my testing, commenting out the ls alias defined in my ~/.bashrc enabled to one I added for global definition in etc/bash.bashrc to work.

This is quite a bit different to how Red Hat handles global aliasing, which enables you to put your global aliases in /etc/profile.d/[filename].sh but due to the different way Debian and Red Hat are configured and the relationship between the profile and bashrc files, this doesn't seem to be an option for Debian.

By that, I mean for Red Hat it handles profile/bashrc files by sourcing them so they work for various shells/login types (as explained here https://unix.stackexchange.com/questions/170493/login-non-login-and-interactive-non-interactive-shells). However, for Debian it seems the files /etc/profile.d/*.sh are only sourced for login shells. But as my previous answer here was deleted, I was unable to edit and clarify.

For Debian, if you are happy for global aliases to work only for login shells then put them in, say, /etc/profile.d/aliases.sh. Otherwise, it looks like you need to add them to /etc/bash.bashrc. Bearing in mind that aliases in ~/.bashrc will take precedence. If aliases you define don't work, then chances are they are defined elsewhere and are overriding yours.