Learn › Linux Foundations › Bash Shell Environment
alias - a hands-on Linux lab on a real virtual machine.
Give a long command a short nickname with alias. Define a shortcut, list every alias in the current shell, look one up by name, and add a safe default to a real command. Aliases live only in the current shell: this lesson teaches the shape and the moves, and points at ~/.bashrc for making them permanent.
There is a command you run so often your fingers know it in the dark. Maybe it is ls -alF to see everything in a folder, long form, hidden files and all. Maybe it is git status. You type the whole thing, every character, every time.
What if you could rename it? Give that long command a short nickname, two letters, and have the shell expand the nickname into the full command every time you press Enter. That is one command's entire job, and it is called alias.
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. An alias you define here lives only in this shell for this session. When you close the terminal, it is gone. Making one permanent is a later lesson.
alias makes a short name stand in for a longer command. You tell it once, this word means that command, and from then on, whenever you type the short word as the first thing on a line, the shell swaps in the full command before it runs.
Think of it as a nickname. Your friend Robert answers to Bob. You say Bob, everyone knows you mean Robert. An alias is a nickname for a command: you say ll, the shell knows you mean ls -alF.
The shape has three parts: the word alias, then the nickname, then an equals sign and the full command in quotes. Here is the most famous one of all. It makes ll (two lowercase L's) run a long, detailed listing:
alias ll="ls -alF"
prompt: student@linuxcamp:~$ answer: alias ll="ls -alF" output: hint: Type alias, a space, ll, then equals, then ls -alF wrapped in double quotes: alias ll="ls -alF"
Nothing printed, and that is exactly right. Defining an alias is a quiet act: the shell simply records the nickname and says nothing back. No news is good news. Behind that silence, ll now means ls -alF for the rest of this session. Notice there are no spaces around the = sign, ll="ls -alF", not ll = "ls -alF". That spacing rule is strict, and the next step shows what happens when the whole command lives inside one pair of quotes.
Look again at what you wrapped in quotes: "ls -alF". The whole command, the program AND its flag, sits inside one pair of double quotes. That is deliberate. The quotes bundle everything to the right of the = into a single value, spaces and all, so the shell stores the complete command as one nickname.
Leave the quotes off and the space breaks the definition apart, because the shell reads the space as the end of the value. Quote the whole command string, every time, especially when it has spaces or flags. Define a second alias now, gs for git status, and quote it the same way:
alias gs="git status"
prompt: student@linuxcamp:~$ answer: alias gs="git status" output: hint: Same shape as before. The nickname gs, then equals, then git status inside double quotes: alias gs="git status"
Silent again, and now you have two nicknames loaded: ll and gs. The command git status is two words with a space between them, and the double quotes held those two words together as one value. Type gs and press Enter, and the shell runs the full git status for you. You just turned ten keystrokes into two.
You have defined two aliases. Can you get the shell to show them back to you? Yes. Run alias with nothing after it, no nickname, no equals sign, and it lists every alias currently defined in this shell, one per line.
This is the form you reach for when you sit down at a machine and want to know what shortcuts are already set up. Ask the shell to list them all:
alias
prompt: student@linuxcamp:~$ answer: alias output: alias gs='git status' alias ll='ls -alF' hint: Just the one word and Enter, nothing after it: alias
In this sandbox the list holds only the two aliases you just made. On a real machine, bare alias also prints whatever aliases your ~/.bashrc loaded at login, so your list will be longer and different from what is shown here. That is expected: alias reports the live set for THIS shell. Notice one detail the shell does everywhere: it prints the command back in single quotes, 'git status', even though you typed double quotes. Both kinds of quote work for defining; the listing just standardises on single quotes when it shows them to you.
The full list is useful, but sometimes you want just one answer: what does ll actually stand for on this machine? Hand alias a single nickname with no equals sign, and it prints that one alias definition and nothing else.
Two words, alias then the nickname, and it works like a dictionary lookup. Ask it what ll means:
alias ll
prompt: student@linuxcamp:~$ answer: alias ll output: alias ll='ls -alF' hint: The word alias, a space, then just the nickname ll, with no equals sign: alias ll
One line back: alias ll='ls -alF'. By naming ll with no =, you asked a question instead of making a definition, and the shell answered with that single nickname's meaning. This is how you check an alias before you trust it. If you ever type ll and get a surprise, alias ll tells you exactly what the shell is really running underneath.
Aliases are not only for saving keystrokes. They can also add a safety net. The rm command deletes files, and by itself it deletes them instantly with no second chance. Add the -i flag and rm asks remove this file? before each delete, giving you a moment to say no.
Many engineers alias rm to always include that flag, so the safe behaviour becomes the default. It is a two-word command, so quote the whole thing:
alias rm="rm -i"
prompt: student@linuxcamp:~$ answer: alias rm="rm -i" output: hint: Nickname and command are both rm here. Type alias rm, equals, then rm -i in double quotes: alias rm="rm -i"
This shows the great gotcha of aliases. An alias only expands when the nickname is the FIRST word of a line, and only in an interactive shell like this one, not automatically inside scripts. That first-word rule is also a risk: give a real command like rm a broken definition and you can mask the real tool until you remove the alias, which is a job for unalias, the very next lesson. Redefining rm to add -i, as above, is a common and safe habit. Just know that whatever rm runs from now on in this shell is your alias, not the bare command.
Scaffolding off. No command is printed this time. You have every piece you need.
You are tired of typing ls -alF in full. Create an alias named la that runs ls -A, so that typing la from now on lists everything including hidden files. Remember the three parts, the word, the nickname, and the command in quotes, and remember there are no spaces around the equals sign.
prompt: student@linuxcamp:~$ answer: alias la="ls -A" output: hint: Recall the shape: alias, then the nickname la, then equals with no spaces, then the command ls -A wrapped in double quotes.
That is the everyday move. The word alias opened the definition, la is the nickname, and "ls -A" in quotes is the command it now stands for. The shell recorded it in silence, and la will run ls -A for the rest of this session. You built the whole shape from memory, the word, the name, the equals with no spaces, and the quoted command, which is exactly the recall a real machine asks of you.
You earned this cheat sheet. Every row is a form of alias you just ran:
The rules that make it all work: quote the whole command string, put no spaces around the =, and remember an alias only expands as the FIRST word of a line, in an interactive shell.
Every alias you make lives only in the current shell and vanishes when you close it. To make an alias permanent, you put its alias line inside ~/.bashrc, a file the shell reads every time it starts. That file gets its own lesson later in this module. For now, defining aliases by hand is exactly the right way to learn the shape.
The practice terminal has shown you the shape of alias. You can define a nickname, list them all, look one up by name, and add a safe default to a real command. 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 use alias 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: variables, exports, the command lookups, expansions, quoting, and the aliases you just learned. 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 set up a real shell for yourself.
Practice alias in a real Linux terminal at The Linux Camp. Progress is verified automatically as you type commands on the machine.