1

In bash on Linux platforms, I can write an alias that performs a command, such as:

alias cdpics='cd /home/me/Pictures; ls -l'

Which will change to my Pictures folder and list its contents. And even use it to override commands:

alias sudo='echo;cd'

Which will make the sudo command echo what they pass to it, then change to their home holder. Is there a way to do this on the Windows command prompt - particularly the latter example? for instance, can I have the dir or tree command instead execute a batch file?

atom8bit
  • 106

2 Answers2

1

Can I have the dir or tree command instead execute a batch file?

You can use doskey for this:

doskey dir c:\batch\mydir.cmd
doskey tree c:\batch\mytree.cmd

See Doskey - recall commands - Windows CMD - SS64.com

Qwerty
  • 586
DavidPostill
  • 162,382
0

.cmdrc, the most convenient unix-like experience

If you are looking for a bash-like experience, this is the closest you can get.

  • Loads automatically with every instance of cmd
  • Doesn't require keyword DOSKEY for aliases
    example: ls=ls --color=auto $*
  • Supports arbitrary commands (e.g. custom welcome prompt, etc.)

See this QA for details How to set an alias in Windows Command Line?

cmd greetings & aliases

Qwerty
  • 586