How can I preset aliases for all users?

You can create a script in /etc/profile.d/ to make aliases for all users:

  1. Create a file called 00-aliases.sh (or any other fancy name) in /etc/profile.d:

    gksu gedit /etc/profile.d/00-aliases.sh
    
  2. Put you aliases in this file. Example:

    alias foo='bar --baz'
    alias baz='foo --bar'
    
  3. Save the file

  4. Restart any open terminals to apply the changes.
  5. Enjoy!

Some notes:

  • /etc/profile is a global file that gets run before ~/.profile.
  • /etc/profile.d/ is a folder that contains scripts called by /etc/profile
  • When /etc/profile is called (when you start/login a shell), it searches for any files ending in .sh in /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.


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.

Source: https://unix.stackexchange.com/a/52509/15954