Coolest Guides on the Planet

coolest guides on the planet

Coolest Guides On The Planet

Neil Gee

  • Home
  • macOS
  • WebDev
  • All Posts
  • Contact

Make an Alias in Bash or Zsh Shell in macOS, OS X Terminal

September 19, 2018 23 Comments

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

As of macOS 10.6 Catalina, Apple has made the zsh shell the default shell, previously it was the bash shell.

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 or .zsh file using the command line program called ‘nano’ if it doesn’t exist:

nano .bash_profile
bash-alias-OSX

bash-alias-OSX

When the .bash_profile or .zsh 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 shell environment by entering the command below:

source ~/.bash_profile

Or..

source ~/.zsh

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

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

Cats: macOS Tags: alias, bash, OSX, shell

The Ultimate Managed Hosting Platform

Subscribe

Coolest Guides on the Planet

Tags

3gs 10.6 apache backup baseband Bing boot clean urls Coolest Guy on the Planet cpanel css custom database drupal el capitan git Google image instadmg ios iphone jailbreak keys lion mac macos mojave macos sierra menu mysql OSX panda php phpmyadmin private public redirect remote rsa SEO shell ssh terminal unstoppables urls Yahoo
Load WooCommerce Stores in 249ms!
Beaver Builder Ultimate Addons

Donate a Beer to the Coolest Guides

Get Beaver Builder Now!
Load WordPress Sites in as fast as 37ms!

Copyright © 2021· Neil Gee - All Rights Reserved - Hosted by Runcloud

Copyright © 2021 · gee on Genesis Framework · WordPress · Log in