Command Aliases: Boosting Productivity in Windows and Unix Systems
Working efficiently at the command line can dramatically increase your productivity as a developer or system administrator.
One of the simplest yet most powerful techniques is creating command aliases - custom shortcuts for frequently used commands.
This guide explores how to set up and manage command aliases in both Windows and Unix-based systems.
Unix-Based Systems (Linux, macOS, BSD)
Temporary Aliases
In Unix-based systems, you can create a temporary alias that lasts only for the current terminal session:
1 |
|
For example:
1 |
|
These aliases will be available immediately but will disappear once you close the terminal.
Permanent Aliases
To make aliases persist across sessions, add them to your shell’s configuration file:
Bash Users
Edit ~/.bashrc
or ~/.bash_profile
:
1 |
|
Add your aliases:
1 |
|
Apply changes by sourcing the file:
1 |
|
Zsh Users
Edit ~/.zshrc
with similar syntax:
1 |
|
Managing Unix Aliases
List all defined aliases:
1 |
|
Remove an alias:
1 |
|
Create function-like aliases with parameters:
1 |
|
Windows Command Prompt
Windows Command Prompt has a different approach to aliases, which are called “doskey macros” in this environment.
Temporary Aliases in CMD
To create a temporary alias in Command Prompt:
1 |
|
Examples:
1 |
|
The $*
passes all arguments to the original command.
Permanent Aliases in CMD
- Create a batch file:
hnew.bat
in Location C:\custom_cmd
;
1 |
|
- Set up a registry key to run this file every time Command Prompt starts:
Add C:\custom_cmd
.
Windows PowerShell
PowerShell offers more powerful alias capabilities than Command Prompt.
Temporary Aliases in PowerShell
Create a temporary alias:
1 |
|
Examples:
1 |
|
For more complex commands, create a function and alias it:
1 |
|
Permanent Aliases in PowerShell
Create a PowerShell profile file if you don’t already have one:
1 |
|
Add your aliases to this file:
1 |
|
Managing PowerShell Aliases
List all aliases:
1 |
|
Remove an alias for current session:
1 |
|
Best Practices for Command Aliases
- Keep it intuitive: Choose alias names that clearly relate to their function
- Don’t override essential commands: Avoid replacing built-in commands with dramatically different behavior
- Document your aliases: Add comments in your config files explaining complex aliases
- Standardize across machines: Consider using a version control repository for your alias configurations
- Start small: Begin with a few key shortcuts and add more as needed