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
alias shortcut='original command with parameters'

For example:

1
2
alias ll='ls -la'
alias gits='git status'

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
nano ~/.bashrc

Add your aliases:

1
2
3
4
5
# Useful shortcuts
alias ll='ls -la'
alias cls='clear'
alias update='sudo apt update && sudo apt upgrade'
alias gitc='git commit -m'

Apply changes by sourcing the file:

1
source ~/.bashrc

Zsh Users

Edit ~/.zshrc with similar syntax:

1
2
3
4
# Zsh aliases
alias gco='git checkout'
alias gp='git push'
alias gs='git status'

Managing Unix Aliases

List all defined aliases:

1
alias

Remove an alias:

1
unalias ll

Create function-like aliases with parameters:

1
2
3
4
# In your .bashrc or .zshrc:
mkcd() {
mkdir -p "$1" && cd "$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
doskey alias_name=original_command $*

Examples:

1
2
3
doskey ls=dir $*
doskey clear=cls
doskey gits=git status

The $* passes all arguments to the original command.

Permanent Aliases in CMD

  1. Create a batch file:

hnew.bat in Location C:\custom_cmd;

1
2
@echo off
pnpm hexo new %*
  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
Set-Alias -Name alias_name -Value original_command

Examples:

1
2
Set-Alias -Name ll -Value Get-ChildItem
Set-Alias -Name grep -Value Select-String

For more complex commands, create a function and alias it:

1
2
function Git-Status { git status }
Set-Alias -Name gits -Value Git-Status

Permanent Aliases in PowerShell

Create a PowerShell profile file if you don’t already have one:

1
2
3
4
if (!(Test-Path -Path $PROFILE)) {
New-Item -ItemType File -Path $PROFILE -Force
}
notepad $PROFILE

Add your aliases to this file:

1
2
3
4
5
6
7
8
9
10
# Simple aliases
Set-Alias -Name ll -Value Get-ChildItem
Set-Alias -Name grep -Value Select-String

# Function-based aliases
function Start-ProjectRepo {
Set-Location C:\Projects
git status
}
Set-Alias -Name proj -Value Start-ProjectRepo

Managing PowerShell Aliases

List all aliases:

1
Get-Alias

Remove an alias for current session:

1
Remove-Alias -Name alias_name

Best Practices for Command Aliases

  1. Keep it intuitive: Choose alias names that clearly relate to their function
  2. Don’t override essential commands: Avoid replacing built-in commands with dramatically different behavior
  3. Document your aliases: Add comments in your config files explaining complex aliases
  4. Standardize across machines: Consider using a version control repository for your alias configurations
  5. Start small: Begin with a few key shortcuts and add more as needed

Command Aliases: Boosting Productivity in Windows and Unix Systems
https://www.hardyhu.cn/2025/04/08/Command-Aliases-Boosting-Productivity-in-Windows-and-Unix-Systems/
Author
John Doe
Posted on
April 8, 2025
Licensed under