Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
Command Console Tutorial BCIS 3680 Enterprise Programming
Overview • Working in Command Console • Navigation • Working directory • Listing contents of directory • Special “directories” • Running Java Commands in Console • Difference between system and Java commands • Using PATH • Showing File Extensions
Alternative Way to Start Console • Click Windows Start menu. • Select Run… • In the ensuing dialog box, type cmd • Click OK or press Enter.
Working Directory • When the console opens, you’re at a certain location in the file system. • The default is the Windows home folder for the current user. In Windows XP, it’s C:\Documents and Settings\<username>. In Windows 7 and 8, it’s C:\Uers\<username>. • From here, you may move away to other locations. • At any point of time, you are “parked” somewhere in the file system. The current location you’re at is your working directory.
GUI View of My Working Directory • What is a folder in Windows graphic user interface (GUI) is called a directory in the terminology of command console. • Similarly, subfolder = subdirectory.
Navigation: Moving to Another Drive • To move a different drive, simply type the drive letter, followed by a semicolon, at the command prompt. • Press Enter and you’re at the root of that drive. • My working directory is the root of F: now.
Navigation: Moving to Another Folder • To move to another folder, use the CD (change directory) command. • In Windows, the commands are not case-sensitive. So CD and cd are the same command.
Navigation: Moving to Another Folder • Again, note that as I cd into the new location, the path in front of the prompt (>) changes to reflect my new working directory.
Viewing Contents of a Directory • To see what are the contents inside a directory, use the DIR (short for “directory”) command.
Special “Subdirectories” • In every directory, there are two special “subdirecotries”: • A single dot refers to the current directory, i.e., working directory. • Double dots refer to the immediate parent directory of the working directory. • Therefore, in the example below, if you issue the command dir ., the same output will be repeated. • If you issue cd .., your working directory will changed to F:.
Drilling Down inside a Directory • In the DIR output, <DIR> indicates a subdirectory (notice that both the . and .. “subdirectories” are marked as <DIR>. • In this example, hello also is a subdirectory of the working directory. • Use CD to move your working directory into the hello subdirectory. • Use DIR to list the contents of hello. • Repeat this procedure to “drill down” through the subdirectories of a directory. • Whenever you need to go back up one level, use the cd.. command.
Shortcuts for CD Command • If there are many levels of subdirectories, it would be too cumbersome to run cd.. repeatedly, each issuance of the command bringing you up only to the immediate parent of the current working directory. • You may combine the double dots as part of a relative path to the subdirectory you want to go to. • Use a pair of double dots for each level above the subdirectory you’re starting out from. • Separate two pairs of double dots with a backslash (\). • Once you reach a point where the parent of the destination folder, write out names of each directory in that branch. • Use the entire string as the “argument” of the cd command.
Navigation: CD with Absolute Path • The alternative solution is to type the absolute path (starting with the drive letter and spell out all subdirectory names).
Beeline to Root of Drive • Use backslash as the argument of CD command and it moves you directly to the root of the drive.
Other Useful Commands • MD <new subdirectory name> • Also MKDIR • Create a new subdirectory • RMDIR <subdirectory to remove> • Remove a subdirectory • DEL <subdirectory> does not remove the subdirectory. It only deletes all files in the subdirectory • DEL <file name> • Delete a file • TYPE <file name> • Output a file to the console • CLS • Clear the display of console
Running Non-System Commands • For system commands such as CD or DIR, the command console knows where to find their executable files and run them. • But if a program is not a native system file, the console assumes that it is inside the working directory. If it indeed finds the executable there, it runs it. If not, it throws in the towel and complains.
Running Java Commands • Java is not a Windows system application. So without assistance, the command console doesn’t know where java.exe or javac.exe is.
PATH Environment Variable • The PATH variable contains a number of absolute paths, separated by semicolons. • When Windows is installed, it adds quite some items in this variable. • You can add to this variable absolute paths to non-system programs you want to run in command console. • Do NOT add specific file name, only the path to the directory that contains the file you want to run.
Editing PATH • To edit PATH, right-click the computer icon on the desktop (or the Computer menu item in the Start menu). • Select Properties.
Editing PATH • Alternative, you can start the process by going to Control Panel and clicking System.
Editing Value of Path • To add a new path, first go to the very end of the existing value of Path. • It is very important not to change the current value in any way. Otherwise some of your programs may not work properly. • If you suspect that you may have altered the value inadvertently, simply click Cancel and start over again.
Editing Value of Path • Add a semicolon to the end and then type in (paste in) the new path you’re adding. It’s NOT necessary to add a trailing backslash and/or semicolon. • Click OK to save the new value.
Verifying PATH Changes • To make sure that you have changed the PATH, start a command console and run the PATH command. • The new value should be in the command output. • It may be necessary to restart your computer for the changes to take effect.
Showing File Extensions in Windows 7 • In this course, often we want to show the file extensions (e.g., the .class for source code files) in Windows Explorer. • However, the default Windows behavior is to hide file extensions that it recognizes. • We can change the settings of Windows Explorer.
Showing File Extensions • In Windows Explorer, click Organize (upper-left corner). • In the ensuing drop down menu, click Folder and search options.
Showing File Extensions • In the Folder Options dialog box, clear the checkbox for Hide extensions for known file types. • Click OK to close the dialog box.
Showing File Extensions • Now all file extensions are displayed, whether Windows recognizes them or not.