Use Unix Commands in Windows' Built-In Command Prompt
Posted by Kevin Purdy at 2:45 AM on March 1, 2008

Lifehacker reader Michael writes in with a nifty tip that was lurking in our comments all along, but deserves to see the bright light of posting. If you're already using the Unix-like Cygwin, it's an easy hack to embed Cygwin's commands into your standard Windows comand prompt; if not, it might be worth checking out the free download. The instructions follow after the jump.
These instructions are for Windows Vista, but fairly similar to the process in Windows XP (check out an XP-specific environment variable tutorial for more clarification.) The steps:
- Find out where your Cygwin installation is on your hard drive and copy the path to its \bin subfolder (usually C:\Cygwin\bin).
- Open the Control Panel, hit "System and Maintenance," then "System," then "Advanced System Settings" on the left.
- Click the "Environment Variables" button at the bottom of the new window.
- Scroll through the "System Variables" list at the bottom of this window until you find the line for "Path," then select it and hit "Edit."
- Add a semi-colon to the end of the "Variable Value" line (if it's not there), then add the path to Cygwin's bin directory. Hit OK on this and any windows opened along the way.

Comments (AU Comments · US Comments)
There are currently no AU comments for this post.
mr_oshodi
Posted 3:42 AM 1/3/08
it works great but just a little slow compared to dir...but still the latency is not bad..
mr_oshodi
mr_oshodi
Posted 3:42 AM 1/3/08
sweet. Another reason to love LH. For those tho are confused with step 2 above..
You can also hit the Windows logo button + Pause button at the same time and go to the advanced tab and at the bottom will be the Environment varibales....then follow the rest of the instructions above.
mr_oshodi
Poob
Posted 3:42 AM 1/3/08
Great tip! You can apply this method to many other applications too =)
Poob
dritan
Posted 4:07 AM 1/3/08
Also check out the gnuwin32 project ([gnuwin32.sourceforge.net]). Windows versions of many Linux command-line utilities are available. They can be installed individually without Cygwin.
dritan
rubbsdecvik
Posted 4:07 AM 1/3/08
Gotta love cygwin
rubbsdecvik
altherac
Posted 4:07 AM 1/3/08
You could use a native port too, such as [unxutils.sourceforge.net]
It's simpler than Cygwin when you just need a few regular Unix commands such as ls/grep/tail... You need to set up your path as described in the article.
altherac
fredramsey
Posted 4:07 AM 1/3/08
C:\Windows\System32>copy con ls.bat
@echo off
dir/w
^z
C:\Windows\System32>
Low tech, but easy to do... You could delve further into batch language and make it as fancy as you wanted to.
fredramsey
jarmod
Posted 4:32 AM 1/3/08
I still don't quite see why you'd want to install Cygwin in the first place. I have a native Windows 'grep' so that's catered for already. I can't see any good reason to want to run "ls -l" (or variant thereof). I use SysInternal process utilities so 'ps' is no use to me.
Are there some really compelling reasons to install Cygwin?
jarmod
Duncan Sample
Posted 4:32 AM 1/3/08
I agree with @altherac, unxutils is a much lighter weight solution to Cygwin. Personally, I use Linux quite a lot and couldn't didn't like Cygwin very much.
Duncan Sample
weezuhl
Posted 4:57 AM 1/3/08
@jarmod: I use it for openssh server and rsync, which I didn't see in GnuWin32 or unxutils, but there are probably alternative ways to get those on a windows machine.
weezuhl
uglysmurf
Posted 5:22 AM 1/3/08
this trick used to cause gaim/pidgin to choke on startup...not sure if that's still a problem, but we wary of it...
uglysmurf
jafac
Posted 5:22 AM 1/3/08
aw hell, I didn't know you could run the cygwin tools inside a CMD instance, I thought you had to be in bash.
Here's another nice tip:
In XP, it was VERY annoying that your Cygwin user directory was /home/(username), but your Windows user directory was c:\documents and settings\(username).
Well, in Vista, Microsoft finally did something right - and when you install Cygwin on Vista - it picks up on this - and BOTH user directories are now in the same location: c:\users\(username). yay!
jafac
FruitSmack
Posted 5:22 AM 1/3/08
Another way to get *nix-like functionality on Windows is with UnxUtils. I use them at work on my Windows box. They're a batch of *nix utilities that have been ported to run on MS's operating system.
I prefer it to cygwin, personally.
FruitSmack
Morton Fox
Posted 5:46 AM 1/3/08
@jarmod: I was developing a Pidgin plugin on Windows and the build environment needed Cygwin and MinGW.
Generally though, I agree. Most users will do just fine with native Windows utilities and GnuWin32/unxutils to fill in the gaps.
Morton Fox
ian320
Posted 5:46 AM 1/3/08
@uglysmurf: Tried it out on Windows Vista. Restarted Pidgin and it started fine and works the same as before.
ian320
srh
Posted 6:32 AM 1/3/08
I've found a much more elegant solution than making cygwin commands available in cmd.exe, is to make windows commands available in cygwin.
I use Windows XP, and just added '/cygdrive/c/WINNT' to my path.
Now I can open a windows explorer in my current cygwin dir with "explorer ."
I can manage my network connections with ipconfig.
All from within tcsh (or sh, if you prefer).
srh
PReDiToR
Posted 6:58 AM 1/3/08
@jarmod
How about getting the GNU C compiler for free, rather than some very expensive proprietary compiler from Borland or Microsoft?
PReDiToR
xxdesmus
Posted 7:22 AM 1/3/08
@FruitSmack: Thank you for the link to this, it looks great.
xxdesmus
Posco Grubb
Posted 8:13 AM 1/3/08
@srh: Yeah, this is more useful.
Cygwin doubters: The thing you gain from running Cygwin is not just look-alike utilities. It's a more sane shell! Or, at least, a more familiar shell. I just haven't taken the time to learn the Windows command shell. Simple things like shell variables, redirection and pipes, backgrounding jobs, pushing and popping directories. It's just easier for some of us to use bash (or tcsh).
@fredramsey: Meh, not the same. Ls has a lot of fun and useful options.
Posco Grubb
sebu
Posted 9:18 AM 1/3/08
If you find your cmd.exe / cygwin shell too limited:
Use the Cygwin installer to set up a SSH server on your Windows machine (there are good, short tutorials about this), and then log in into this SSH server from the same machine by using Putty. Then you have all the readline goodness :-)
If you use Putty on a regular basis, and have a working set up with key-based authenciation (Pageant), then this even works without entering your password.
Sebastian
sebu
scottcoulter
Posted 9:18 AM 1/3/08
I can't remember the last time I started up a plain old Windows cmd shell. I use cygwin's rxvt almost exclusively. I highly recommend it.
scottcoulter
ffejie
Posted 2:06 PM 1/3/08
Be sure to not include a space between the path and the semi-colon. I screwed that up.
ffejie
tomstrummer
Posted 12:30 AM 2/3/08
unfortunately this doesn't work for commands that take a path (like cp). It expects the path to. Be in unix format which usually doesn't play nice in CMD.
I use rxvt for my terminal, which looks better under XP.
tomstrummer
brianary
Posted 4:41 AM 2/3/08
Of course, putting the unix command directory at the end of the Path means any Windows versions of the commands will still be used, since their directory appears earlier in the Path.
brianary
coonj
Posted 4:32 AM 5/3/08
This is a great idea if you have a Windows machine at home and prefer Linux (how that happened...I don't know).
But at work, you might want to make sure everyone who uses a command prompt installs Cygwin (or whatever you choose) as well. If you start running UNIX commands, and write up documentation or create a script, everyone on your team may need Cygwin. And then if someone on your team is working with another team, same thing...
Maybe it's just because I don't like mixing Windows and UNIX
coonj
yabadaba
Posted 6:25 AM 11/3/08
Another port of Unix like commands ported to Windows is Janotech (www.janotech.com). The neat thing about this command line environment is that it is completely graphical (uses Windows GUI) and there is a free demo download.
yabadaba
Mapex
Posted 7:41 AM 13/3/08
I've been looking for this functionality for a long time, and I never actually knew what cygwin did (at least, the only time it came up in my life was when I was younger and didn't know any better about UNIX :P). Regardless, I just installed cygwin literally 5 minutes ago, and what srh said is true - it is better to get Windows working inside cygwin's bash shell as opposed to the UNIX utilties inside the Windows Command Prompt.
For me, all I had to do was run the setup.exe on from [cygwin.com] on the first page, let it install all the minimal requirements. I didn't have to edit a thing - seems the newer cygwin files automatically add the Windows folder to its $PATH for you. I can access everything just by spending 10 seconds hitting Next throughout the installation. I also changed my installation directory to D:\cygwin (I use a three partition setup, and I reserve C solely for my Windows install and anything else that is forced to install on C) and this works just fine as well. No problems, happy as hell here, added the cygwin shortcut to my RocketDock.
This Windows machine is more UNIX than Windows. I have bash instead of cmd. I have Avant Window Navigator in the form of RocketDock. Now I just need four desktops (not the way PowerToys does it, which sucks by the way) and Compiz Fusion and Emerald. And then I need to lose all DirectX support, lol.
Mapex