May 5, 2025

How to Create and Use Bash Aliases in Linux

mr rockstar

How to Create and Use Bash Aliases in Linux
Cheap Dedicated Server

How to Create and Use Bash Aliases in Linux

If you find yourself typing long terminal commands repeatedly in Linux, bash aliases are here to save your time and sanity. Aliases let you create shortcuts for complex or frequently used commands. This guide shows you how to create, manage, and remove bash aliases in just a few steps.


Step 1: What is a Bash Alias?

A bash alias is a custom shortcut for a longer command. For example, instead of typing:  

ls -la --color=auto

you could create an alias:
A bash alias

alias ll='ls -la --color=auto'

Now, typing ll runs the full command.


Step 2: Create a Temporary Alias

To create an alias for the current terminal session:
Create a Temporary Alias

alias gs='git status'

This alias works until you close the terminal.


Step 3: Make the Alias Permanent

To keep aliases available in every terminal session, add them to your shell’s configuration file.

For most users, that’s ~/.bashrc or ~/.bash_aliases:
Make the Alias Permanent

nano ~/.bashrc

Add your alias at the bottom:
Add your alias at the bottom

alias gs='git status'

Then reload the file:

source ~/.bashrc

Step 4: List and Remove Aliases

  • To list all active aliases:
alias
  • To remove an alias (only for current session):
    List and Remove Aliases
unalias gs

Tips

  • Use quotes if your alias contains spaces.
  • Avoid naming aliases the same as existing commands.

 

How to Create and Use Bash Aliases in Linux (F.A.Q)

Can I use aliases in zsh or fish shells?

Yes, but syntax may vary. For zsh, it’s the same. For fish, use alias name "command".

Where should I store permanent aliases?

Typically in ~/.bashrc, ~/.bash_aliases, or ~/.zshrc depending on your shell.

Do aliases work in scripts?

Not by default. It’s better to use shell functions or full commands in scripts.

 

Can I alias commands with parameters?

Yes, but use functions if you need dynamic parameters.

Popular Blog Posts