I am looking for a simple way to create a permanent alias for all users. So ~/.bashrc or ~/.bash_profile is not an option.

Hasn't anybody created a program for this? I think it should be a very common need. If not, I can always create a custom Bash script, but I need to know if there is a equivalent of .bash_profile for all users.

In my case, I am using Mac OS X v10.9 (Mavericks) and Ubuntu 12.04 (Precise Pangolin), but I would like a method that works on major Unix systems.

UPDATE: I was wondering about a program which automatically allows the users to manage a list of permanent of aliases directly from the command-line without having to edit files. It would have options for setting for all users, target users, interative/login shell, etc.

UPDATE 2: Reply to answer of @jimmij

$ su -m
# cat /etc/profile
alias test343="echo working"
# cat /etc/bash.bashrc
alias test727="echo working"
# test727
bash: test727: command not found
# test343
bash: test343: command not found
  • 1
    First you are talking about files then about a program... – Hauke Laging Feb 7 '15 at 15:37
  • @HaukeLaging I'm talking about possible solutions for my problem. I'll edit to clarify this – NeDark Feb 7 '15 at 15:47
  • @NeDark was that test on OSX or on Ubuntu? – muru Feb 7 '15 at 16:05
  • Re: Update #2. Exit the shell and try again. – cremefraiche Feb 7 '15 at 21:30
  • @cremefraiche I did restart shell, anyway it only happens using -m – NeDark Feb 8 '15 at 5:54

Please have a look at bash manual:

  • /etc/profile

    The systemwide initialization file, executed for interactive login shells

  • /etc/bash.bashrc

    The systemwide initialization file, executed for interactive, non-login shells.

  • ~/.bash_profile

    The personal initialization file, executed for interactive login shells

  • ~/.bashrc

    The individual per-interactive-shell startup file

  • ~/.bash_logout

    The individual login shell cleanup file, executed when a login shell exits

So you need to put your aliases in /etc/profile or /etc/bash.bashrc in order to make them available for all users.

| improve this answer | |
  • @terdon where did you get this /etc/bash.bashrc from? My manual of GNU bash, version 4.2.53(1) doesn't say anything about it. – jimmij Feb 7 '15 at 15:14
  • 2
    I've always known about it as the global init file, it's been around for as long as I've been using bash. It is also mentioned in the man page for my bash 4.3.25. That's where you define global stuff for interactive, non-login shells. Are you saying that man bash | grep -F bash.bashrc returns nothing on your system? – terdon Feb 7 '15 at 15:17
  • @terdon that is correct, I'm right now in front of recent stable bash on gentoo box, but there are indeed more recent unstable versions up to 4.3.33 – jimmij Feb 7 '15 at 15:44
  • @terdon At least on OS X yes, version 3.2.51(1) – NeDark Feb 7 '15 at 15:45
  • 1
    @NeDark Did you tried to with su -? su -m preserves environment, it is possible that it doesn't parse rc files. – jimmij Feb 7 '15 at 16:14

If you have ruby installed, you can use aka to generate permanent alias on the fly.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.