I have Ubuntu 14.04.2. I want to make it so all users automatically have a specific set of aliases. I have my aliases set in my personal .bashrc, but I don't want to have to manually copy them into the other users. Ideally it should automatically set these for newly created users as well.
4 Answers
You can create a script in /etc/profile.d/ to make aliases for all users:
Create a file called
00-aliases.sh(or any other fancy name) in/etc/profile.d:gksu gedit /etc/profile.d/00-aliases.shPut you aliases in this file. Example:
alias foo='bar --baz' alias baz='foo --bar'Save the file
- Restart any open terminals to apply the changes.
- Enjoy!
Some notes:
/etc/profileis a global file that gets run before~/.profile./etc/profile.d/is a folder that contains scripts called by/etc/profileWhen
/etc/profileis called (when you start/login a shell), it searches for any files ending in.shin/etc/profile.d/and runs them with one of these commands:source /etc/profile.d/myfile.sh
. /etc/profile.d/myfile.sh- I'm putting
00-before the file name to make it execute before the rest of the scripts. - You can also add your aliases in
/etc/profile, but this isn't recommended.
As pointed out here, it's probably better to add global aliases in /etc/bash.bashrc:
alias foo='bar --baz'
alias baz='foo --bar'
, because scripts in /etc/profile.d can be ignored for certain (non-login) shells. It took me hours to figure out why /etc/profile.d didn't work.
See e.g. https://askubuntu.com/a/606882/ and Understanding .bashrc and .bash_profile for the distinction between shells.
- 3,328
An alias will only work while inside of a shell. If you want something as widely accessible as an executable, you can add a small shortcut script to /usr/bin, e.g.:
#!/bin/sh
ls -l "$@"
The "$@" passes all arguments through to the executable. The name of the script will be the name of the executable.
- 2,115
- 3
- 20
- 21
/etc/bashrc
- System wide functions and aliases
- Environment stuff goes in /etc/profile
It's NOT a good idea to change this file unless you know what you are doing. It's much better to create a custom.sh shell script in /etc/profile.d/ to make custom changes to your environment, as this will prevent the need for merging in future updates.