Jump Menu : Content | Explore | Comments | Search | Home | Sitemap | Contact | Login | Access.

Fun with the DOS Command Prompt

Note: This article assumes a basic familiarity with the DOS command prompt, and is somewhat of a continuation of our previous article on DOS, Basic DOS Commands. Here, we are exploring a few of the more interesting commands available via the DOS command prompt. For a more complete reference please consult the Windows Help file (Windows XP) by entering

hh.exe ms-its:C:\WINDOWS\Help\ntcmds.chm::/ntcmds.htm

at the command line prompt (or via the Start > Run... dialogue box). For a brief overview of essential DOS commands, characters, devices, and variables, check out DOS Fundamentals.

Display file contents in DOS window

There are two ways to display the contents of a file through DOS. Both of these methods employ the con (i.e., console, which consists of the keyboard and monitor) device. Here we are displaying the contents of the file atari.exe, which is located within the c:\files\docs\ directory:

(using the copy command)

c:\> copy files\docs\atari.exe con

(using the type command)

c:\> type files\docs\atari.exe con

Create text files in DOS

While working in DOS, it is possible to create text documents easily, on the fly, and without any external text editor. Here, we command DOS to record all keystrokes into a file called note.txt, which we will create in the c:\files\docs\ directory:

(to create the text file and begin recording keystrokes)

c:\> copy con files\docs\note.txt

(to create a new line within the file)

press [ENTER]

(to stop recording keystrokes)

press [F6] or [CTRL+Z and then ENTER]

Add single lines of text to a file

To quickly append lines of text to any file, use the output redirection command as follows:

c:\> echo sometext >> somefile.txt

This will append the text "sometext" to the file "somefile.txt". If the file exists, the line of text will be added to the end of the file. If the file does not exist, it will be created. To overwrite the contents of the file, use this instead:

c:\> echo sometext > somefile.txt

Fun with the nul device

The nul device is like a black hole into which dumped data will simply disappear. You can copy or pipe files or keystrokes into it and they will vanish forever. Thus there are a few fun things that may be done with the nul device.

Here is a way to prevent inexperienced users from using your DOS machine while you are away on break. The following method will create a situation in which a DOS prompt exists, but fails to execute anything. The user will be able to type commands, press enter, and scratch their heads while nothing happens and everything they type is sent directly to the nul hole:

(first type this to initiate the process)

c:\> copy con nul [ENTER]

(then type this to emulate your DOS prompt)

C:\> [DO NOT PRESS ENTER]

(then, to exit the process)

[CTRL+C] or [CTRL+BACK] or [CTRL+Z and then ENTER]

Using the nul device, you can also copy files into nowhere:

c:\> copy somefile.txt nul

..or even pipe nothing into nowhere (yes!):

c:\> copy somefile.txt nul > nul

Print a file through DOS

Although I have as of yet been able to get this method to work, it is theoretically possible to accomplish. This command should send the contents of some file to the printer device (prn):

c:\> copy somefile.txt prn

Convert the output of one process into the input of another process

Piping (via the pipe "|" symbol) is the process in DOS whereby output data becomes input data. Here, sending the contents of script.js to the system debug.exe file:

c:\> type script.js | c:\programs\debug.exe

This same command could also be written as:

c:\> programs\debug.exe < script.js

Send directory listing to a printer or file

This is a very useful method of printing a list of directory contents:

(send directory listing to the printer)

c:\> dir > prn

(send directory listing to somefile.txt)

c:\> dir > somefile.txt

This is a handy way of printing a list of, say, all .mp3 files in a specific directory. Here, we use the wildcard "*" character to select all .mp3 files in the music directory. The list is then printed to the file musiclist.txt, which is located in the c:\files\docs\ directory:

c:\music\> dir *.mp3 > c:\files\docs\musiclist.txt

Roll your own boot log

To create a log file that records system activity status at every reboot, append the following to your system’s autoexec.bat:

