Link to home
Create AccountLog in
Avatar of rortiz77

asked on

Is there a way to create alias in Windows 2008 just like in Linux Bash?

Is there a way to create aliases in DOS command prompt just like in Linux Bash?  I know of Doskey but how does it keep your information?  If I exit it gets lost.  Is there a profile that can be created to allow it to save it?
Avatar of Chris
Flag of United Kingdom of Great Britain and Northern Ireland image

you can use the set command but that won't keep it out of that session


set backupshare=\\mycompany-dc01\backup
Avatar of farzanj
Flag of Canada image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Use setx /m command line
Avatar of rortiz77


Farzanj's looks a bit easier to work with.  

Govvy, can you give an example of how it would work with SETX? For example, how would I alias ls=dir?
This is the error I get:

C:\>setx LS DIR /M
ERROR: Access to the registry path is denied.
Easier way probably is just add a batch file called ls to your path, i.e. enter this in notepad and call it c:\windows\ls.cmd

@dir %*

The %* will pass any command line options to the apps.

If this is Win7 etc. you would need to do it as an admin, e.g.  start cmd.exe prompt as admin then:

cd /d c:\windows\system32
echo @DIR %* > ls.cmd

Your command prompt needs to be run as Administrator

Didn't work as expected.


SUCCESS: Specified value was saved.

'LS' is not recognized as an internal or external command,
operable program or batch file.
setx sets environment variables.... not aliases of commands, unless I am missing another use?

Yeah, that's what it seems to me.  And what I'm trying to do is just use aliases that can be stored for future use.  
Have you tried little one line (or whatever needed) batch files like suggested then?

Yeah, I tried this but it seems like I'd need a file per alias.  Is that correct?
yes... unless you want a generic name, e.g.

u ls

so you have u.cmd whcih takes first param as shortcut etc...

but easier then to type dir!
I did originally think I might be able to use the AppPaths area of the registry but have never been able to get it to work other than subsituting one exe for another, i.e. you can add in here:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\App Paths

or here

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\ls.exe]

and ls.exe will launch cmd.exe, like in the same way that if you run "write.exe" it runs wordpad for you.... BUT I haven;t been able to add any command line arguments, and you'd have to do:

cmd /c dir

As to doskey.... you could stick a number of doskey entries in a batch file, or you can call it with a macro:

@echo off
doskey /macrofile=c:\somepath\doskey-macro.txt
cmd /k

doskey-macro.txt contains


You can amend registry entries so that a batch autoruns when launching a cmd.exe session or just use a shortcut to this batch to start yourself a cmd windows with them in place.

Alternatively if you haven't looked at it in the link given by fanranj above it shows similar where doskey is added to the autorun key I mention above and an alias defined of "alias".  Therefore you can add aliases in the same way as you are used to with unix shells... clever stuff!

Haven't had a chance to try it like this but looks like it could be useful.

Well, the world of registries has always been a bit of a mystery.  What all would I have to add in there?
This is following the path:
"HKEY_CURRENT_USER\Software\Microsoft\Command Processor"
Right click the command processor and choose New --> String Value
Value name is "AutoRun"
Value of it is "C:\somedir\yourscript.cmd"

And then in yourscript.cmd either

@doskey /macrofile=c:\somepath\doskey-macro.txt

and then list all your macros in doskey-macro.txt

or list them all one by one:

@echo off
doskey ls=dir
doskey cat=type


cat / ls / grep is about the limit of my unix shell usage so make the rest up yourself :-)
Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account

This looks exactly like what I want!  So, I understand the "Save" part...but it doesn't look like I need to type "LOAD" to use the aliases.  When would I use that?
Very good job with explaining :-)
sorry was away at fireworks display with the kids.... I think the idea is ... Any aliases you add is like using doskey command, i.e only for that session.  so alias save makes them permanent.  alias load i guess would only be needed if you messed up the aliases and/or wanted to put them back as they are.

Have enabled this in my own cmd prompt now too - had seen technique befoe but not as neat as with making an alias alias!

thanks.  cant't believe all that was only 900 points mind :-(