w indows c ommands. references: windows command line interface, prof. yitzchak rosenthal 2
TRANSCRIPT
WINDOWS COMMANDS
2
References: Windows Command Line Interface, Prof.
Yitzchak Rosenthal
CLI AND DOS
The Windows command line interface (CLI) commands
are sometimes referred to as "DOS" commands.
DOS was the name of the operating system that predated
Windows (it stands for Disk Operating System).
The only way to control DOS was to use these commands
The commands in the modern Windows Command Line
interface are very similar to the original DOS commands.
WHY SHOULD WE USE THE CLI (DOS COMMANDS)?
Many windows users will never have a need for the DOS commands
DOS commands are useful or required for many administrative or programming tasks
For example, using DOS commands one can write programs to automate many administrative tasks.
5
THE BASICS Prompt: what the computer tells you when ready
for a command (c:\>) You type a command and press ENTER when you
want to send it to the computer Computer may come back with text about what it
did (or didn’t do) and then will present the Prompt again.
6
ACCESSING THE COMMAND LINE
XP: Run dialog box; type CMD or COMMAND Vista/7: Search Dialog box; same commandor start | All Programs | Accessories | Command
Promptor Right-click shortcut and select Run As
Administrator for commands that affect Windows
Win 8/8.1: Windows Button, CMD
7
FOCUS
• Command Line always focused on a drive and directory; prompt will show both
• C:\Windows\System32> has focus on C: drive and Windows\System32 folder
• Change focus– Type drive letter and colon, then ENTER– Type CD and directory name to drill down– Type CD .. To go up a level
• DOS will remember drive and directory
8
FILENAMES
Everything is a file to the computer Each file has a name: 8.3 format Windows allows 255 characters in file name Extension (should be) unique to application that
created the file; changing the file extension does not change the file contents
Windows uses file extension to determine: a) Program that created it and b) What icon to use for the file
9
ASCII
American Standard Code for Information Interchange
Each unique method of binary organization is called a file format
ASCII defines 256 eight-bit characters First, universal, file format still used for
configuration files
10
FOLDERS
Also called directories Any file at the root of the directory tree is said
to be in the Root Directory A folder within a folder is a sub-directory or
subfolder Any folder can have many subfolders and files;
names have to be unique unless in different folders
11
PATH
The route to a file; listing of drive and directory structure to get to the file: C:\Windows\System32\Notepad.exe
This is the path to the file and its full name
12
COMMAND.COM
Shifts command to upper case Looks within command.com Looks within the current directory (focus) Looks in directories specified in the PATH Returns “Bad command or file name” <command> /? Will bring up help on the
command
13
OH NO!
DOS will do what you say, not what you mean so double-check spelling and syntax before the Enter key is pressed
I wanted a directory listing, but I typed DEL instead of DIR
14
DIR
Shows the contents of the current directory Can show another directory if you point it there:
dir c:\windows Dir /w will give you a five-column display Dir /p will pause at each screenful of
information
15
SPACES IN FILENAMES
If any folder or filename in a path contains spaces, you must surround the entire path with quotes when using it in a DOS command.
Example
dir "c:\my folder\my file.txt"
16
CD
Change directory CD <directory name> will take you down to
that directory CD .. Will take you up one directory level CD \ will take you to the root directory for the
drive
17
MOVE BETWEEN DRIVES
Type the drive name followed by a colon and then press enter
A: will take you to the A: drive C: will take you to the C: drive Command will remember what directory you
were in on each drive when you switch
18
MD
MD <name> to make a directory New directory is directly below current directory Automatically creates . (dot) and .. (double-dot)
files. Dot is current directory; double-dot is parent directory (one up)
Does not tell you anything if it worked
19
RD
RD <name> to remove (empty) directory (only . and .. Files remain
Removes directory below current directory RD <name> /s will remove files, subdirectories
and directory
20
RUNNING A PROGRAM
Your computer can only run files with the extensions: .exe, .com or .bat
You do not have to type the extension to run the file/program
21
ATTRIB
Attrib <name> displays the attributes (H,S,R,A) for a file
Attrib <name> + turns on the attribute Attrib <name> - turns off the attribute
22
WILDCARDS
* (shift-8) replaces any number of characters ? Replaces just one character Can be used anywhere a file name is legal DIR a*.* will find any file that starts with “a” in
the directory and has any extension
23
REN
Renames a file name to a new name REN <old name> <new name>
24
DEL
BE VERY CAREFUL WITH THIS COMMAND!!!! Deletes one or more (if you use wildcards) files;
all gone, no going back Will not remove directories Actually, replaces the first character with Σ You don’t get a response
25
COPY/MOVE
Copy <what> <where> Copy d:\win98\*.* c:\win98\*.* will copy all files
from the D: drive (optical drive) win98 directory to the C:\WIN98 directory – will not change file names
There is no “undo” for copy/move gone wrong
26
XCOPY
Allows copying of directories, files and subdirectories at one time
Xcopy c:\data d:\data /s/e will copy everything in the c:\data directory to a d:\data directory including files and subdirectories (/s) even if empty (/e)
ROBOCOPY
Robust copy command Allows you to copy files and directory structures
across a network Found in Vista and 7
27
CHKDSK
Command line version of Error Check Usually fails when you start it because it can
not lock the drive; will run next time Windows restarts
FORMAT
We have a whole presentation on this Format c: /s will format c: drive and install
system files (DOS)
28
Hostname Will give you the name of the computer
SFC System File Checker SFC /scannow Will attempt to set computer disk to be the
same as installation disk
Shutdown
| MORE
This is what you typefollowed by the ENTER key
`
This is the prompt. It is
printed by the computer
To view a lot of output, instead of using the scroll bar, you can force the output of most commands to be displayed one screen at a time.
Type the command followed by "| more" (without the quotes), for example:
c:\> help | more
The vertical bar symbol (also called a pipe symbol) is located on the keyboard above the backslash ( \ ) character.
30
OUTPUT OF "HELP | MORE"
When you use "| more", the output from the command is displayed one screenfull at a time
Below is the output of the command "help | more" Press the spacebar to see the next screenfull of output. Press the ENTER key to see the next line of output. To quit seeing the output type "q" (for quit) or Ctrl-C
31USING “| MORE” WITH OTHER COMMANDS
You can add “| more” (without the quotes) to the end of most commands to have the output of that command displayed one page at a time.
E.g.
dir | more
type myfile.txt | more
We will learn more about what the “|” means later.
32
CHANGING THE PROPERTIESOF THE COMMAND WINDOW
Another way to see more information at once is to increase the height of the command window
To do that, "left click" on the icon in the upper left hand corner of the window and choose "Properties"
INCREASE THE SIZE OF THECOMMAND WINDOW
CHANGING THE PROPERTIES OF THE COMMAND WINDOW
Another way to see more information at once is to increase the height of the command window
To do that, "left click" on the icon in the upper left hand corner of the window and choose "Properties"
35
INCREASING THE HEIGHT OF THE COMMAND WINDOW
choose the "Layout" tab.
change the value of the "Height" field in the "Window Size" section
this is the number of lines of output that is displayed in the command window. (the default value is 24)
press the "OK" button
36
APPLY THE CHANGES
finally, you will see this dialog box
If you choose "Apply properties to current window only" then the next time you start a command window the new window will be the original size
If you choose "Modify shortcut that started this window" then then next time that you start a command window it will be the larger size.
37
RESULT - LARGER COMMAND WINDOW
38
INCREASING THE HEIGHT OF THE COMMAND WINDOW
choose the "Layout" tab.
change the value of the "Height" field in the "Window Size" section
this is the number of lines of output that is displayed in the command window. (the default value is 24)
press the "OK" button
39
APPLY THE CHANGES
finally, you will see this dialog box
If you choose "Apply properties to current window only" then the next time you start a command window the new window will be the original size
If you choose "Modify shortcut that started this window" then then next time that you start a command window it will be the larger size.
Make a choice (either is fine) and press the "OK" button.
40
RESULT - LARGER COMMAND WINDOW
41
Windows Command-Line File and Folder Management ToolsTool DescriptionATTRIB Displays, applies, or removes attributes for the specified file or folder.
CD Changes to the specified folder.COMP Compares the contents of two specified files byte by byte.
COMPACT Displays or modifies the compression settings for the specified file or folder (which must be located on an NTFS partition).
COPY Creates a copy of the specified file or folder in another location.
DEL Deletes the specified file or folder.DIR Displays a directory listing for the current folder or for the specified file or folder.
FC Compares the content of two specified files.FIND Searches for and displays all the instances of a specified string in a file.
FINDSTR Uses a regular expression to search for and display all the instances of a specified string in a file.
MKDIR Creates the specified folder.MOVE Moves the specified file or folder to another location.
REN Changes the name of the specified file or folder.
REPLACE Replaces files in the destination folder with files in the source folder that have the same name.
RMDIR Deletes the specified folder.SORT Sorts the specified file and then displays the results.
SFC Runs the System File Checker, which scans and verifies the protected Windows 7 files.
TAKEOWN Enables an administrator to take ownership of the specified file.
TREE Displays a graphical tree diagram showing the subfolder hierarchy of the current folder or the specified folder.
WHERE Searches for and displays all the files that match a specified pattern in the current folder and in the PATH folders.
XCOPY Creates a copy of the specified file or folder in another location. This tool offers many more options than the COPY command.