0% found this document useful (0 votes)
47 views

Dos Command Prompt Tutorial

This document provides a tutorial on basic commands for the DOS command prompt, including how to open the command prompt, navigate folders, view file listings, change directories, and compile and run Java programs. Key commands covered are dir to view files, cd to change directories, cd.. to go back one level, and javac and java to compile and run Java files. The document explains how to use these commands to compile and run a sample Java program called HelloConsole.

Uploaded by

farrukh_ali_15
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Dos Command Prompt Tutorial

This document provides a tutorial on basic commands for the DOS command prompt, including how to open the command prompt, navigate folders, view file listings, change directories, and compile and run Java programs. Key commands covered are dir to view files, cd to change directories, cd.. to go back one level, and javac and java to compile and run Java files. The document explains how to use these commands to compile and run a sample Java program called HelloConsole.

Uploaded by

farrukh_ali_15
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

DosCommandPromptTutorial

Thistutorialcoversthebasiccommandsthatyoumayfindhelpfulforusingthedoscommandprompt, aswellasinstructionsoncompilingjavaprogramsinit. Toopenthecommandprompt,holdthewindowskey(seebelow)andpressR,thentypeincmdinthe Rundialogwindow,thenpressOK.

Youshouldseesomethinglikethis(withouttheyellowline):

C:\DocumentsandSettings\AlvinmeansthatwearecurrentlyinthefoldernamedAlvin,whichisinthe folderDocumentsandSettings,whichisontheCdrive/partition.Thisisalsoknownasthepathofthe Alvinfolder.Filesystemnavigation(foldernavigation)incommandpromptisthesameconceptas windowsexplorer,butinsteadofdoubleclicking,wetypeinthenameofthefolderascommands. Commontoboth,itisonlywhenweareinthatfolder,thatweareabletomanipulateit(moresoin windowsexplorerthaninDos). Thekeykeyworddirstandsfordirectory,anditshowsallthefilesanddirectoriescontainedinthe currentfolder.Thecontainedfilesanddirectoriesaredisplayedasaverticallist,withdates&timeof whichitwaslastmodified.

Thisisthesameasviewingthefilesintheeverfamiliarwindowsexplorerthatyouvegrownso accustomedto.Justthatinthecommandprompt,therearenographicaldisplay,everythingisintext form.Notethatinthewindowsexplorer,theAddressbarcontainstheidenticaladdressasthe commandprompt(C:\DocumentsandSettings\Alvin)

Saythatinwindowsexplorer,wewishtogointothetestfolder,containedintheAlvinfolder,wewould simplydoubleclickonthetestfoldersicon.Inthecommandprompt,tochangetoacontainedfolder, weusethecdcommand,followedbythenameofthatfolder.Thecdcommandstandsforchange directory.Theoutputshouldlooklikethefollowing.Thoughtheexplorerwillshowallthecontentof thetestfolder,thecommandpromptsimplyswitchittothatfolderwithoutautomaticallydisplaying anything.Toviewthefiles,usethedircommanddescribedearlier.

Inwindowsexplorer,ifwewishtogobacktotheAlvinfolderfromthetestfolder,wesimplypressBack.

Thecommandpromptequivalentiscd..(thatscdfollowedbytwoperiods).Ourcurrentfolderwillbe backtotheAlvinfolder(C:\DocumentsandSettings\Alvin)

Imsureyouvenoticed,the\symbolisusedtoseparatedifferentleveloffoldersorsimplyfolder names.Whenusingthecdcommand,wecanlinkmanyfolderstogetherasillustratedinthefollowing. Thisisafasterwaythantypingnumerouscdsonmultiplelines.

OtherNoteworthyKeywordsthatyouMayNeedinthisCourse(givetheseatry): cls d: [tab] cd\ Clearsthecommandpromptofthetextyouveinputtedandtheoutputthatscurrentlyon there,makingiteasiertoread Changesthecurrentpathtotheddrive(ifitexistontheharddrive).Likewise,c:changesit tothecdrive.Thesemicolonhasmanyusesinthedoscommandprompt,justsohappensthat thedriveletter(eg.c,d,e)followedbythesemicolonchangestothatdrive/partition. Whenenteringnamesoffoldersorfiles,aftertypinginthefirstfewletters,pressingtabwill allowthedosprompttofinishtypingrestofthefilenameforyouifamatchexist.Sayifyou havea foldernamedMississippi,andyouwishtoenterit.YoumayonlyneedtotypecdMand thenbypressingtab,thecomputerwillfillouttherestofthewordandshowcdMississippifor you.Thenyoujusthavetopressentertoexecuteitandactuallygointothatfolder.This featurematchesthenameoffiles/directorieswiththefirstfewcharactersofwhatyouvejust startedtoenter,but,onlytothebestofitsabilities.Thismeansifyouhavemultiplefolders that startwithMiss,itllmatchtothefirstonethatshigherupbyalphabeticalorder. Pressingtabagainwillcyclethroughtothenextbestmatch.Thismaybearealtimesaver whencompilingprograms. Asopposedtotypingincd..multipletimestogettotheCpartition(C:),thecd\commandwill jumpyoustraightthere.

dir/w Avariationofthedircommand,inwhichthefiles/foldersaredisplayedhorizontally,leavingout mostoftheinformationthatthedircommandwouldoutput.Aneasierwaytoviewfilesofa folderthatcontainsALOToffiles. dir/p exit Note:Innewerversionsofcommandprompt,theslash/andbacklash\canbeusedinterchangeably. ButintheWindowsfilingsystem,thebackslashisthepropercharacterofuse.Also,the[tab]auto completionfeaturewasnewlyaddedinWindowsXP,takingtheideafromLinuxscommandprompt (terminal).WindowsfilingsystemisNONcasesensitive,socdTest=cdTEST=cdtest=cdtestwhen entering.MacsandLinuxfilingsystemsarehowever. CompilingaProgramintheCommandPrompt Thefirststepistonavigatetothefolderthatcontainsthefilethatyouwishtorun.Inthisexample,the pathisC:\exampleanditcontainsthefileHelloConsole.java. Anothervariationofthedircommand.TrythiswithafolderthatcontainsALOToffilesandsee theresultsforyourself(easierthanmeexplainingwhathappensandleavingyouclueless). Thisisprettyselfexplanatory

Oursourcecodeorprogramsalwayshasa.javaextension,exactlylikehowallpdffileshavea.pdf extension.Beforerunningallprograms,wemustcompileit.Thekeywordthatweuseisjavac,followed bythefullnameoftheprogram,HelloConsole.java.Thejavaccommandwillworkifjdkisinstalledand thepath/classpatharesetupcorrectlyasinstructedinthemanualbyJohnNakamura(inthehelp sectionofthecoursewebpage).Iftherearenoerrorsinthesourcecode,youroutputshouldlooklike thefollowingandyouwillhaveanewfileinyourfolder.Thatnewfilehasthesamenameasyour sourcefile,butwitha.classextension.Iftheprogramscompiledcorrectly,itwilljustgotothenext linewithoutanyindication.Itypedinthedircommandonlytoshowyouthatthereisanewlyaddedfile.

Finally,toruntheprogram,typeinthekeywordjavafollowedbythenameofthesourcecode, WITHOUTtheextension.Inthiscase,IdenterjavaHelloConsole.Theprogramwillrunanditisonly afteryouquittheprogram,thatyouarewouldregaincontrolofthecommandprompt.

END WrittenBy:AlvinHsieh For:CS1MD3,McMasterUniversity Tuesday,September22,2009,1:48am

You might also like