📖 Scenario: You often type long commands in the Linux terminal. To save time, you want to create shortcuts called aliases. Aliases let you type a short word instead of the full command.For example, instead of typing ls -la every time, you can create an alias ll that runs ls -la.
🎯 Goal: Create aliases in the Linux shell to make common commands shorter and easier to use.
📋 What You'll Learn
Create an alias named ll for the command ls -la
Create an alias named gs for the command git status
Create an alias named .. for the command cd ..
Display the list of all current aliases
💡 Why This Matters
🌍 Real World
Aliases help Linux users work faster by reducing repetitive typing of long commands.
💼 Career
Many IT, DevOps, and developer roles use shell aliases daily to improve productivity and efficiency.
Progress0 / 4 steps
1
Create the first alias
Create an alias named ll for the command ls -la using the syntax alias ll='ls -la'.
Linux CLI
Hint
Use the alias command followed by the alias name, an equals sign, and the command in single quotes.
2
Add more aliases
Add two more aliases: gs for git status and .. for cd ... Use the syntax alias gs='git status' and alias ..='cd ..'.
Linux CLI
Hint
Each alias uses the same alias name='command' format on its own line.
3
Use the aliases
Use the alias ll to list all files with details by typing ll in the terminal.
Linux CLI
Hint
Just type the alias name ll and press Enter to run the shortcut command.
4
Show all aliases
Display all current aliases by typing the command alias.
Linux CLI
Hint
Just type alias and press Enter to see all aliases.
Practice
(1/5)
1. What does the command alias ll='ls -l' do in a Linux shell?
easy
A. Runs the ls -l command immediately
B. Deletes the ll command permanently
C. Lists all aliases currently set
D. Creates a shortcut named ll that runs ls -l
Solution
Step 1: Understand the alias syntax
The command alias name='command' creates a shortcut named name for the given command.
Step 2: Apply to given example
Here, ll is set as a shortcut for ls -l, so typing ll runs ls -l.
Final Answer:
Creates a shortcut named ll that runs ls -l -> Option D
Quick Check:
alias creates shortcut = A [OK]
Hint: Alias syntax is alias name='command' to create shortcuts [OK]
Common Mistakes:
Thinking alias runs the command immediately
Confusing alias with deleting commands
Assuming alias lists all commands
2. Which of the following is the correct syntax to create an alias named gs for the command git status?
easy
A. alias gs = git status
B. alias gs='git status'
C. alias 'gs' = 'git status'
D. alias gs: git status
Solution
Step 1: Recall correct alias syntax
The correct syntax is alias name='command' without spaces around the equal sign.
Step 2: Match options to syntax
alias gs='git status' matches exactly: alias gs='git status'. Others have spaces or wrong punctuation.
Final Answer:
alias gs='git status' -> Option B
Quick Check:
Correct alias syntax = B [OK]
Hint: No spaces around = and use single quotes for commands [OK]
Common Mistakes:
Adding spaces around equal sign
Using colons or other punctuation instead of =
Putting quotes around alias name
3. Given the alias alias ll='ls -l' and the command ll /tmp, what will be the output?
medium
A. Lists files in /tmp in long format
B. Shows an error: command not found
C. Lists files in current directory only
D. Prints the text 'll /tmp'
Solution
Step 1: Understand alias expansion
The alias ll replaces ll with ls -l when typed.
Step 2: Apply alias with argument
Typing ll /tmp runs ls -l /tmp, listing files in /tmp in long format.
Final Answer:
Lists files in /tmp in long format -> Option A
Quick Check:
Alias expands command with arguments = A [OK]
Hint: Alias replaces command name but keeps arguments [OK]
Common Mistakes:
Thinking alias ignores arguments
Expecting alias to print text
Assuming alias causes error
4. You run alias ll='ls -l' but typing ll gives an error: command not found. What is the likely problem?
medium
A. The alias was set in a different shell session
B. You typed the alias command incorrectly
C. You forgot to export the alias
D. The ls command is missing
Solution
Step 1: Understand alias scope
Aliases last only for the current shell session unless saved in config files.
Step 2: Identify cause of error
If you set alias in one session but use another, the alias is not known, causing 'command not found'.
Final Answer:
The alias was set in a different shell session -> Option A
Quick Check:
Aliases are session-specific unless saved = C [OK]
Hint: Aliases vanish when shell closes unless saved [OK]
Common Mistakes:
Thinking aliases need export
Assuming alias command syntax error
Blaming missing system commands
5. You want to create an alias update that runs sudo apt update && sudo apt upgrade -y. Which command correctly creates this alias so it works as expected?
hard
A. alias update='sudo apt update; sudo apt upgrade -y'
B. alias update = "sudo apt update && sudo apt upgrade -y"
C. alias update='sudo apt update && sudo apt upgrade -y'
D. alias update='sudo apt update & sudo apt upgrade -y'
Solution
Step 1: Understand command chaining in alias
The && operator runs the second command only if the first succeeds, which is desired here.
Step 2: Check alias syntax and chaining
The correct form is alias update='sudo apt update && sudo apt upgrade -y', which uses no spaces around =, single quotes, and && for conditional chaining. Forms with spaces around = cause syntax errors. Using ; runs the upgrade regardless of update's success. Using & runs upgrade in background.
Final Answer:
alias update='sudo apt update && sudo apt upgrade -y' -> Option C
Quick Check:
Correct alias syntax with && = D [OK]
Hint: Use && to run second command only if first succeeds [OK]
Common Mistakes:
Using single & instead of &&
Using ; which ignores success of first command
Mixing quote types incorrectly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.