Some course materi al on the Teachi ng Network may sti l l use
the command l i ne operati ng system cal l ed DOS (Di sk Operati ng System). Thi s requi res the user to type speci fi c commands at a prompt. You may al so need to use thi s system, for exampl e, when changi ng your password, and you can enter DOS by choosi ng 'MS-DOS Prompt' from the Publ i c menu on the taskbar. Commands can be typed i n response to the network DOS prompt: G:\> Commands may be typed i n upper or l ower case. Here, they are speci fi ed i n upper case to di sti ngui sh them from other i nput. Commands have a parti cul ar format. Some can be used si mpl y by typi ng the command name onl y, as i n: DIR whi ch di spl ays a l i sti ng of fi l es i n the current di rectory. Many commands can take extra i nformati on cal l ed parameters to make them more speci fi c, For exampl e, the COPY command can have a parameter speci fyi ng a fi l e to be copi ed and a parameter speci fyi ng a fi l e to whi ch the copy i s to be made. So the command woul d l ook l i ke thi s: COPY filea fileb I n thi s case, filea woul d be the name of a fi l e to copy from and fileb woul d be the name of a fi l e to copy to. Parameters can someti mes be omi tted i n whi ch case a defaul t acti on wi l l appl y. Commands can al so be qual i fi ed by the use of opti ons. Opti ons are preceded by a /si gn. A si mpl e exampl e of the use of an opti on i s wi th the DIR command. DIR can be qual i fi ed by /P or /W. Thus the commands: DIR DIR /W DIR /P resul t i n l i sti ngs presented i n a di fferent format as detai l ed l ater. DOS Command Reference Introduction Command Format Parameters Options 2 DOS Command Reference Some Useful DOS Commands Make a copy of a fi l e or merge fi l es together. COPY original-file destination-file where original-file and destination-file are fi l e names, separated by a space. The command can be used to merge several fi l es i nto one fi l e si nce the original-file parameter can be a l i st of fi l enames separated by the + symbol . For exampl e: COPY file1 + file2 file3 woul d copy fi l e1 and fi l e2 i nto fi l e3. Note that the fi l e names used i n the copy command must i ncl ude the fi l e extensi on i f i t exi sts. So i f you were copyi ng a fortran program cal l ed first.for, for exampl e, you woul d need to i ncl ude the .for extensi on i n the fi l ename. Del ete a fi l e. DEL filename where filename i s the name of the fi l e to be del eted. You are asked to confi rm that you real l y want to del ete the fi l e. Note that the name must i ncl ude the fi l e extensi on. The amount of space on a di sk i s l i mi ted and i t i s necessary peri odi cal l y to ti dy up unwanted fi l es. I t i s possi bl e to use a '*' character i n a fi l ename to match any sequence of characters. Thi s feature i s very useful when del eti ng unwanted fi l es wi th i denti cal extensi ons. For exampl e, when devel opi ng programs, DEL *.obj wi l l del ete every bi nary (.obj) fi l e i n the current di rectory. Si nce an .obj fi l e can al ways be recreated from the ori gi nal source program, i t i s usual l y unnecessary to keep i t. Obtai n a l i st of the fi l es stored i n a di rectory. I f used wi thout opti ons thi s command wi l l gi ve a l i st of fi l es i n the current di rectory, i ncl udi ng any extensi on (e.g. .for), and thei r si ze. I f used wi th the opti on /P, that i s: DIR /P The same i nformati on wi l l be di spl ayed page by page wi th the message: strike a key when ready at the end of each page. COPY DEL DIR DOS Command Reference 3 I f i t i s used wi th the /W opti on, i .e. DIR /W the l i sti ng i s of names and extensi ons onl y and i n a more compact format across the page. Take a securi ty copy of your worki ng di sk. I t i s very i mportant to have a second copy of your programs and data i n case you l ose your di sk or i t becomes unreadabl e for some reason. Use the DI SKCOPY command as fol l ows: DISKCOPY A: A: where A: denotes the dri ve the di sks wi l l be l oaded i nto. When a copy of your di sk i s generated i n the computer's memory, the computer tel l s you to remove the fi rst or source di sk and i nsert the di sk, whi ch i s to become the copy (the target di sk). I nsert the target di sk and press ENTER. I f the second di sk i s not formatted i t wi l l be formatted automati cal l y. The source di sk shoul d be wri te protected usi ng the tab i n the corner i n case you mi stake i t for the target di sk (see the chapter on usi ng di sks). Obtai n a pri nted l i sti ng of a fi l e. LIST filename where filename i s the fi l e to be pri nted. I f the pri nter i s busy, or i f you don't need a pri nted copy, you can use the TYPE command to vi ew a fi l e on the screen. You coul d al so use an edi tor such as DOS Edi t to di spl ay a fi l e, i n whi ch case, as a bonus, you woul d then be i n a posi ti on to correct any errors you mi ght noti ce. Remember that the fi l e name must i ncl ude the fi l e extensi on. So i f you want to pri nt your Pascal program cal l ed first you woul d need to use: LIST first.pas Change the name of a fi l e. Thi s command can be abbrevi ated to REN: REN oldname newname where oldname i s the fi l e to be renamed and newname i s the name i t i s to be gi ven. Note that fi l es on dri ves other than the current dri ve can be referred to by prefi xi ng the fi l ename by the rel evant dri ve l etter, for exampl e: A:\filename where the \ refers to the root di rectory of the dri ve. DISKCOPY LIST RENAME 4 DOS Command Reference Fi l enames can al so i ncl ude di rectori es separated by the \ character as i n: A:\dir1\dir2\filename Vi ew a fi l e on the screen. TYPE filename where fi l ename i s the name of the fi l e to be di spl ayed on the moni tor screen. I f you are l ooki ng at a l ong fi l e, you wi l l need to press the PAUSE key to stop conti nuous scrol l i ng. Press the space bar to conti nue scrol l i ng when you have read the screen. To format a fl oppy di sk, pl ace the di sk i n the fl oppy dri ve and type: FORMAT A: Note that by defaul t the di sk wi l l be formatted to hol d about 1.44 megabytes of data. Warning: formatting will destroy any data on the disk so only do this once! DOS Command Listing I n the fol l owi ng secti on, al ternati ve opti ons are separated by the ! character. Arguments are opti onal unl ess i n i tal i cs. cwd stands for Current Worki ng Di rectory. DOS commands are not case sensi ti ve. Some commands have swi tches; these must be preceded by a forward sl ash (/). Pathnames may be preceded by a dri ve l etter as i n X:pathname and i f no dri ve or pathname i s gi ven the current di rectory i s assumed. ATTRI B +!-r +!-a pathname di spl ay, or set!cl ear Read-onl y or Archi ve attri bute BREAK on!off di spl ay, or turn on!off i ncreased l evel of ^C detecti on CHDI R (CD) path di spl ay, or change worki ng di rectory CHKDSK pathname (A: dri ve onl y) check di sk or fi l e l ogi cal structure /f - fi xprobl ems encountered /v - verbose; di spl ays fi l especs CLS cl ear screen TYPE FORMAT DOS Conventions The Commands DOS Command Reference 5 COMMAND path cttydev run nested CLI from path wi th I /O devi ce cttydev /e:# - set envi ronment si ze # /p - do not i nvoke another CLI /c command - run command and then enter COPY pathname pathname or COPY pathname +pathname copy or concatenate fi l es /v - veri fy wri tes /a!b - precedi ng and al l subsequent fi l es are asci i ! bi nary (* fi l enames i n source(s) and target are matched one-to-one.) CTTY devi ce change MS-DOS I /O devi ce DATE dd-mm-yy di spl ay and/or set date (numeri cal country-dependent format) DEL ! ERASE pathname del ete fi l e(s) - prompts i f pathname i s *.* DI R pathname di spl ay di rectory - fi l ename and/or ext defaul t to * /p - pagi nate /w - mul ti -col umn DI SKCOPY dri ve: dri ve: copy di sk sector-by-sector rather than fi l e-by-fi l e EXI T exi t nested CLI FI ND string pathname fi nd and di spl ay l i nes contai ni ng stri ng i n fi l e /v - l i nes NOT contai ni ng stri ng /c - count l i nes onl y /n - di spl ay l i ne numbers al so FORMAT drive: (A: dri ve onl y) /1 - si ngl e si ded /4 - use doubl e rather than hi gh densi ty (40 tracks) /8 - use 8 sectors of each track /n:xx - speci fi es xx sectors per track /t:yy - speci fi es yy tracks /v - prompt for vol ume l abel , up to 11 characters /f:720 - format at 720 kb LABEL dri ve: l abel (A: dri ve onl y) di spl ay, or edi t vol ume l abel - 11 characters excl udi ng most speci al s MKDI R (MD) path make di rectory 6 DOS Command Reference MODE i nteracti vel y confi gure vari ous opti ons MORE pagi nates screen output e.g. type fi l ename | more PATH path;path;... di spl ay or set command search path(s) to be used after cwd PATH; resets defaul t to cwd onl y PROMPT stri ng reset or set prompt. Characters (each prefi xed by $) mean: $=$, t=ti me, d=date, p=cwd, v=versi on, n=dri ve, g=>, l =<, b=!, _=CRLF, s=l eadi ng space, e=ESC (for ANSI dri ver) RENAME (REN)pathname pathname rename fi l e(s) wi thi n a dri ve - wi l dcards are matched one-to-one RMDI R (RD) path remove empty di rectory SET vari abl e=text di spl ay al l , set or cl ear MS-DOS vari abl e - accessed as %vari abl e% SHARE enabl e networked mul ti -access fi l e l ocki ng /f:nbytes - nbytes per fi l e, need about 20 bytes per fi l e, defaul t 2048 /l :nl ocks - nl ocks per fi l e, defaul t 20 SORT pathname pathname sort l i nes of fi l e al phabeti cal l y, i gnori ng case, to fi l e or stdout; reads stdi n by defaul t /r - reverse order /+n - on nth character i n each l i ne, defaul t i s fi rst SUBST dri ve: path (A: dri ve onl y) di spl ay substi tuti ons, or substi tute path by vi rtual dri ve SYS drive: (A: dri ve onl y) copy hi dden MS-DOS .sys fi l es from defaul t dri ve TI ME hours:mi nutes di spl ay and/or set ti me usi ng 24-hour format TYPE pathname output contents of a fi l e, wi th tab spaci ng of 8 VER di spl ay MS-DOS versi on DOS Command Reference 7 VERI FY on!off di spl ay, or set!cl ear di sk wri te veri fi cati on VOL dri ve: di spl ay di sk vol ume l abel XCOPY pathname pathname copy di rectory tree /a!m - i f archi ve bi t set ! al so cl ears i n source /d:date- modi fi ed on or after date onl y /s!e - copy subdi rectori es i f not empty ! even i f empty /p - prompt /v - veri fy /w - wai t for keypress I f renamed to MCOPY i t determi nes automati cal l y whether target i s fi l e or di rectory. Ful l detai l s of al l DOS commands can be seen by fol l owi ng the command wi th the swi tch /? For exampl e, DI R /? gi ves a l i sti ng of al l DI R opti ons. DOS commands are stored i n a templ ate and previ ous commands can be recal l ed, character by character enabl i ng edi ti ng as requi red. The templ ate i s accessed by the fol l owi ng keys:- F1 - get next character from templ ate F2 C - get characters up to but excl udi ng character C F3 - get remai ni ng characters from templ ate del - ski p one character i n templ ate F4 C - ski p characters up to but excl udi ng character C ESC - cl ear command l i ne I NS - toggl e overwri ti ng of templ ate F5 - copy command to templ ate for re-edi ti ng F6 - put ^Z i n new templ ate The arrow keys may al so be used to recal l the previ ous command. Al l DOS commands may be used i n batch fi l es. Addi ti onal l y, the fol l owi ng commands are useful for more advanced batch processes. Arguments for batch fi l es are accessed as %1 to %9. ECHO on!off!message di spl ay echo status, turn echoi ng on!off (defaul t on) or di spl ay message FOR %%C I N (SET of i tems) DO command C i s any character other than 0-9, SET i s e.g. l i st of fi l es On-Line Command Help Command Editing Batch File Commands 8 DOS Command Reference GOTO LABEL LABEL i s any l i ne of text, usual l y preceded by col on (:) i n fi rst col umn, whi ch makes MS-DOS i gnore i t other than as a l abel . Termi nates i f l abel not found I F ERRORLEVEL number command command executed i f previ ous command returned exi t code >= number I F string1 == string2 command command executed i f stri ngs match may be negated by NOT before condi ti on I F EXI ST filename command command executed i f fi l e exi sts may be negated by NOT before condi ti on PAUSE comment comment di spl ayed onl y i f echo on REM comment remark - i gnored by MS-DOS SHI FT shi ft arguments - al l ows access to more than 9 Several speci al characters may be used when referri ng to di rectori es and fi l es: \ = root di rectory or a di rectory separator . = current di rectory .. = parent di rectory Wi l dcard characters may be used i n fi l enames or extensi ons: ? = any character * = any tai l or extensi on X: - swi tches to current worki ng di rectory (cwd) on dri ve X. The FC command enabl es compari son of two fi l es: FC pathname1 pathname2 compare two fi l es, or two wi l dcarded sets of fi l es /a - abbrevi ate output of ASCI I compari son /b - force bi nary compari son (byte-by-byte) /c - i gnore case /L - force ASCI I compari son (l i ne-by-l i ne) /Lb# - use l i ne buffer of #l i nes /n - di spl ay l i ne numbers i n ASCI I mode /t - do not expand tabs - defaul t expands to spaci ng of 8 /w - compress whi te space (tabs and spaces) to si ngl e space (l eadi ng or trai l i ng whi te space al ways i gnored) /# - #l i nes must match to re-synchroni ze el se regarded di fferent (defaul t i s 2) Special Characters File Comparison Utility DOS Command Reference 9 I /O Control DOS i nput and output may be control l ed by the fol l owi ng control key sequences. (^ = the CTRL key). ^C - abort current command ^H - destructi ve backspace ^J - l i nefeed - physi cal newl i ne to i nput l ong l i nes ^N - toggl e copyi ng of termi nal output to pri nter ^P - toggl e redi recti on of termi nal output to pri nter ^S - suspend/restart termi nal output ^X - cancel current l i ne, and output \-CR-LF ^Z - end of fi l e I nput and output from commands or programs can be redi rected by usi ng the fol l owi ng symbol s:
> send output to... >> append output to... < take i nput from... | pi pe output to next i nput For exampl e: pi pe output from command a to i nput of command b: command a | command b send a di rectory l i sti ng to fi l e fi l ename: DI R > fi l ename DOS i ncl udes a ful l -screen edi tor i nvoked by the EDI T command (wi th or wi thout a fi l ename). To use thi s edi tor type: EDI T (filename) The edi tor provi des pul l -down menus, operated by the keyboard or mouse, and a hel p faci l i ty. Note that any changes made to a fi l e overwri tes the ori gi nal , no backup i s created. I/O Redirection Using The DOS Editor