On linux, you can create aliases for commonly used commands. These can be pretty much anything you like. Here’s an example, which creates a command called ports
, which runs the stuff in quotes:
# List all the ports that are currently open, with the processes that are listening
alias ports="sudo netstat -tulpn | grep '^tcp' | awk '{print \$1,\$4,\$7}' | sort -n | uniq | column -t"
On Windows, PowerShell does support aliases, but doesn’t support parameters - they’re intended to just be single PowerShell Verb-Noun
things, I think?
Anyway, if you want to run a command with some parameters, you have to create a function.
Here’s an example of creating a simple shortcut for git status
:
Bash version:
# git status shortcut
alias gst='git status'
PowerShell version:
function GitStatus {git status}
New-Alias -Force -Name gst -Value GitStatus
Where are PowerShell aliases stored?
PowerShell aliases are stored in various places, but this is probably the file you want to edit: $Home\[My ]Documents\PowerShell\Microsoft.PowerShell_profile.ps1
. This is also stored in the $PROFILE
variable:
notepad $PROFILE