27

I would like to have

alias ll="ls -l"

to be system wide.

How is that done on Ubuntu?

Sandra
  • 10,303
  • 38
  • 112
  • 165

3 Answers3

27

Add it in to /etc/bashrc. This will (or should) get called on login by every user who uses bash.

Andy Smith
  • 1,828
  • 14
  • 15
  • 2
    My machine (Ubuntu 12) doesn't have /etc/bashrc or any references to it in /etc/profile, ~/.bashrc or elsewhere. The place I found that was best to do this, decoupled from the system's files and thus better for maintaining customizations with something like Puppet, is to place a file in /etc/profile.d/ – Spanky Dec 04 '13 at 18:11
  • 2
    I believe the correct location is actually `/etc/bash.bashrc` FWIW – Paul Carroll Jan 20 '20 at 04:04
21
# echo "alias ll='ls -l'" >> /etc/bash.bashrc

and make sure that this file is executed whenever an user enters a shell by adding the following in ~/.bashrc:

# Source global definitions
if [ -f /etc/bash.bashrc ]; then
    . /etc/bash.bashrc
fi
quanta
  • 51,413
  • 19
  • 159
  • 217
  • This answer was helpful. In Ubuntu 14.04, when I opened my `.bashrc` file, near the end, there's a pre-created section similar to the `if [...]` @quanta mentions, except is uses `.bash_aliases`. All I had to do is echo the alias into `echo "alias ll-'ls -l'" >> ~/.bash_aliases` since `.bashrc` already had something setup in this environment. And I closed/re-opened putty. – jmbertucci Jan 04 '15 at 19:50
8

If your user's $HOME/.bashrc contains the usual

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

Then put it in /etc/bashrc. If it doesn't then put it in /etc/profile from where it will at least be read for login shells.

user9517
  • 115,471
  • 20
  • 215
  • 297