0
0
Linux CLIscripting~5 mins

Aliases for shortcuts in Linux CLI - Commands & Configuration

Choose your learning style9 modes available
Introduction
Typing long commands repeatedly can be tiring and slow. Aliases let you create short nicknames for these commands, saving time and effort.
When you often run a long command like 'ls -la' and want a quick shortcut.
When you want to fix a common typo by creating an alias that corrects it automatically.
When you want to customize commands with your favorite options without typing them every time.
When you want to create easy-to-remember shortcuts for complex commands.
When you want to speed up your work in the terminal by reducing typing.
Commands
This command creates a shortcut named 'll' that runs 'ls -la' to list all files with details.
Terminal
alias ll='ls -la'
Expected OutputExpected
No output (command runs silently)
Runs the alias 'll' which lists all files in long format including hidden files.
Terminal
ll
Expected OutputExpected
total 8 drwxr-xr-x 3 user user 4096 Apr 27 10:00 . drwxr-xr-x 10 user user 4096 Apr 27 09:00 .. -rw-r--r-- 1 user user 18 Apr 27 10:00 example.txt
Creates an alias 'gs' to quickly check the status of your git repository.
Terminal
alias gs='git status'
Expected OutputExpected
No output (command runs silently)
Runs the alias 'gs' which shows the current git status.
Terminal
gs
Expected OutputExpected
On branch main Your branch is up to date with 'origin/main'. nothing to commit, working tree clean
Removes the alias 'll' when you no longer want to use it.
Terminal
unalias ll
Expected OutputExpected
No output (command runs silently)
Key Concept

If you remember nothing else from this pattern, remember: aliases let you create easy shortcuts for long commands to save time.

Common Mistakes
Creating an alias without quotes around the command.
The shell may misinterpret the command or only alias part of it, causing errors.
Always put the full command inside single quotes, like alias ll='ls -la'.
Defining aliases only in the current terminal session.
Aliases disappear when you close the terminal, so you lose your shortcuts.
Add alias commands to your shell config file like ~/.bashrc or ~/.zshrc to keep them permanent.
Trying to alias commands that require arguments without handling them.
Aliases do not accept parameters, so they won't work as expected with arguments.
Use shell functions for commands needing arguments instead of aliases.
Summary
Use the alias command to create shortcuts for long or frequent commands.
Run the alias name to execute the shortcut command quickly.
Remove aliases with unalias when they are no longer needed.