Bash Alias For Mac



I've spent years curating a collection of Mac bash aliases and shortcuts to make my life easier. My full .bash_profile is below, feel free to take whatever you find useful and put it to good use.
  1. Bash Alias Mac
  2. Mac Remove Alias
  3. Bash Aliases Mac Terminal
  4. Bash Alias For Mac Shortcut
  5. Bash Alias For Path
  6. Bash Alias For Mac Mojave
  7. Bash Alias For Mac Os

Bash Alias Mac

To create an alias in bash that is set every time you start a shell: Open your /.bashprofile file. Add a line with the alias—for example, alias lf='ls -F' Save the file. Quit the editor. The new alias will be set for the next shell you start. Open a new Terminal window to check that the alias is set: alias. You should see your new alias. Aliases in zsh work just like aliases in bash. You declare an alias with the alias (built-in) command and it will work as a text replacement at the beginning of the command prompt: alias ll='ls -al' You can just copy your alias declarations from your.bashprofile or.bashrc to your.zshrc. By alias, I mean the folder shortcut created when you right-click a folder in Finder and select 'Make Alias'. I can traverse symbolic links in Terminal with cd, but it doesn't work on aliases: bash: cd: example-alias: Not a directory. Is it possible to change directory to an alias's destination in Terminal? When I define a new alias in.bashaliases file or a new function in.bashrc file, is there some refresh command to be able immediately use the new aliases or functions without closing the terminal (in my case xfce4-terminal with a few tabs open, many files open and in the middle of the work)?

A (very) quick primer on .bash_profile for Mac Users

There is a hidden file in your Mac’s user directory named .bash_profile. This file is loaded before Terminal loads your shell environment and contains all the startup configuration and preferences for your command line interface. Within it you can change your terminal prompt, change the colors of text, add aliases to functions you use all the time, and so much more.

This file is often called a ‘dot file’ because the ‘.’ at the beginning of it’s name makes it invisible in the Mac Finder. You can view all invisible files in the Terminal by typing ls -al in any directory.

How to edit your .bash_profile

For the newly initiated, here’s how you can edit the .bash_profile on your Mac.

Step 1: Fire up Terminal.app

Step 2: Type nano .bash_profile – This command will open the .bash_profile document (or create it if it doesn’t already exist) in the easiest to use text editor in Terminal – Nano.

Step 3: Now you can make a simple change to the file. Paste these lines of code to change your Terminal prompt.

Mac Remove Alias

Step 4: Now save your changes by typing ctrl +o Hit return to save. Then exit Nano by typing ctrl+x

Step 5: Now we need to *activate your changes. Type source .bash_profile and watch your prompt change.

My .bash_profile

I have been compiling my own set of aliases and configurations for years in which time I have borrowed copiously from others who have made their aliases available online. I can claim credit for very little of what follows. I recently became aware of alias.sh, a site making sharing BASH aliases easy. Check it out.

Update: Due to popular demand, my bash profile is now available as a Gist for your forking pleasure.

Without further ado, here is my .bash_profile:

Bash Aliases Mac Terminal

Update: If you enjoyed this post, you might also like:

  • A collection of Bash scripting utilities I compiled to make custom Bash programming easier.

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:

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

Bash Alias For Mac Shortcut

Bash Alias For Mac

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

Bash Alias For Path

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’

Bash Alias For Mac Mojave

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:

Or..

Bash Alias For Mac Os

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

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