Add a Command Alias to Linux User Profile




Problem:  I'm tired of typing long commands in the Linux command prompt whenever I want something done. Not only that, typing these commands is prone to typo errors.

Solution: Add a command alias to our user profile.

Here's how:

1.  Edit your Linux OS user profile (or .bash_profile)  and add a command alias

dbaworks@dbasrv1:~$ vi .profile

-- add the command alias

# set PATH so it includes user's private bin directories
PATH="$HOME/bin:$HOME/.local/bin:$PATH"

alias check_mongo='ps -ef | grep mongo'


2.  Reload your OS user profile

dbaworks@dbasrv1:~$ . .profile

3.  You can now run the command alias and get the desired result:

dbaworks@dbasrv1:~$ check_mongo

--- output
dbaworks@dbasrv1:~$ check_mongo 
mongod 9655 1 1 Jun29 ? 04:15:13 /usr/bin/mongod -- configsvr --replSet csReplSet1 --port 27050 -f /data/mongod.conf --bind_ip_all 


Learn more about Linux shell scripting using this guide book: