Command Console Tutorial BCIS 3680 Enterprise Programming

advertisement
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

2
Start a Command Console (Win 8 & 10)
Right click the Windows start icon
.
Select Command Prompt from the pop-up menu.
For managing Tomcat and MySQL, select Command Prompt (Admin)
instead.



3
Start a Command Console (Pre-Win8)
For Tomcat and MySQL management, right-click and select “Run as Administrator”.
4
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.


5
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.


6
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.



7
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.


8
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.

9
Viewing Contents of a Directory

To see what are the contents inside a directory, use the
DIR (short for “directory”) command.
10
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:.
11
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.
12
Drilling Down inside a Directory
13
Shortcuts for CD Command


If there are many levels of subdirectories, it may 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.




14
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 Relative Path
15
Navigation: CD with Relative Path
16
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).
17
Beeline to Root of Drive

Use backslash as the argument of CD command and it
moves you directly to the root of the drive.
18
Other Useful Commands

MD <new subdirectory name>



RMDIR <subdirectory to remove>



Delete a file
TYPE <file name>


Remove a subdirectory
DEL <subdirectory> does not remove the subdirectory. It only
deletes all files in the subdirectory
DEL <file name>


Also MKDIR
Create a new subdirectory
Output a file to the console
CLS

19
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.
20
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.
21
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.

22
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.
23
Editing PATH

Alternative, you can start the process by going to Control
Panel and clicking System.
24
System Properties Dialog Box
25
Find Path in System Variables
26
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.
27
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.
28
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.
29
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.

30
Showing File Extensions


In Windows Explorer, click
Organize (upper-left
corner).
In the ensuing drop down
menu, click Folder and
search options.
31
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.
32
Showing File Extensions

Now all file extensions are displayed, whether Windows
recognizes them or not.
33
Download