1. Understanding Paths
The command prompt shows the current path at the
prompt. For example, if you open a prompt with administrator privileges,
you’ll see the following prompt:
When executing a command, the system always looks in
the current location for the file or executable command. For example, if
you have a file named 70-642.txt in the current path, you can use the
following command to open it with Notepad:
C:\studynotes>notepad 70-642.txt
You can also specify a path with the command. For
example, if your file is in a folder named studynotes on the c: drive,
you can use the following command:
C:\>notepad c:\studynotes\70-642.txt
In the second example that includes the path, it
doesn’t matter what your current path is because you specified it in the
command.
You might notice that the command is notepad, but the path to notepad
is not needed when it is executed. Notepad is located in the c:\windows
folder and Windows Server 2008 is already aware of this path. Windows
Server 2008 is aware of the following paths by default:
c:\windows
c:\windows\system32
c:\windows\wystem32\wbem
Tip
Windows Server 2008 R2 is also aware of the path to
PowerShell by default (c:\windows\system32\windowspowershell\v1.0\).
Windows Server 2008 (not R2) adds this path when PowerShell is
installed.
You can view the path with the commands shown in the following table.
Command | Comments |
---|
| The output is
c:\Windows\system32;c:\Windows;c:\Windows\System32\Wbem;c:\Windows\System32\WindowsPowerShell\v1.0\ |
| The output is
PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\ |
You can also modify the path with the commands in the following table.
Command | Comments |
---|
| Sets
the path for the current command prompt session to only c:\mypath. When
you close the session and open another session, the path reverts to the
value in the %path% variable. |
c:\>path = %path%;c:\mypath
| Appends
the current path with the value you include (in the example,
c:\mypath). When you close the session and open another session, the
path reverts to the value in the %path% variable. |
2. Using Basic Commands
The following table shows many of the basic commands used at the command prompt.
Note
The term directories was used in the original DOS commands, and Windows uses the term folders. However, directories and folders refer to the same thing. In other words, directories and folders are synonymous.
Command | Comments |
---|
dir
c:\>dir
c:\>dir *.txt
c:\>dir appcmd*.* /s
| Retrieves a listing of the current folder.
Wildcards can be used. The example displays all files with a .txt extension.
The /s switch looks in subdirectories also. The example lists all instances of the appcmd file on the c: drive. |
cd
c:\>cd data\study
c:\data\study>cd ..
c:\data\>cd \
c:\>
| Changes directory.
The cd .. command moves up one folder.
The cd \ command moves to the root of the current drive. |
| Makes a directory. |
rd
c:\>rd tmpdata
c:\>rd tmpdata /s
c:\>rd tmpdata /s /q
| Removes a directory if it is empty.
The first example removes the folder named tmpdata, but only if it is empty.
The next example (with /s for subfolders) removes the folder and any subfolders even if there is data in any of the folders.
The last example (with /q for quite mode) suppresses the confirmation prompt. |
| Ends the current command prompt session and closes the command prompt window. |
3. Redirecting Output to Files
Many times you’ll want the output of a command sent
to a file. You can do this with the redirector symbol (>), as shown
in the following table.
Redirector | Description |
---|
>
Command > filename
c:\>gpresult /z > grouppolicies.txt
| Sends output to a file. The file is created if it doesn’t exist and overwritten if it exists. |
>>
Command >> filename
c:\>gpresult /z >> grouppolicies.txt
| Appends output to a file. Existing data is not overwritten. |