23 December 2009

Some Usefull DOS Tricks



Change Directories Without Typing the Whole Name

Changing directories at the command prompt can be a hit and miss process when long filenames are involved. This tip let you change directories with ease, not matter how long the directory name.

To change a directory quickly you can use wildcards, for example, to change to the 'C:\Program Files' directory simply type:

cd c:\prog*

Note: This will work in alphabetical order, therefore if you have two directories named 'c:\dir1' and 'c:\dir2' and you type cd dir*, you will be moved to the 'c:\dir1' directory.


Showing Long and Short File names

Dos have two additional switches that can be used when doing a DIR

/B - Shows only the long filename, no details
/Z - Shows the short filename, with details
/B /Z - Shows only short filename, with no details

Show DOS Command History
If you use DOSKEY in either your AUTOEXEC.BAT file or as part of the properties of your Dos Window
you can show and recall the history of commands you enter and the DOS prompt.

To recall previous commands, use the up arrow key.
A complete list of previous commands can be shown if you press the F7 key
To use one, press F9 and the number of the command you want to use
To clear the cache, press Alt+F7

Changing a File's Date and Time Stamp
To change the Date and Time stamp of a file to the current setting.

Type:
COPY filename /B + ,, /Y

Customize Setting the Number of Lines in a DOS Window

To set the number of lines displayed when you open up a DOS window:

Create a shortcut for the MS-DOS Prompt
Right click on it
Select Properties
Click on the Program tab
In the Batch file:, line enter mode con: lines=xx (where xx is the number of lines you want displayed)
Valid numbers for xx are 25 or 43

You can Add DOSKEY to your DOS Window
One way to have DOSKEY available when you open a DOS window would be to have it in the AUTOEXEC.BAT file.
This takes away conventional memory, even when you don't have a DOS window open.
To only use DOSKEY when you open a DOS window:

Right click on your DOS shortcut
Select Properties
Click on the Program tab
Add DOSKEY > NUL to the Batch File field
You can also add /INSERT if you prefer

Show DOS Error Codes
If you want to see what error codes are being generated by DOS programs,
start your DOS session with the addition of a /Z parameter to the COMMAND.COM program.


Entering Long Paths in a DOS Window
If you have to enter a long path and program name in a DOS window,

Open up the Explorer
Go to the folder you want
Drag it to the DOS window
The path will be inserted into the window

This can come is useful with the long path names and all the ~'s you would normally need to type.
If you need to change directories, type in the CD before you drag the directory.


Make DOS Programs Prompt for Input
When you normally create a shortcut for a DOS program, it does not prompt you for any input and just runs the program
To change that, simply add a ? after the program name in the CMD field.

For example:
C:\WINDOWS\COMMAND\EDIT.COM ?
will start the DOS editor and prompt you for a file name to edit.


Verbose Directory Listing
To see your free memory and other useful info in detail:

Open a DOS box
Go to the directory that you want to get specific info about, or if you just want to see memory info go to any directory (I use the root).
Type DIR /V
The /v argument stands for "verbose".
All sorts of good information comes up.

ABOUT THE AUTHOR
AbhiShek SinGh
Founder of 'TheHackingArticles'. Cyber Security Analyst, Cyber Security Researcher, and Software Engineer. Follow 'AbhiShek SinGh' on Facebook , Twitter or Google+ or via Email

Subscribe to stay up to date