what is the DOS equivalent of alias command?

how do we create aliases to commands in dos?

thanks

Plain DOS does not have support for aliases. You might want to look at 4dos / 4nt or Cygwin.

Or you can use an ordinairy batch file or a VB script.

Actually, an alias to a command can be done in XP. Using regedit I created a subkey called "cpu-z" in "HKLM\SOFTWARE\Microsoft\CurrentVersion\App Paths" with a value of "C:\Utilities\cpu-z\cpuz.exe". And now when I try to run cpu-z, it works. I can replace the value with a path to any program and that works too. Also batch files work, although a cmd window pops up.

One of several little tricks I learned from battling a recent virus.... :mad:

I know I'm rather late on this but it might help others...

You can use doskey to create an alias on any version of windows up to Windows XP (I'm not sure if it's available on Vista).

C:> doskey alias_name=command

doskey will only work within the environment that it's invoked in and if you want the aliases to be available every time you start cmd.exe will need to write a script that will load them upon invoking your cmd prompt (cmd /K "My_Environment_Script.bat").

Example:

I often need to change drives and cd doesn't handle it very well but chdir does. However, the length of the command is tiresome to type every time I need it so I do this...

doskey cdd=chdir /D %1

So when I type:

cdd F:

The command prompt will change to F:>

More information on DosKey can be found here:

DOSKey - Wikipedia, the free encyclopedia

Carlos, if you are trying to just change teh drives, you can simply type drive letter as in below...

C:\Documents and Settings\ilango>f:

F:\>e:

E:\>h:

H:\>c:

C:\Documents and Settings\ilango>

/ilan

PS: ignore my comments if you are just you used this an example in your comment!!

Hello Milhan,

on top of what Pederabo has suggested.., the oter easy way to get working similar to aliases are using a set command..

C:\Documents and Settings\ilango\test>set dira=dir /A

C:\Documents and Settings\ilango\test>dir
Volume in drive C has no label.
Volume Serial Number is 548F-C2AD

Directory of C:\Documents and Settings\ilango\test

04/06/2009 12:13 PM <DIR> .
04/06/2009 12:13 PM <DIR> ..
04/06/2009 12:13 PM 4 normal.txt
1 File(s) 4 bytes
2 Dir(s) 6,269,435,904 bytes free

C:\Documents and Settings\ilango\test>%dira%
Volume in drive C has no label.
Volume Serial Number is 548F-C2AD

Directory of C:\Documents and Settings\ilango\test

04/06/2009 12:13 PM <DIR> .
04/06/2009 12:13 PM <DIR> ..
04/06/2009 12:13 PM 4 hidden.txt
04/06/2009 12:13 PM 4 normal.txt
2 File(s) 8 bytes
2 Dir(s) 6,269,403,136 bytes free

C:\Documents and Settings\ilango\test>

In teh above example, i made simiar to alias - dira to be executed as dir /A, only thing is you will have to use it with percentages.. as in %dira%

/ilan

This approach will not work if you have a directory that have spaces in the path.

C:\Documents and Settings\All Users

To move from a mapped drive, for instance, to a profile directory you would need to use cd or chdir with the "/D" switch and encase the path with quotation marks.

chdir /D "C:\Documents and Settings\All Users"

Therefore my example gives the best way to accomplish the task and keep the typing to a minimum.

Using the "set" command is not, in my opinion, a very efficient way for an alias to be created or used. Simply because of the way it needs to be typed on the command line or in a script. Also you can't use arguments with it.

C:> set dira="chdir /D $1"

C:> %dira% "C:\Documents and Settings\All Users"

The above command will not work. It would work if you only used the command with no argument capture but what would be the point? The whole idea of an alias is to be able to create a command with options and arguments without having to type the entire command every time you want to use it. In these examples we are using "dira." I count 4 characters. To use the "set" method you would be typing 6 characters to produce the same command if you were to use DosKey to produce the alias.

C:> set dira=chdir /D

C:> %dira% "C:\Documents and Settings\All Users"

The "set" command, in my opinion, should only be used to store variables.

Carlos, your idea of using doskey is perfect. approach with set command is one of teh ways that we can achieve that..!!

on the chdir usage, i thought you are trying to switch drives often, i dien't realize that you switch to different directory paths.. overlook!

/ilan