Tutorial on Basic Windows 2000 DOS
This Section Will Cover
- 00. What a file is under win enviroment
- 01. What a variable is in %win2k% batch and how to create them.
- 02. What echo echo. @echo off does.
- 03. What operators like > and >> and | do.
- 04. What a ::comment is.
- 05. What & does and how to use it &::creatively.
- 06. What 'DIR' and 'SORT' is and does
- 07. What a * and a ? mean to the DOS shell.
- 08. What GOTO _is when used with :_labels, also using PING to create a delay.
- 09. What if "statements"=="are and what they do".
- 10. What a basic "for" loop is/does.
- 11. How to use low interger values with variables.
- 12. How to parse strings into substrings.
- 13. How to echo non-echoable characters.
- 14. How to pass %arguments to a .bat file.
- 15. Summary
To get help on almost ALL CL tools in Win2k type the command then
/? i.e. DIR /? or CMD /?
If you're using a CL tool that you downloaded or whatever, most of the
time you can just type in the tool's
name and press enter. Usually when you don't supply any switches to a tool
it brings up help for the tool.
Also most tools other than M$ tools use a - instead of a /
Commands like DIR are built into cmd.exe.
cmd.exe is the 32bit shell that runs
these scripts. There is also command.com but that is 16bit. Always try to
run everything in cmd.exe (32bit) whenever possible because it is more flexible. Odds
are you will never have to use command.com. cmd.exe does everything it does
and a world more.
Ok, now press the windows key on the keyboard, keep it held down and press
R (the R does NOT have to be in capital case, lower case works
too). This needs
to be done fast. You can almost press them at the same time. You want to do this quickly
almost like you are pressing them at the same time, just make sure you hit R after the winkey.
If it doesnt work for you, then
click the start menu, then click run. Now in this run box just type
the 3 letters cmd and hit enter. This will bring up a DOS shell.
Same shell
the .bat use's but unlike the .bat, this shell will remain open. Usually at the end of
a .bat file, if it's written right, it will just close. Not even a
pause will happen
unless you put pause >nul in there so you could see what the final output was.
Ok in that DOS window, type DIR /? this will bring up help for
switches that
DIR can take. NOTE: you dont have to have DIR in all capitals or really any of these commands,
I just always try to do it like that.
Ok what you should see is the below...
C:\>dir /?
Displays a list of files and subdirectories in a directory.
DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N]
[/O[[:]sortorder]] [/P] [/Q] [/S] [/T[[:]timefield]] [/W] [/X] [/4]
[drive:][path][filename]
Specifies drive, directory, and/or files to list.
/A Displays files with specified attributes.
attributes D Directories R Read-only files
H Hidden files A Files ready for archiving
S System files - Prefix meaning not
/B Uses bare format (no heading information or summary).
/O List by files in sorted order.
sortorder N By name (alphabetic) S By size (smallest first)
E By extension (alphabetic) D By date/time (oldest first)
G Group directories first - Prefix to reverse order
NOTE: there is more I just listed the ones we are going to use.
Ok it all might look twisted to you, but its really simpler than most of
the
things you
already do. Read what each one does. Now keep hitting enter until it gets you
back
to where you can type stuff.
Now type in DIR /AD /B /ON You should see something like the below if you are
on C:\ (and you should be for this tutorial). This is what it looks like for me...
C:\>DIR /AD /B /ON
_base_apps
_pages
bestboot
CDRWIN3
Documents and Settings
DVRA03
j2sdk1.4.2
ntfspro
Pioneer
PNP
Program Files
Recycled
ScanPanel
Sun
WINNT
These are all directories. That is because we used the Attributes switch of /A and we put
with it D. /AD means only display directories. The /B means Bare. This hides alot of info.
We also used the Order switch of /O and with it N. /ON means order the output by name.
Here we go again, this time, lets just use DIR /ON OK, here is just what part of mine looks
like. Since i dont want to waste space I have cut it down. Yours will look
slightly different of course...
C:\>DIR /ON
Volume in drive C has no label.
Volume Serial Number is 60A0-AB66
Directory of C:\
08/17/2003 19:42 0 __apps
08/11/2003 21:51 DIR _base_apps
09/05/2003 23:02 1,527 _java_notes.txt
08/13/2003 08:15 DIR _pages
09/08/2003 02:04 13,958 basic_dos_howto.txt
08/12/2003 04:12 DIR bestboot
11/27/2022 13:44 2,949,120 bestboot.ima
08/26/2003 07:18 21 blah.txt
09/08/2003 01:34 159 zz.bat
.
..
...(keeps going but I cut it off)
22 File(s) 14,082,349 bytes
20 Dir(s) 6,411,542,528 bytes free
As you can see we only used the switch /ON so we see files and directories, and also
other attributes like date, time, DIR meaning it's a directory,
1,527 is the size in bytes of file _java_notes.txt.
The command SORT is actually a file in your WINNT system.
It's not built into cmd.exe like
DIR is. What it does is sort a file but only to the screen. It does not create a new sorted file
or sort the one you used with SORT. You will have to use redirection >> to output to
a new sorted file. Type in SORT /? in your DOS window. Yes you
might see
some crazy stuff, I understand what all those options do, but never found
myself having to use
them. Simple fact is, if you have to use those options, you are going to hunt down a different
CL tool on the internet that can do it more effieciently and/or alot more
stuff...at least that was
the case for me. (application named texttools I used to use)
Basically all you need to know is the below.
SORT file_to_sort >> sorted_file.txt
The above will use the file of file_to_sort and output the sorted text to sorted_file.txt.
Notice file_to_sort does NOT have a .txt extension. This is because
like I said you don't
have to have one. All the data in file_to_sort I know is text, so
I'm fine.
In an OS that doesnt have simple redundant limitations like file
extensions,
you don't need file
extensions at all. In fact, windows is the only currently up to date OS I
know where you have to have
them for just about everything. But in DOS, you can perform any routines on files you want regardless
of file extension. You could actually do SORT setup.exe >> sorted_setup.exe.
This would of course would be a meaningless operation since the sorted file would not work since you messed it up from its intended usage,
but you can do it.
/P This swich you can add to a lot of commands; not all, but most.
What this will do, is pause the output of
a command into screen fulls. This way the output won't just fly by your
eyes. You will get to see a screen full
of information before carrying on to the next. It will keep pausing for each screen full until there is no more
output. You will probably never use this in a script, since it requires a user to press a key, but it can be useful
for debugging or working straight from the shell itself.
NOTE: there are files that are binary. If you try to perform a text
operation on one of these
you will hear beeps and tones and the screen will go crazy. Dont worry,
you haven't broken anything,
but you just can't do a simple text operation like SORT on
it.
Click here to continue
|