Under Ubuntu, how can I place a shell alias command that will be global to everyone?

6

Under Ubuntu 9.10, where can I place an alias command that will be valid to all users, root or otherwise, and that will work with a shell under GNOME as well as an ssh session and plain console login ?

For example, I love the ll command, which is not defined by default under Ubuntu, but is under openSuSE. I can manually enter:

alias "ll=ls -als"

but it will only be valid for the current shell. I want this to be valid for all users, all the time, remote or local connection.

Which file should I edit?

jfmessier

Posted 2010-02-06T01:54:07.163

Reputation: 2 530

Answers

4

Actually, I found that the answer, at least for me, is a combination of two previous answers. I found that the following was working for me:

The file /etc/profile is indeed executed, but the alias commands there are not working. I understand that the alias command there is only valid while the shell process is executed. Looking at the file /etc/bash.bashrc, I read at the top of the file that the file has to be "sourced" from /etc/profile.

So I added the alias command that I wanted in /etc/bash.bashrc first. like:

 alias "ll=ls -als"

Then I appended the source command at the end of /etc/profile:

 source /etc/bash.bashrc

It seemed to be working fine in both a shell locally launched and one from an SSH connection.

jfmessier

Posted 2010-02-06T01:54:07.163

Reputation: 2 530

8

You should put it under:

 /etc/bash.bashrc

to be available to all users.

Jon

Posted 2010-02-06T01:54:07.163

Reputation: 346

Yes. However, by titself under Ubuntu, this is not enough. I had to add the line "source /etc/bash.bashrc" at the end of th e/etc/profile file. – jfmessier – 2010-02-06T02:15:42.997

I didn't need to - it works for me – Jon – 2010-02-06T02:20:40.617

3

Try the /etc/profile file.

This is intended for system-wide initialisation of the Bourne shell and compatible shells.

pavium

Posted 2010-02-06T01:54:07.163

Reputation: 5 956

I tryed the alias command by itself there, and it was not running. As I was opening a new shell, the command was not available. However, by adding "source /etc/bash.bashrc" and the actual alias command at the end of that file, it was then working all fine. – jfmessier – 2010-02-06T02:17:05.270

0

As stated on the top of the file /etc/bash.bashrc:

 # System-wide .bashrc file for interactive bash(1) shells.
 # To enable the settings / commands in this file for login shells as well,
 # this file has to be sourced in /etc/profile.

So, both Jon and jfmessier are correct. Jon probably had /etc/bash.bashrc already sourced in /etc/profile, which seems to be the default case.

I would recommend to insert the alias commands in /etc/bash.bashrc and try to run them first, both with your normal user and with root. If they run as expected, you don’t need to source the file on profile. If they don’t, then source them.

asenseofdesign

Posted 2010-02-06T01:54:07.163

Reputation: 1