echo Another Reboot! >> c:\reboot.log
mode.com >> c:\reboot.log
systeminfo.exe >> c:\reboot.log

Now, upon every reboot (or every time the autoexec.bat file is executed), system status data will be appended to c:\reboot.log, which will be created upon initial execution. Here, the appended data is provided by two functions, mode.com, which displays the status of various system devices (e.g., LPT1, COM1, COM2, CON, etc.), and systeminfo.exe, which displays various system information. Of course, these functions are merely random, demonstrative examples. You would, of course, want to customize your own set of logged data according to your system specifics and diagnostic needs.

Customize the DOS command prompt

The default command prompt specifies the current directory, followed by a "greater-than" (">") symbol and a blinking underscore. There are many options for changing the default prompt, including system variables, normal characters, and preset codes. To begin, check out the list of parameters by entering prompt /? at the command prompt. Note that each variable must be preceded by a dollar symbol ("$"). Here are a few examples for changing the prompt:

Display current directory followed by a greater-than symbol:
prompt $p$g
Display the time after the default prompt:
prompt $p$g$t
Display the computer name followed by the username:
prompt [%computername%] [%username%] $g
Reset the prompt to the default:
prompt

To modify the color of the DOS prompt and screen color, type color followed by two hexidecimal color values of your choice. The first digit sets the background color while the second sets the text color:

Change prompt color to matrix green and screen color to black:
color 0a
Change colors to red on grey:
color 84

Here are a few other basic color choices:

  • 0 = Black
  • 1 = Blue
  • 2 = Green
  • 3 = Cyan
  • 4 = Red
  • 5 = Magenta
  • 6 = Yellow
  • 7 = White
  • 8 = Grey
  • 9 = Bright Blue
  • A = Bright Green
  • B = Bright Cyan
  • C = Bright Red
  • D = Bright Magenta
  • E = Bright Yellow
  • F = Bright White

Note: users may also change colors and other properties via the prompt shortcut itself. Right-click the shortcut and select properties. Have a look around — lots of choices!

Related articles

About this article

This is article #293, posted by Perishable on Monday, January 29, 2007 @ 08:20am. Categorized as Technology, and tagged with code, dos, notes, plus, windows. Updated on January 06, 2008. Visited 42254 times. 20 Responses »

BookmarkSubscribeExplore

« DOS Fundamentals • Up • Feed your Image via Atom or RSS »


20 Responses

1 • March 7, 2007 at 10:26 pm — Noor Isham says:

no comments just question.. i’m sharing my pc with 2 other persons.. is there any dos command to trace when they on/use my pc?

2 • March 11, 2007 at 6:17 pm — Perishable says:

Noor,

I do not know of any way to do this with DOS/command line.. But there are many excellent solutions available to explore:

Good luck!

3 • July 29, 2007 at 3:06 pm — james.m.k says:

Noor Isham,

If you want to do it via dos promt you can add a batch file with the following text into the “All Users” startup Directory ( found at C:\Documents and Settings\All Users\Startup
)

======

echo %Time% %Date% %USERNAME% Has Logged On >> c:\logfile.txt
echo His profile is found at %USERPROFILE% >> c:\logfile.txt

======

It will make a logfile something like this:

12:04:13.12 06/30/2007 Don has Logged On
His profile is found at C:\Documents and Settings\All Users\Don

======

Have fun!

4 • July 29, 2007 at 4:11 pm — Perishable says:

james.m.k,

muchas gracias, señor!

( very kind of you! )

5 • August 12, 2007 at 6:17 am — mike says:

for the printer i think you want “lpt” ive never heard of prn

6 • August 13, 2007 at 7:49 am — Perishable says:

prn and lpt are equivalent in the eyes of DOS:

http://www.tcs.org/ioport/jun98/driver2.htm

7 • November 14, 2007 at 7:54 pm — curious says:

Hi,how can I see the web pages my roommates visited on my computer?

8 • November 18, 2007 at 9:08 am — Perishable says:

Hey curious,
Which version of Windows are you using?

