LearnLinux FoundationsBash Shell Environment

unalias

unalias - a hands-on Linux lab on a real virtual machine.

Take a shortcut back with unalias. Remove one alias by name, watch command not found prove it is gone, meet the not found message for a name that was never an alias, and clear every alias at once with -a. The pair to alias: one adds a shortcut, unalias takes it away, and any alias set in ~/.bashrc returns in the next shell.

Last lesson you built a shortcut. You typed alias ll='ls -alF' and from then on, ll stood in for a long, detailed listing. One tiny word did a big command's work.

Now flip it around. What happens when a shortcut is WRONG? Someone hands you a machine where ll has been aliased to something odd, or you made an alias that now hides a real command you need. The shortcut is stuck to the name. How do you peel it back off and get the plain command returned to you?

The black boxes in this lesson are a practice terminal: a safe sandbox that only checks the one command each step teaches, so you cannot break anything. Everything shown here is byte-for-byte what real bash prints. These messages do not change from machine to machine, so what you read here is what you will see anywhere.

unalias removes an alias. That is its whole job. You give it the name of a shortcut, and it detaches that shortcut, so the name goes back to meaning nothing special, or back to the real command it was covering.

Read the name literally. alias glues a shortcut ONTO a name. unalias peels that shortcut back OFF. One adds, one takes away. They are a matched pair, and you will almost never use one for long without reaching for the other.

There are only two forms to learn. unalias NAME removes one alias by name. unalias -a removes every alias in your shell at once. That is the entire command.

To remove an alias, you first need one to remove. Recreate the shortcut from last lesson so you have something real to peel off. Type it now:

alias ll='ls -alF'

prompt: student@linuxcamp:~$ answer: alias ll='ls -alF' output: hint: Type alias, a space, the name ll, an equals sign, then the command in single quotes: alias ll='ls -alF'

Nothing printed, and that is correct. Making an alias is a quiet act: bash just files the shortcut away and says nothing. But ll now means ls -alF in this shell. In the next step you take it back.

Now peel the shortcut off. Before you run it, decide what you expect: after this command, does the name ll still do anything?

Hand the name to unalias:

unalias ll

prompt: student@linuxcamp:~$ answer: unalias ll output: hint: Type unalias, a space, then the alias name: unalias ll

Silent again, just like creating it. unalias removes the shortcut without ceremony. The name ll is no longer a shortcut for anything. To see what that really means, you have to try to use it. That is the next step, and it is the whole point of the lesson.

This is where the lesson lands. The alias is removed, so ll should no longer work. Type it and watch what bash says:

ll

prompt: student@linuxcamp:~$ answer: ll output: bash: ll: command not found hint: Just type the two letters l l and press Enter: ll

bash: ll: command not found is exactly what you wanted to see. ll was never a real program. It only ever worked because the alias stood in for ls -alF. Take the alias away and the name has nothing behind it, so bash reports it cannot find a command by that name. This same message is how you confirm ANY alias is truly removed: try the name, and a command not found proves the shortcut is gone.

There is a second message worth meeting on purpose, because you will trip over it. What if you unalias a name that is not actually an alias? Maybe you already removed it, or you spelled it wrong. Ask unalias to remove ll a second time, now that it is gone:

unalias ll

prompt: student@linuxcamp:~$ answer: unalias ll output: bash: unalias: ll: not found hint: Run the same removal command again on a name that is already gone: unalias ll

bash: unalias: ll: not found means unalias looked for an alias named ll to remove and there was not one. This is not a disaster. It usually just means the alias is already gone, or you typed a name that was never aliased in the first place. Read it as an all-clear on that name, not an error to fear. Note the shape too: unalias: ll: not found names the tool that complained, while the earlier ll: command not found came from the shell trying to RUN ll. Two different messages for two different moments.

Sometimes one at a time is too slow. You inherit a shell stuffed with aliases you did not set and you want a clean slate. The -a flag stands for all: unalias -a removes every alias in the current shell in one move.

It is safe to run even when you are not sure any aliases exist. Wipe the slate now:

unalias -a

prompt: student@linuxcamp:~$ answer: unalias -a output: hint: Type unalias, a space, then the all flag: unalias -a

Silent, and thorough. unalias -a cleared every alias this shell had, all in one command. Unlike unalias NAME, the -a form never complains that a name was not found: it simply removes whatever aliases exist and stops. Reach for it when you want a fresh shell with no shortcuts at all, not when you want to remove one specific alias.

One honest limit worth knowing. unalias only affects the CURRENT shell, the one you are typing in right now. If an alias was defined in your ~/.bashrc file (the setup file bash reads every time a new shell starts), then unalias removes it for now, but the very next shell you open reads ~/.bashrc again and the alias comes right back. On your machine that path shows your own username, such as /home/student/.bashrc, so your values differ. To remove an alias for good, you delete its line from ~/.bashrc as well. That is a file-editing job for a later lesson.

Scaffolding off. No command is printed this time. You have every piece you need.

Someone set up grep on this machine as an alias that always adds colour, but right now you need to run the plain, unaliased grep just once. You do not want to touch any other shortcuts, only this one. Remove the single alias named grep so the real command is what runs next.

prompt: student@linuxcamp:~$ answer: unalias grep output: hint: You want the form that removes ONE alias by name, not the one that clears them all. Think unalias, then the name grep.

That is the everyday move. unalias grep detached just that one shortcut and left every other alias alone, so the very next grep you type is the real program. If you had wanted to clear the whole shell instead, unalias -a was the other tool in your kit. You picked the single-name form from memory, which is the same recall the real machine will ask of you.

You earned this cheat sheet. Every row is a form of unalias you just ran:

And the two messages you can now read on sight: bash: ll: command not found means a removed alias's name has nothing behind it, and bash: unalias: ll: not found means there was no alias by that name to remove. Neither is a disaster.

alias and unalias are two ends of one tool. alias name='command' adds a shortcut; unalias name takes it away. When you want to run the real command behind an alias just once, unalias it, run the plain command, and remember: in a fresh shell any alias set in ~/.bashrc returns on its own.

The practice terminal has shown you the shape of unalias. You built an alias, removed it by name, watched command not found prove it was gone, met the not found message for a name that was never an alias, and cleared a whole shell with -a. Every one of those you typed yourself.

The Bash Environment module ends with one real Linux machine, the Bash Environment capstone mission, and that is where you run unalias for real. A VM boots just for you, with its own live shell. It hands you objectives that use exactly what you practiced across this module: setting variables, exporting them, building aliases, and taking them back. One difference from here: the mission shows no commands. You read the objective, you recall the command, you type it. That recall is what makes it stick.

Finish the other Bash Environment lessons, then go clean up a real shell for yourself.

Practice unalias in a real Linux terminal at The Linux Camp. Progress is verified automatically as you type commands on the machine.