Make an Alias in Bash Shell in macOS using Terminal

To make aliases of macOS Unix commands in your bash shell on macOS and earlier versions, it is done via your .bash_profile file which lives in your home account directory, if the file does not already exist, just create one.

Launch Terminal from the /Application/Utilities folder

Go to your home directory by just entering cd followed by the ‘return’ key to enter the command:

cd

List your home directory contents including invisible files to see if the file already exists, use:

ls -la

drwxr-xr-x+ 18 ladmin staff 612 Jul 14 09:21 .
drwxr-xr-x 6 root admin 204 Jul 3 18:28 ..
-rw------- 1 ladmin staff 3 Jun 2 12:53 .CFUserTextEncoding
[email protected] 1 ladmin staff 6148 Jul 14 09:01 .DS_Store
drwx------ 5 ladmin staff 170 Jul 3 18:44 .Trash
-rw------- 1 ladmin staff 1157 Jul 14 08:59 .bash_history
drwx------+ 5 ladmin staff 170 Jul 14 08:33 Desktop
drwx------+ 6 ladmin staff 204 Jun 2 13:48 Documents
drwx------+ 8 ladmin staff 272 Jul 3 18:10 Downloads
drwx------+ 29 ladmin staff 986 Jul 3 17:49 Library
drwx------+ 3 ladmin staff 102 Jun 2 12:53 Movies
drwx------+ 3 ladmin staff 102 Jun 2 12:53 Music
drwx------+ 4 ladmin staff 136 Jun 2 12:53 Pictures
drwxr-xr-x+ 4 ladmin staff 136 Jun 2 12:53 Public
drwxr-xr-x+ 6 ladmin staff 204 Jul 3 18:11 Sites

Create the .bash_profile file using the command line program called ‘nano’ if it doesn’t exist:

nano .bash_profile

When the .bash_profile file is created you are ready to enter your alias commands.
So here I am using the alias ‘l’ to alias the command ‘ls -lah’

alias l='ls -lah'

In nano ‘control+o’ to write the file out and ‘control+x’ to exit the file.

Refresh the bash shell environment by entering the command below:

source ~/.bash_profile

That’s it, now the alias will take effect.

To add other aliases just start a new line,  and apply the same formatting.