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 thec:\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!
No comments:
Post a Comment