soundtraining.net website links

Tuesday, April 12, 2016

Creating Global Aliases in Linux (CentOS 7/RHEL 7)

If you're like me and like to use aliases to simplify administration of your Linux servers, here's the easy way to create global aliases for all users.

  • Create a file in /etc/profile.d such as aliases.sh.
  • Add your aliases to the file.
  • Log off and log back on.
  • Your aliases should work.

As an example, I do a lot of administration through my smart phone (Nexus 6P on Google Fi), so I hate typing long commands. The two commands I use more than any others are "sudo yum -y update" and "exit". (Okay, "exit" isn't a long command, but still...)

Here's the contents of the aliases.sh file I created in /etc/profile.d:
alias yu="sudo yum -y update"
alias x="exit"

Now, all I have to do to run a yum update is type "yu" and all I have to do to exit is type "x".

I can (and will) add whatever other aliases I want to simplify my life to /etc/profile.d/aliases.sh.

Hope that helps.

Peace.