Skip to content

alias MacOS command

The MacOS alias command allows users to create custom shortcuts for lengthy or frequently used commands, improving efficiency and productivity. By setting up aliases, users can simplify complex commands and make them easier to remember and execute. This feature is especially useful for individuals who work with the terminal frequently and want to streamline their workflow. With the alias command, Mac users can save time and effort by creating personalized shortcuts for common tasks or commands.

alias Syntax:

Terminal window
alias [name[='value'] ...]

Options:

OptionDescription
-pList all defined aliases in name=value pairs.

Parameters:

ParameterDescription
nameThe name of the alias being created or updated.
valueThe command or sequence of commands to be executed.

alias bash Examples:

Create a Simple Alias

Terminal window
alias ll='ls -al'

Creates a simple alias “ll” for the command “ls -al”.

Display Current Aliases

Terminal window
alias

Displays a list of all currently defined aliases.

Remove an Alias

Terminal window
unalias ll

Removes the alias “ll” that was previously created.

Alias with Arguments

Terminal window
alias grep='grep --color=auto'

Creates an alias “grep” that includes the --color=auto argument for color-highlighting search results.

Persistent Aliases

Terminal window
echo "alias desktop='cd ~/Desktop'" >> ~/.bash_profile

Sets an alias “desktop” to change directory to the Desktop and makes it persistent by adding it to the .bash_profile file.

Combine Multiple Commands in an Alias

Terminal window
alias dulp='du -h --max-depth=1 | sort -hr'

Creates an alias “dulp” that combines the commands du, sort, and list file sizes in the current directory.

alias Command Help Center:

How do I use alias in MacOS?

To use the alias command in MacOS, execute the following command:

Terminal window
alias --option <value>

How do I create a new alias in MacOS?

To create a new alias in MacOS, use the following syntax:

Terminal window
alias newalias='command'

How do I list all aliases in MacOS?

To display a list of all defined aliases in MacOS, run the command:

Terminal window
alias

How do I remove an alias in MacOS?

To remove an alias in MacOS, use the unalias command followed by the alias name:

Terminal window
unalias aliasname

How do I make an alias permanent in MacOS?

To make an alias permanent in MacOS, add the alias command to your shell configuration file like ~/.bashrc or ~/.bash_profile.

How do I know the full command an alias refers to in MacOS?

To see the full command an alias refers to in MacOS, use the type command with the alias name:

Terminal window
type aliasname

How do I prevent overriding existing commands with an alias in MacOS?

To prevent overriding existing commands with an alias in MacOS, use the \ before the command or built-in command:

Terminal window
\command

How do I remove all aliases in MacOS?

To remove all aliases in MacOS, use the unalias command with the -a option:

Terminal window
unalias -a

Applications of the alias command

  • Creating custom shortcuts for frequently used commands
  • Increasing productivity by reducing typing
  • Simplifying complex commands
  • Organizing and managing command workflows