Fall Sale! Code FALL2024 takes 25% OFF our Pro Plugins & Books »
Web Dev + WordPress + Security

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 the following command at the command-line prompt (or via the Start > Run... dialogue box):

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

Also, 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 resources

About the Author
Jeff Starr = Designer. Developer. Producer. Writer. Editor. Etc.
GA Pro: Add Google Analytics to WordPress like a pro.

20 responses to “Fun with the DOS Command Prompt”

  1. 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..

  2. 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 :)

  3. 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?

  4. 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?

  5. Perishable 2008/01/06 9:41 am

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

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

  7. 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

  8. Perishable 2008/01/06 1:12 pm

    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. Something to add? Let me know.
Welcome
Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience. Here you will find posts about web development, WordPress, security, and more »
Blackhole Pro: Trap bad bots in a virtual black hole.
Thoughts
I disabled AI in Google search results. It was making me lazy.
Went out walking today and soaked up some sunshine. It felt good.
I have an original box/packaging for 2010 iMac if anyone wants it free let me know.
Always ask AI to cite its sources. Also: “The Web” is not a valid answer.
All free plugins updated and ready for WP 6.6 dropping next week. Pro plugin updates in the works also complete :)
99% of video thumbnail/previews are pure cringe. Goofy faces = Clickbait.
RIP ICQ
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.