Tutorial of various MS-DOS commands. For instructions on how to
open a DOS command prompt window, see: How to Open Command Prompt.

Note: Click here for newer version of this tutorial

Tuesday, July 1, 2008

DOS Commands :: dir

DOS Commands :: dir

dir
Use the dir command to output a listing of the contents of the current directory. Information about the files and subdirectories of the current directory will be displayed.

dir directory
By specifying a directory, the contents of that directory is displayed. For example, dir \mystuff will display the contents of the \mystuff directory. Note: If directory contains a space, then type quotation marks around the directory name; for example, dir "c:\program files"

dir *.txt
Displays a listing of all the .txt files located in the current (or specified) directory.

dir my*
Displays a listing of all files that start with the pattern you specify; in this example, "my".

There are a few options you can use with the dir command. See dir /? or help dir for the complete list. Note: If you specify a directory as part of the command, options can be specified before or after the directory

The following examples demonstrate some of the more useful options:

dir /p
Pause the directory listing after every screenful. To continue the listing, press any key (e.g.: spacebar or Enter key).

dir /w
Wide directory listing.

dir /b
Displays a directory listing showing just the filenames without header information or file size/date. This bare format is useful when you just want the actual filenames and you're going to do some sort of further processing. For example dir /b \mystuff > files.txt would create a file named files.txt that contains just the filenames of files located in the \mystuff directory.

dir /o:gne
Displays a directory listing that is sorted. You specify the sort order by one or more letter after the /o: part. The most useful sort order is gne which puts all the subdirectories before files (g), and sorts by name (n), and then by filename ending (e). Tip: You can set the sort order (lasts until you close the DOS window) by typing a set command: set dircmd=/o:gne

dir /o:s
Displays a directory listing that is sorted by size (smallest to largest). To reverse the sort order (largest size to smallest size), instead use: dir /o:-s

dir /s
Displays the contents of the current directory (or specified directory) as well as the contents of all subdirectories and their subdirectories too. Since the output can be very long, especially if you have subdirectories inside subdirectories, you probably should also use the /p option to pause output. If you forget to do, you'll probably see the output zipping by on your screen; in that case, press Ctrl-C to stop the command. Or you might want to save the output to a text file, for example: dir /s > myfiles.txt will output a list of all files contained in the current directory and all subdirectories to the file myfiles.txt

dir /s *.txt
Displays a listing of all .txt files located in the current directory and in all subdirectories.

dir /s mystuff.txt
Displays a listing of all instances of a file named mystuff.txt located in the current directory and in all subdirectories. Useful when you know the name of a file but don't recall which subdirectory it is located in. You can think of this command as the equivalent of the Windows Search Companion (accessible by pressing F3 when viewing a Windows folder).

dir /ah
Displays a listing of hidden files (if any) that are located in the directory. Tip: Use the attrib command to change the hidden attribute of a file.

Note: You can type more then one option at the same time. For example, dir /p/w \mystuff would display a wide listing of the \mystuff directory and pause after each screenful.

Monday, June 30, 2008

DOS Commands :: notepad

DOS Commands :: notepad

Although notepad is not a part of DOS, it is a useful command that you can use from a DOS command prompt window.

notepad
This command will cause the Windows Notepad text editor program to be run. This program is the same Windows Notepad program that is accessible in Windows via: Start > Programs > Accessories > Notepad

notepad filename
This command will cause the file named filename to be opened by the Notepad text editor. For example, notepad mylist.txt would open the mylist.txt file. If the file filename does not exist, Notepad will ask you if you want to create a new file with that name.

If you want to edit a file that is in a directory other than the current directory, then use the "cd directory" command first or specify the directory name as part of the filename, such as: "notepad \mystuff\ebooks\list.txt".

DOS Commands :: cd (change directory)

DOS Commands :: cd (change directory)

When you are using a Microsoft DOS command window, MS-DOS works on one directory at a time. The "current" directory is indicated as part of the command prompt.

For example, the command prompt "C:\mystuff\ebooks>" means that the current directory is the "ebooks" directory which is located inside the "mystuff" directory on the c: drive.

Use the cd command to make a different directory the "current" directory ("cd" is short for "change directory").

The command can be typed as either:

cd directory

or

cd drive:directory

For example, "cd \mystuff" will make "\mystuff" the current directory. To get to the "root" (top level directory) of your c: drive, type cd \

Note: To see what directories are available for you to cd into, use the dir command. And to make a new directory, use the md (or mkdir) command.

You can also type cd .. (the two dots are required) to back out one level out of the current directory. For example, if the current directory is "C:\mystuff\ebooks>" then typing cd .. will change the current directory to "C:\mystuff>"

DOS Commands :: cls

DOS Commands :: cls

When you are using a Microsoft DOS command prompt shell window, you can type cls to clear the window and move the command prompt to the top of the window. No files are changed by the cls command. The window display is merely cleared.

DOS Command :: Help

DOS Command :: Help

Open a Microsoft DOS command prompt shell window and type help and you will see a list of available commands with a brief description of each command.

To display detailed help information about command command, you can type either of the following help commands:

help command

or

command /?

For example, help dir and dir /? displays help information about the dir command.

How to Open Command Prompt

How to Open Command Prompt

To open a Microsoft DOS command prompt shell window, first click the Start menu at the lower-left of your computer's desktop and select "Run...".

Then if you are using Windows XP or Vista, type "cmd" (without the quotation marks) into the Run box and click "OK".

Otherwise, type "command" (without the quotation marks) into the Run box and click "OK".





After you click "OK", a DOS command prompt window will appear. Depending upon which version of Windows you are using, the DOS command window will look similar to these images:





See other postings here for a description of the commands that you can type into the DOS command prompt window.

To close the window, either type "exit" (without quotations marks) and press Enter, or click the X button in the top-right of the window frame.