# How to Check Aliases in Linux


Have you ever typed a command in your Linux terminal, only to be told "command not found"? Chances are you set up an alias ages ago and have since forgotten about it.

Using aliases can save time by creating shortcuts for commonly used commands or sequences. But that convenience vanishes when you no longer remember what your alias stands for.

So how do you check what aliases you have configured in a Linux environment?

Fortunately, it only takes a simple command to view, modify, or remove any aliases you have set up. With a few keystrokes, you can refresh your memory or do some alias "spring cleaning".

## Why Aliases Get Forgotten

Aliases are often created on a whim to save effort in the short term. You find yourself typing `git status` repeatedly, so you map it to a shorter `gs`. A few weeks later, you try `gs` in a different directory and get the familiar "command not found" since your alias only works in Git repositories.

Even common aliases can slip your mind over time. It's frustrating when muscle memory kicks in and you find yourself staring confusedly at the error message:

```plaintext
$ ls
-bash: ls: command not found
```

With a thousand other things demanding your attention, remembering every alias and its meaning is nearly impossible. Rather than waste time puzzling over what your former self was thinking, you can quickly list all active aliases. A few seconds to check will jog your memory and get you back on track.

## View All Current Aliases

The easiest way to review your existing aliases is with a single command:

```plaintext
alias
```

This prints all aliases defined in your current shell session along with the value they represent. Any alias mapped to a command sequence or script will be shown here.

For example, you may see something like:

```plaintext
alias ls='ls --color=auto'
alias gs='git status'
alias ..='cd ..'
```

If you ever need a refresher on what time-saving shortcuts you have available, `alias` has you covered.

> Also read - [**Understanding the Powerful head Command in Linux**](https://developnsolve.com/understanding-the-powerful-head-command-in-linux)

## Search for a Specific Alias

If you know part of an alias name but want to confirm what it expands to, pipe the output of `alias` to the `grep` command:

```plaintext
alias | grep 'searchterm'
```

Say you vaguely remember having an alias called "mkd" but aren't sure what it mapped to. You could run:

```plaintext
alias | grep 'mkd'
```

And if mkd was an alias for `mkdir`, you would see:

```plaintext
alias mkd='mkdir'
```

Now you know that running `mkd` will execute `mkdir` instead.

## Check Alias Values

In addition to listing all aliases, you can pass a specific one to `alias` to print just that shortcut's value:

```plaintext
alias AliasName
```

If we wanted the value of `ls` from the earlier example, running `alias ls` would return:

```plaintext
ls='ls --color=auto'
```

This provides an easy way to check what any individual alias expands to without the noise of all other defined aliases.

## Location of Aliases

The aliases shown by the `alias` command exist only in your current terminal session. When you close the session, those aliases disappear.

To persist aliases across sessions, you can add them to shell startup scripts like `~/.bashrc`. Aliases defined in these files will load whenever you open a new terminal window.

The `alias` command reflects only session-specific aliases, not these persistent ones. But now you know where to look if you need to find aliases that load on startup.

## Clearing Forgotten Aliases

As you discover aliases you no longer use or remember setting up, it's easy to remove them:

```plaintext
unalias AliasName
```

So if we wanted to remove the hypothetical `mkd` alias from before, we'd run:

```plaintext
unalias mkd
```

To remove all aliases and start fresh, clear them all in one command:

```plaintext
unalias -a
```

> Also read - [**Understanding the Linux cp Command for Beginners**](https://developnsolve.com/understanding-the-linux-cp-command-for-beginners)

## Don't Let Aliases Slow You Down

While aliases facilitate efficiency, forgotten ones can grind progress to a halt. But with the handy `alias` command, you can manage aliases by:

- Checking for forgotten aliases wastes your time
- Listing all active aliases and their meanings
- Inspecting values for specific alias shortcuts
- Clearing aliases you no longer need bogging you down

The next time "command not found" appears after trying to use an alias, don't waste cycles puzzling over it. A quick `alias` lookup can jog your memory, letting you get back to more important tasks.

And moving forward, document new aliases by adding comments in your `.bashrc` file. Past You set up those time-saving shortcuts to help Future You. So do Future You a favor by recording alias meanings instead of relying on fallible human memory.

