1

Is there an option in command prompt (cmd.exe) that comes with windows to set default command arguments. For example, I may want dir /a every time I run dir to show hidden files. For sake of convenience I would like to set /a to be always enabled even if I don't provide the option.

To get a list of all commands I'm talking about type help at the prompt

2

You want to create cmd aliases. doskey seems to work just fine. Allows you to configure a set of parameters against a text file. This link might be of help to you.

http://www.displayobject.fr/2010/03/07/create-cmd-aliases-in-windows/

Hope this helps

  • ah, haven't used doskey in 20 years and forgot about it. thanks! – Alex Jan 24 '14 at 12:23
  • 1
    Be careful with doskey macros. They only work from the command line. They do not work within batch scripts. – dbenham Jan 24 '14 at 20:49
2

There is no standard, but some commands can get default options from an environment variable.

COPY, XCOPY, and MOVE all can get a default /Y option from the COPYCMD variable. The default value can be overridden with the /-Y option on the command line.

DIR can get any option from the DIRCMD variable. Default environment variable values can be overridden by prefixing the option with - on the command line, for example /-W

There may be other variables to control some other commands, but I am not aware of them.

Unlike DOSKEY macros, the defaults specified by environment variables apply to both batch scripts and the command line.

  • great answer! I wish I could split yours and Matthew's as both accepted. – Alex Jan 25 '14 at 15:37
  • Just noticed that command help also provides this info. dir /? prints following at the bottom: Switches may be preset in the DIRCMD environment variable. Override preset switches by prefixing any switch with - (hyphen)--for example, /-W. – Alex Jan 25 '14 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.