9 • November 23, 2007 at 4:13 am — talen says:

Dear sir
It is a pleasure writing to you this massege,i’m a student in a professional school in Cameroon.I will like to know more about the fundamental fact about DOS command.

thanks in advance

10 • December 14, 2007 at 2:16 am — luke says:

Dear DOS Master
I have a batchfile that sends/gets files via ftp but i would like a log of all information in the dos window

the append command only records certain things and doesnt give me the kb/s information after a file is uploaded or downloaded

can you help?

I need the information which comes
back from the FTP:

how can i get this into a log?

Thanks!

11 • December 16, 2007 at 11:26 am — Perishable says:

Thanks for the question, luke, but I am nowhere near being a “DOS Master”.. (DOS noob, maybe)..

Nonetheless, I will keep your question in mind and see if I can come up with a solution the next time I find myself playing around with DOS :)

12 • December 19, 2007 at 10:10 am — Eric says:

Hey, I’m just wondering, when I go into directory

C:\Program Files\ROBOPro>

and type in

copy roboproen.hlp con

The computer beeps, and on the command prompt is a bunch of garbage. Random letters, along with random alt-codes (e.g., Smiley faces, arrows, card suits). Is it something to do with the file being a .hlp?

I’m just wondering, actually it’s pretty cool.

13 • December 19, 2007 at 10:39 am — Perishable says:

That’s great, Eric — glad to hear you are enjoying your RoboPro software :) Also, thanks for sharing your beeping noises with us — the comments that I receive on my DOS articles never cease to amaze me..

14 • December 20, 2007 at 8:57 am — Eric says:

Another fun thing to do is net send, unfortunately my school has disabled it. You can go further by sending it to all computers on the network using a “*” instead of a computer name, and if you [em]really[/em] want to annoy people, create a batch file that will keep doing that. >;-)

And then my friend and I discovered that the Ctrl+G character is what can trigger a beep. ^G^G makes two beeps, and so on.

dir /s is fun too.

Do you know of any other fun things to do while I’m board at school? Things that look like something crazy is happening, when in reality it’s harmless, are the best. Messing with teachers who aren’t computer-savy can be fun.

Also, I’d love to know how to get around the net send block :)

15 • January 5, 2008 at 9:12 pm — shane says:

hey uhh im a kid i wanan know about this net send stuff i hav a desktop an a laptop i hav vista on my laptop an a difrent xp on my desktop can anyone gimme some info or cool stuff to do btw my school blocked EVERYTHING u cant even right kick it sucks.. but yeah any healp?

16 • January 5, 2008 at 9:14 pm — shane says:

hey anyone wanan healp me with this netsend stuff idk how to use it i wanna know like how to use it what the commands are i can get it to work its kind of hard im a kid hey they only bloked that at ur school i cant even right click in places at my school..

btw comptuer teacher hates me hahaha

but could somone tell me how to use it i have vista an xp on to dif cmputers an can u send like a file that wont stop opening over an over an over again threw net send? or threw dos at all?

17 • January 6, 2008 at 9:41 am — Perishable says:

Truly insane.. if this is the fruit of the current public educational system, then I greatly tremble upon pondering what the future may hold.

18 • January 6, 2008 at 12:16 pm — zohaib says:

HI.i wana run a .cpp program through the command prompt and save its outut in a .txt format…HOw can i do that??

19 • January 6, 2008 at 1:07 pm — shane says:

does anyone know how to send file’s threw net sen in cmd all i get is like a hle bunch of stuff that sayhs system computer confic account puas print theres like a hole bunch of stuff does anyone know how to do net sen on a vista computer it will not work fore me. i dont udnerstand wha to do..

please healp

20 • January 6, 2008 at 1:12 pm — Perishable says:

I’m sorry, but I am going to have to close this comment thread. I just can’t bring myself to read any more of shane’s abominable writing.

[ Comments are closed for this post. ]


Set CSS to lite theme
Set CSS to dark theme