How to create a new alias?

QuestionsQuestions8 SkillsProDec, 18 2025
0119

Creating a new alias is very simple! You use the alias command followed by the name you want to create and the command it should run.

Basic Syntax

alias name='command'

Note: Make sure there are no spaces around the equals sign (=).

Example 1: A simple shortcut

If you find yourself moving to a specific folder often, you could create a shortcut:

alias goproj='cd /home/labex/project'

Now, whenever you type goproj, the terminal will immediately change your directory to that path.

Example 2: Adding default flags

If you want the df command (which shows disk space) to always show sizes in a human-readable format (MB/GB), you can do this:

alias df='df -h'

Temporary vs. Permanent

  1. Temporary: If you type the command directly into the terminal (like the examples above), the alias will only work in your current session. If you close the terminal, it's gone.
  2. Permanent: To keep your alias forever, you need to add that line to your shell's configuration file (usually a hidden file named .bashrc or .zshrc in your home directory).

How to remove an alias

If you change your mind, you can use unalias:

unalias goproj

In the context of this lab, understanding aliases helps you realize why type ls gives a different result than type cd! Shall we continue with the lab steps to see how to get help for these commands?

0 Comments

no data
Be the first to share your comment!