How to make DOS look like Unix

July 19, 2005, 11:45 AM —  ITworld.com — 

Ok, well maybe the subject line of this column is stretching it just a wee bit. There's no way that you can emulate more than a small fraction of Unix power at the DOS Command Prompt. But DOS has grown quite a bit since the days when it was an operating system in its own right. With pipes and redirection, a pile of commands that are roughly equivalent to their Unix counterparts (dir is to ls what type is to cat) and a little finesse, you can make your time working in DOS seem a little less like a detour through the dark ages and a little more like home.



To begin our little makeover, let's look at the typical DOS command prompt. When I open a command prompt on my Windows XP Professional laptop, I see something like this:

C:\Documents and Settings\shenry-stocker\Desktop>


Not so bad, you might be thinking, but any prompt that stretches more than halfway across MY screen is too much prompt for me. Can I change this the way I can change my prompt on a Unix system (e.g., setting PS1="\h> ")? Yes, in fact I can. For a minimalistic prompt, I like using something like this:


prompt=$G$S


This will change the DOS prompt to "> ". The $G represents the greater-than and $S is a space.


The default prompt on DOS is usually $P$G -- the current path followed by a > and you can change it back as easily:



prompt=$P$G



Many other variables can be also be used in the prompt string:


$Q  	= (equal sign)
$$ 	$ (dollar sign)
$T 	Current time
$D 	Current date
$P 	Current drive and path
$V 	Windows version number
$N 	Current drive
$G 	> (greater-than sign)
$L 	& (less-than sign)
$B 	| (pipe)
$H 	Backspace (erases previous character)
$E 	Escape code (ASCII code 27)
$_ 	Carriage return and linefeed


Some of these (such as $V) make a perfectly hideous and worthless prompt, but others can be advantageous at times -- such as $T$G$S when you're watching the clock on a Friday afternoon.



Defining Macros



To clear the screen in DOS, use the cls command. It works just like clear on Unix. And, if you don't like translating between Unix and DOS commands just to clear your screen, you can turn clear into a macro. Macros work like aliases in the Unix shells. To make clear equivalent to cls, for example, you would do this:


doskey clear=cls


Once you type this at the command prompt, you can use "clear" to clear your screen instead of cls -- at least until you open a new DOS command prompt.



So now let's tackle some other annoying near-equivalents. I often find myself typing "ls" at the command prompt when I meant to type "dir". It runs, but it takes a while to get started. If I create a macro to make ls equivalent to dir, on the other hand, the response is quick and I don't feel like such a klutz for not being able to keep my operating systems straight.



Another macro that I find useful is "date=date /t". Every time

I like it!
Post a comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
Resources
White Paper

Symantec Backup Exec 12 and Backup Exec System Recovery 8 deliver industry leading Windows data protection and system recovery. Download this whitepaper to find out the top reasons to upgrade and how to get continuous data protection and complete system recovery.

Webcast

Data and system loss — from a hard drive failure, malicious attack, natural disaster, or simple human error — can happen anytime. Don’t leave your business vulnerable. Make sure you have a secure recovery strategy in place. Symantec's latest backup and system recovery technology can efficiently restore critical applications, individual emails and documents and even restore your entire system in minutes in the event of a loss.

White Paper

Businesses face a growing challenge to ensure that the IT environment is properly protected. Backup Exec 12 integrates with other applications in the Symantec family of products, to complement your current data protection strategy, keep your data securely backed up and make it recoverable when you need it most.

Free stuff

Enterprise 2.0 Implementation
By Aaron C. Newman, Jeremy Thomas
Published by McGraw-Hill
Learn more!

Deploying Cisco Wide Area Application Services
By Zach Seils, Joel Christner
Published by Cisco Press
Learn more!

Featured Sponsor

AISO founders envisioned a Web hosting company that was environmentally friendly. While the company employed energy-efficient innovations like solar panels, its infrastructure produced unacceptable power and cooling requirements. Find out how AISO leveraged AMD technology to overcome their challenge in this case study white paper.

In this whitepaper, Scalar explores the opportunity to change the landscape with respect to mission critical databases built around Oracle. Leveraging technologies such as Linux, high-end commodity processing power and Oracle RAC technology to architect, design, build and maintain database infrastructure that delivers maximum availability, reliability and performance at a fraction of traditional cost.

On a typical day, weather.com, the Web site for The Weather Channel in Atlanta, serves up between 15 million and 20 million page views. But in September 2004, when back-to-back hurricanes ransacked Florida, the peak traffic on one day more than tripled: over 70 million page views by more than 7 million unique visitors. Read the full success story now.

More Resources