5

I've found a few posts on command line aliases in Windows but most of them relate to aliasing long cd commands/paths that are frequently used and I can't make them work for my needs.

In my case, I flip back and forth between Windows and MacOS on a semi-frequently basis when I use command prompts. Since I'm back and forth between the two, habitually I'll enter ls or dir in one or the other and get an obvious error.

Specific to this question, what I'd like to do is map some type of alias of "ls" to "dir", so that if I accidentally enter "ls", I get the same functionality as the "dir" command. I don't need any complex parameter mapping, just a simple alias for ls to dir.

If there is a solution that works for cmd, I'd appreciate the guidance.

RLH
  • 4,665

2 Answers2

4

In PowerShell both dir and ls have the same effect, one is an alias of the other.

harrymc
  • 498,455
1

In PowerShell, such an alias is already present by default. (More precisely, both ls and dir are aliases to the Get-ChildItem cmdlet. It also has default aliases for cat, rm, etc.) So just use DOSKEY for Cmd alone.

Similar to Bash, PowerShell has aliases and shell functions:

Set-Alias -Name ls -Value Get-ChildItem
Set-Alias -Name vim -Value notepad.exe
Remove-Item -Path Alias:curl -ErrorAction Ignore
Function kssh {ssh -o PreferredAuthentications=gssapi-with-mic $args}

DOSKEY defines aliases at console window level; they work in Cmd because it reads a whole line at a time and lets the console handle the actual input (file tab-completion is also provided by the console) but don't work in PowerShell because it reads keys in "raw" mode, one key at a time (it has its own 'PSReadline' much like Bash's readline).

grawity
  • 501,077