A Power User's Guide To DOS

Written by b0iler for http://b0iler.eyeonsecurity.net/


Subdirectory - a directory within another directory.  C:\windows\blah .. blah is a subdirectory of windows.

DOS stands for Disk Operating System, and as I am sure you all have seen it, or used it before.  But that is false, you haven't seen it, you haven't truely used it before.  After you are finished with this tutorial I am hoping you feel the power DOS really has.  It is what seporates the point and click morons from the CLI (command line interface) power users.  The benifits of knowing DOS are great, you can get things done that you didn't know where possible, you can incorperate the commands into your coding, and it will also help you eventually move over to linux, where alot of command line knowledge is needed.

To start lets begin with getting a DOS prompt.  How to open a DOS command prompt is simple, go to start>run> then type in: command   ...if that doesn't work try command.com (in this case com is not a domain, it is a file extention).  If neither of these work something is wrong with your computer, but none the less you can still get to a command prompt.  Go to start>program>MS-DOS prompt click it. And the last way (in windows)is to go to start>find> type in command.com if you don't have it I don't know how you got on windows.  If all else fails just do start>shut down> select "restart in MS-DOS mode".

Getting the DOS prompt wasn't that hard, now on to the actual learning of the commands.  the simplest command to start with is the command 'dir' (commands are signaled with 's. when typing the command do not type the 's).  At your command prompt, black window with "C:\WINDOWS\Desktop>" or simular text and a blinking cursor, type: dir   This should list all the files in that directory.  if you had alot of files you won't beable to see all of them.  This can be a problem, so in DOS you can change the STDIN (standard input) and STDOUT (standard output) to whatever you like.  The default setting is your keyboard, because it is what normal users would use to provide input and the STDOUT is your monitor.  So how can you change the STDOUT so that the output from 'dir' goes to a file?

'dir > b0iler.txt'

Do you understand how that worked?  As you can see by that example the > is used to send the output to the file b0iler.txt instead of to the monitor.  you are changing the STDOUT to a file, why did we do this?  So that you can see all of your 'dir'.  To view the file simply type: 'notepad b0iler.txt' and up pops notepad with b0iler.txt open.  Now you can see the full 'dir' command.  The > is used to reset or create a file then direct the output into that file.  so lets try this:

'echo blah > b0iler.txt'

then

'notepad b0iler.txt'

You will see that b0iler.txt is now just: blah   this is because the > overwrites what was in the file before.  If you want to just "append" to the file you would use >> this would add the text at the end of what is already in the file.  You don't believe me?  Let's try it:

'echo blah > b0iler.txt'

then

'notepad b0iler.txt'

then

'echo b0iler was right >> b0iler.txt'

then

'notepad b0iler.txt'

Told you!  The >> will add to the end of a file.  That's it for changing the STDOUT, pretty simple.  Now to change the STDIN.  This is as simple as the > and >>:

'echo ping 127.0.0.1 > b0iler.txt'

then

'command < b0iler.txt'

Now this should call command.com and enter in ping 127.0.0.1.  Now it's time to go over what are known as pipes.  pipes make it possible to do serveral things in one command by chaining them together.  The | character is used to make a pipe to best show what a pipe can do I will introduce the SORT command.  SORT does just that, it sorts the lines into numarical-alphabetical order. First we will print the directory listing, then we will see how to use a pipe and sort it.

'dir > b0iler.txt'

then

'notepad b0iler.txt'

then

'dir | sort > b0iler.txt'

then

'notepad b0iler.txt'

Nice isn't it.  Piping allows DOS much more power, it allows you to change how things work so you get it how you want it.  FIND is another nice command to help you get what you want.  Try:

'dir | find "DIR" | sort > b0iler.txt'

that should print out just the directories to b0iler.txt all sorted in order.  A better way to do all this 'dir' stuff would have been to use the command 'more', this will print the output one screen at a time and wait for you to press a key, but then I wouldn't have been able to show you how to redirect input and output.  'more' is very easy to use simply do 'dir | more'.

Up till now you have been stuck in the default directory.  you probably want to move around a bit.  the command to move to a different directory is:

'cd'

this means Change Directory.  There is two ways to cd, you can do it using relative or absolute paths.  Relative means you do it from that directory.  lets say we are in c:\one and we do:

'cd two'

we would end up in c:\one\two .  If we then did:

'cd two'

we would be in c:\one\two\two.  Note: you can only cd into a valid directory, if the directory is not there you cannot cd to it.  The command to make a directory is:

'mkdir b0iler'

mkdir stands for make directory, and b0iler will be the name of the directory (this directory will be a subdirectory of the current directory).  Absolute means that you start with c:\ or \ so if we were in c:\one and we did:

'cd \two'

we wouldn't be in c:\one\two .. we would instead be in c:\two because \ means the base directory (C:\ in most cases).  You can easily switch to a floppy disk or a CD by:

'cd A:'

or

'cd D:'

(whatever drive your cd player is on).  To make going up directories easier dos has a short cut:

'cd ..'

If you were in c:\windows\blah and did:

'cd ..'

you would end up in c:\windows.  you can even use them like this (you are in c:\windows\blah):

'cd ..\b0iler'

and you would end up in c:\windows\b0iler.  Remember how to see all the files in the directory? 'dir', but our trick was to list only the subdirectories:

'dir | find "DIR" | sort'

.. so play around your system for awhile, check out all our directories, after a bit make sure to check out linux.  It has 100 times as many commands and is much more complex and useful than DOS. =)


[-----]
http://b0iler.eyeonsecurity.net/
- A really good site with tons of orignal tutorials.
[-----]