Introduction
Hello! In this article, we’ll learn about the alias command.
alias is a command that lets you shorten long commands or give alternative names to commands you use frequently. Using this makes your work way easier.
What is the alias Command?
alias is a command for giving alternative names (aliases) to commands.
For example, isn’t it annoying to type git status over and over? You can make it so just gs runs it, stuff like that.
Basic Syntax
|
|
Usage Examples
Example 1: Basic Usage
|
|
Now typing ll runs ls -la.
Example 2: Using an Alias
|
|
Output:
|
|
Example 3: List Current Aliases
|
|
Output:
|
|
Shows all currently set aliases.
Example 4: Check a Specific Alias
|
|
Output:
|
|
Example 5: Remove an Alias
|
|
This removes the ll alias.
Common Alias Examples
|
|
Tips & Notes
-
Temporary setting: Gone when you close the terminal
1alias ll='ls -la' # Gone when terminal closes -
Make it permanent: Write in
.bashrcto persist1 2 3# Add to ~/.bashrc alias ll='ls -la' alias gs='git status' -
Use single quotes: Double quotes expand variables, so use single quotes
1alias mydir='cd ~/my/directory' # Correct -
Run without alias: Prefix with backslash to run the original command
1 2alias rm='rm -i' \rm file.txt # Delete without confirmation -
With spaces: Need to properly quote it
1alias update='sudo apt update && sudo apt upgrade'
Practical Usage
Shorten Dev Commands
|
|
Move to project folder and open VS Code - all in one command.
Shorten Long Commands
|
|
Shorten frequently used docker options.
Typo Prevention
|
|
Make aliases for commands you often mistype (lol).
.bashrc Example
|
|
Writing in .bashrc like this is convenient.
Summary
In this article, we learned about the alias command.
Key Points:
- Give alternative names to commands with
alias - Can shorten long commands - very convenient
- Write in
.bashrcto make permanent - Actively aliasing frequently used commands boosts efficiency
As you get used to it, you’ll think “Let’s alias this too” and keep adding more. Find commands you use often and alias them - makes work so much easier.
Keep learning Linux commands!