How To Set Alias In Linux

6 min read

Setting up command shortcuts is one of the fastest ways to improve productivity in the Linux terminal. If you frequently type long commands with multiple flags and arguments, learning how to set alias in Linux can save you hours of repetitive work. Which means a shell alias acts as a nickname for a command, allowing you to execute complex operations with just a few keystrokes. Whether you are a beginner navigating your first Linux distribution or an experienced system administrator managing remote servers, understanding how to create, manage, and persist aliases is an essential skill for efficient command-line usage Worth keeping that in mind..

What Is a Linux Alias?

An alias in Linux is essentially a custom shortcut that the shell recognizes as a substitute for another command or series of commands. When you type an alias in the terminal, the shell replaces it with the full command before execution. This mechanism is built into most common shells, including Bash, Zsh, and Fish.

As an example, instead of typing ls -la --color=auto every time you want a detailed directory listing, you can create an alias named ll that performs the same action. The shell handles the substitution transparently, so you get the result of the longer command without the extra typing.

Aliases are not standalone programs or scripts. They exist only within the current shell session unless you save them to a configuration file. This distinction matters because it determines whether your shortcuts disappear after you close the terminal or remain available every time you log in.

Why Use Aliases in Linux?

Using aliases offers several practical benefits:

  • Increased efficiency: Common tasks become faster to execute.
  • Reduced errors: Complex commands with many options are less likely to be mistyped when shortened to a memorable alias.
  • Consistency across systems: You can carry your preferred shortcuts to different servers by copying your shell configuration files.
  • Customization: You can tailor the terminal environment to match your workflow, creating commands that reflect how you actually work.

How to Set a Temporary Alias in Linux

A temporary alias exists only for the current terminal session. Once you close the terminal window or log out, the alias is gone. This approach is useful for testing a shortcut before committing it to your configuration files.

To create a temporary alias, use the following syntax in your terminal:

alias name='command'

Replace name with your chosen shortcut and command with the full command you want to run. For example:

alias update='sudo apt update && sudo apt upgrade -y'

After pressing Enter, you can type update and the shell will execute the full package update sequence. To verify that the alias was created, simply type:

alias

This command lists all active aliases in the current session. If you want to see the definition of a specific alias, use:

alias name

Temporary aliases are ideal for one-time tasks or experiments, but they do not survive a reboot. For lasting convenience, you need to make the alias permanent That's the part that actually makes a difference..

How to Set a Permanent Alias in Linux

To make an alias available every time you open a terminal, you must add it to your shell’s configuration file. The exact file depends on which shell you are using Simple as that..

Identifying Your Current Shell

Before editing configuration files, confirm which shell your user account is running. You can check this with:

echo $SHELL

The output usually shows something like /bin/bash or /bin/zsh But it adds up..

Creating a Permanent Alias in Bash

Bash is the default shell on many Linux distributions, including Ubuntu, Debian, and CentOS. Also, bash reads the ~/. On the flip side, bashrc file for interactive non-login shells and ~/. bash_profile or ~/.Think about it: profile for login shells. Here's the thing — for most desktop users, ~/. bashrc is the correct place to add aliases That's the whole idea..

This is the bit that actually matters in practice The details matter here..

Follow these steps:

  1. Open the .bashrc file in a text editor:

    nano ~/.bashrc
    
  2. Scroll to the end of the file and add your alias on a new line:

    alias ll='ls -la --color=auto'
    alias gs='git status'
    alias ..='cd ..'
    
  3. Save the file and exit the editor. In Nano, press Ctrl+O, then Enter, followed by Ctrl+X Simple, but easy to overlook..

  4. Apply the changes immediately without restarting the terminal:

    source ~/.bashrc
    

The source command tells Bash to reload the configuration file, making your new aliases available in the current session.

Creating a Permanent Alias in Zsh

Zsh is the default shell on macOS and is increasingly popular on Linux distributions such as Kali and Fedora. Zsh uses ~/.zshrc for interactive shell configuration.

  1. Open the Zsh configuration file:

    nano ~/.zshrc
    
  2. Add your aliases at the bottom:

    alias ll='ls -la --color=auto'
    alias cat='bat'
    
  3. Save and exit And that's really what it comes down to. Which is the point..

  4. Reload the configuration:

    source ~/.zshrc
    

Creating a Permanent Alias in Other Shells

If you are using Fish, Ksh, or another shell, the configuration file and syntax may differ. Fish, for example, uses the abbr command rather than `

rather than an alias. Practically speaking, fish instead relies heavily on built-in conveniences such as abbr for abbreviations, though it can also define functions or aliases depending on the desired behavior. Plus, a typical permanent Fish configuration would live in ~/. Here's the thing — config/fish/config. fish.

alias ll 'ls -la --color=auto'
abbr -a gs 'git status'

After saving the file, reload the configuration with:

source ~/.config/fish/config.fish

or simply open a new terminal.

For users of other shells, the process remains similar. In KornShell, the configuration file is usually ~/.Now, kshrc, and aliases use the familiar alias name='command' syntax. In C shell or tcsh, the file is typically ~/.cshrc, and aliases are defined with alias name 'command'. The exact syntax and file location are important because they determine whether an alias is recognized.

Easier said than done, but still worth knowing.

Once you have added an alias to any shell configuration file, you must either source the file or restart the terminal session for the change to take effect. Verification can be done with the alias command, and a specific alias can be checked with alias name Practical, not theoretical..

Short version: it depends. Long version — keep reading.

Best Practices and Troubleshooting

Although aliases are convenient, they should be used thoughtfully. Avoid creating aliases that shadow essential commands, and prefer clear, descriptive names. If an alias does not work, check for typos, ensure the configuration file is being read by the correct shell, and confirm that the shell

has been properly reloaded. Conflicts can also arise when multiple configuration files define the same alias, so it’s a good idea to keep your customizations in one place and review them periodically.

Another useful tip is to organize aliases into logical groups within your configuration file, using comments to label sections such as "Navigation," "Git," or "System Monitoring." This makes maintenance easier and helps others (or your future self) understand the purpose of each alias Less friction, more output..

Conclusion

Creating permanent aliases is a simple yet powerful way to streamline your workflow in the terminal. By adding them to the appropriate shell configuration file and reloading the session, you make sure your shortcuts persist across reboots and new terminal windows. Whether you're using Bash, Zsh, Fish, or another shell, the process follows a consistent pattern: edit the right file, define your aliases with the correct syntax, save, and reload. With a little setup, you can turn repetitive tasks into single-word commands, boosting both productivity and accuracy Not complicated — just consistent..

Out Now

Just Made It Online

Keep the Thread Going

Familiar Territory, New Reads

Thank you for reading about How To Set Alias In Linux. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home