1 / 72

Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

Guide to Parallel Operating Systems with Microsoft Windows XP and Linux. Chapter 7 The Command Line. Objectives. Use the command line Access Help files Display the contents of files Create script files to automate simple tasks. The Command Line.

ghita
Download Presentation

Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

An Image/Link below is provided (as is) to download presentation 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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Guide to Parallel Operating Systems with Microsoft Windows XP and Linux Chapter 7 The Command Line

  2. Objectives • Use the command line • Access Help files • Display the contents of files • Create script files to automate simple tasks Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  3. The Command Line • Non-graphical interface to the operation system • Reasons for studying the CLI • To perform some tasks more efficiently • To troubleshoot a PC that has crashed • To more efficiently utilize system resources • To create powerful sets of commands • To develop better programming skills Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  4. Using The Command Line • Processing a command • Type a command on the keyboard • Characters pass through the STDIN (standard input) • Characters are echoed on the console • Press Enter • Command processor performs appropriate action • Results of command output to screen • Error message passes through STDERR (standard error) • Other output passes through STDOUT (standard output) • Input and output can be redirected • The appearance of the console may be personalized Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  5. Using The Command Line (continued) Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  6. Using the Command Line with the Windows XP CLI • Configure your command prompt • Copy and paste text using the command prompt • Explore the command history • Complete filenames and directory names Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  7. Customizing the CLI Window • Right-click command prompt title bar to open menu • Some options for manipulating the CLI • Restore: restore command prompt from the taskbar • Size: resize the command prompt with the arrow keys • Minimize: minimize command prompt to the taskbar • Edit: edit lines in the command prompt • Defaults: permanently change the default settings • Properties: change settings for current window only • Click Defaults; Console Windows Properties opens • Default settings apply to all future command prompts Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  8. Customizing the CLI Window (continued) Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  9. Customizing the CLI Window (continued) • “Command Prompt” Properties dialog box (for current prompt) • Options • Set options, such as Buffer Size and Cursor Size • Font • Select display font’s pixel size and shape • Verify selection in Selected Font window • Layout • Set size of the screen buffer and size of the window • Control the positioning of the window • Colors • Select colors for text and background (screen and popup) Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  10. Using the Command Prompt Edit Menu • Display menu: right-click title bar and then click Edit • Tasks that may be performed • Mark: mark text using Shift and cursor movement keys • Copy: copy marked text to the Windows Clipboard • Paste: paste copied text from the Windows Clipboard • Select All: mark all of the text in the command prompt • Scroll: turn on scrolling; press Esc to turn off scrolling • Find: display a dialog box to find a text string • Check QuickEdit Mode check box to enable a mouse • Box is in Options tab of Command Properties dialog Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  11. Using the Command History • Reusing a command applied in current session • Click within the window and then press the up arrow • To move forward in list, press the down arrow • Press F7 to review a list of previous commands • Use arrow keys to move up and down list • Press Enter to copy highlighted command to prompt • Press Esc to close the window Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  12. Using the Command History (continued) Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  13. Using Shortcut Keys • Use function keys to speed the entry of commands • F2 key: copies current command in history buffer • Requires you to specify character to delimit text • Example using the F2 key • Command in buffer is CD "\Program Files\TextPad 4“ • You want to move up directory to Program Files • Press F2 and then “T” to copy line up to “T” • Command line now contains: CD "\Program Files\ • Press Enter to execute the command Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  14. Using Shortcut Keys (continued) Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  15. Completing Filenames and Directory Names • Type CMD /F:ON to enable completion feature • Using the completion feature • Type partial directory name or filename • Type a key combination • Ctrl+D to complete a directory entry • Ctrl+F to complete a filename entry • The system automatically completes the entry • Re-press key combination to scroll through entries • Example: Type CD\pro and then Ctrl+D • Response: Program Files directory is supplied Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  16. Console Redirection • Redirect output to a file to create a command record • Example: DIR /S *.* > dirlist • Redirects output of DIR to a file named dirlist • The > switch is the redirection operator • Redirect output to a printer for a physical document • Local printer ports: PRN, LPT1, LPT2, and LPT3 • Example: DIR /S *.* > prn • Network printer uses Universal Naming Convention • UNC format: \\servername\printername • Example: DIR /S *.* > \\Windows99\Printer • Redirect input by using < after the command Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  17. Using Filter Commands • Functions performed by filter command • Take input from a file • Change the input in some way • Send output to a file or the standard output device • Filter commands return essential information • Three filter commands • FIND: searches for a string of characters • MORE: temporarily pauses display output • SORT: sorts lines in ascending or descending order Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  18. Using the FIND Filter • Searches lines of input for specified text string • Syntax: FIND [/V] [/C] [/N] [/I] "string“ [[drive:][path]filename[...]] • /V: displays all lines without the specified string • /C: displays only the count of lines with the string • /N: displays line numbers with the displayed lines • /I: ignores the case of characters when searching • Example: FIND "txt" dirlist > prn • Find all lines containing “.txt” extension in dirlist file • Redirects output of filter to a printer Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  19. Using the SORT Filter • Sort lines of input, output to standard output device • Output may be redirected to another device • Syntax: SORT [/R] [/+n] [[drive1:][path1]filename1] [/O [drive2:][path2]filename2] • /R: reverses the sort order; i.e., Z to A, 9 to 0 • /+n: specifies character number n to begin comparison • Example 1: SORT /+40 /R < dirlist • Sort output in descending order on column 40 • Example 2: SORT < dirlist > prn • Sort dirlist in ascending order, redirect output to printer Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  20. Connecting Commands with a Pipe • Output of one filter routed directly into another filter • Type a “|” (pipe) between filters to form connection • Example: DIR /s *.* | MORE • Display directory files one screen (24 lines) at a time • MORE syntax: command-name | MORE [/E] [/C] [/P] [/S] [/Tn] [+n] • command-name: command whose output is displayed • /E: enables extended features • Combine filter commands • FIND /V"<DIR>”dirlist | FIND /V"File(s)" | FIND/V"Total“ • Omit lines with “<DIR>”, “Files(s)”, “Total” in display Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  21. Using the Command Line with Fedora Core 4 • Similar to Windows XP CLI • Additional features explained in following sections Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  22. Using Command-Line Symbols • Know what you want to do with the files • Know what type of symbols to use • Table 7-3 lists many common command-line symbols • Scripts use symbols to perform file-processing tasks Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  23. Using Command-Line Symbols (continued) Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  24. Using Command-Line Symbols (continued) Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  25. Accessing Help • Functions of a command reference • Refresh user’s memory • Reveal new commands • Help: command reference in Windows XP • Man pages: command manual for Fedora Core 4 Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  26. Accessing Help with the Windows XP CLI • Type HELP at command prompt and press Enter • Commands listed in alphabetical order • Commands are briefly described • Displaying Help information for a specific command • Type command followed by /? • Example: type DATE /? for DATE information • Help describes command form and provides tips Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  27. Accessing Help with the Windows XP CLI (continued) Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  28. Accessing the Man Pages in Fedora Core 4 • Man (manual) pages provide help in Fedora Core 4 • Information displayed in the man pages • Name: name of the command • Synopsis: the syntax of the command • Description: description or use of the command • Options: the variety of switches you can use • Specific definitions: regular expressions or environment variables • Diagnostics: return codes associated with command • Bugs: links to, or descriptions of, any known errors Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  29. Accessing the Man Pages in Fedora Core 4 (continued) Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  30. Displaying the Contents of Files • Displaying files content in Windows XP • Use the PRINT and TYPE commands • Displaying file contents in Fedora Core 4 • Use the less, cut, head, tail, and grep commands Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  31. Displaying the Contents of Files in the Windows XP CLI • FINDSTR and MORE (discussed earlier in text) • Two additional display commands: PRINT, TYPE • PRINT syntax: PRINT [/E:device] [[drive:][path]filename[...]] • /E:device: specifies a print device • Local printer ports: PRN, LPT1, LPT2, and LPT3 • Specifying network printer: \\servername\printername • TYPE syntax: TYPE [drive:][path]filename • Display text file contents on a standard output device Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  32. Displaying the Contents of Files in Fedora Core 4 • less: move forward and backward through a file • less syntax: less [-[+]NpsS] [FILE] • Example: less: less –Np "/rc.d" /etc/inittab • Starts file read at first occurrence of match (“/rc.d”) • cut: used to extract fields from a file line (record) • cut syntax: cut [OPTION]... [FILE]... • Mainly uses the –d and –f options • Example: cut –d: -f3-6 /etc/passwd | more -10 • Prints third field of lines in the /etc/passwd file Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  33. Displaying the Contents of Files in Fedora Core 4 (continued) Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  34. Displaying the Contents of Files in Fedora Core 4 (continued) Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  35. Displaying the Contents of Files in Fedora Core 4 (continued) • head: prints first 10 lines from file to standard output • head syntax: head [OPTION]... [FILE]... • -n: change number of default lines to print • Example: head –n15 /etc/passwd • Prints first 15 lines from /etc/passwd file • tail: prints last N lines or bytes in a file • tail syntax: tail [OPTION]... [FILE]... • Example: tail –n20 –v /etc/passwd | more • Prints the last 20 lines of the /etc/passwd file Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  36. Displaying the Contents of Files in Fedora Core 4 (continued) Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  37. Displaying the Contents of Files in Fedora Core 4 (continued) Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  38. Displaying the Contents of Files in Fedora Core 4 (continued) • grep command • Searches a file and prints lines matching search • Lists line numbers and counts to summarize results • Use wildcards such as * and ? to refine your search • grep syntax: grep [options] PATTERN [FILE...] • Example: grep –n "root" /etc/passwd • Searches /etc/passwd for “root” • Prints line numbers, count, actual lines of text • Tip: use more command to help display information • Example: grep –n "nologin" /etc/passwd | more -10 Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  39. Displaying the Contents of Files in Fedora Core 4 (continued) Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  40. Creating Script Files • Script: batched instructions that do repetitive tasks • Section goals • Learn to build basic script files • Enhance scripts with decision-making and repetition • Script files are an act of programming • Learn problem-solving process before writing scripts Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  41. The Six-Step Problem-Solving Process • General guidelines for solving problems • 1. Read the problem statement • Then name the programming project • 2. Read the problem statement • Then write a descriptive summary of the problem • 3. Read the problem summary • Then list the known input elements • 4. Read the problem summary • Then list the display (output) elements • 5. Read the problem summary • Then identify and list the processing steps • 6. Read the problem summary • Then define the constants and variables Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  42. The Six-Step Problem-Solving Process (continued) • Illustration: write a script listing certain filenames • Filenames in Accounting having “06” and .txt • Results following each of the six steps • 1. Programming project is named “Text file for ’06” • 2. A descriptive summary of the project is written • 3. It is stated that the script file does not need input • 4. The items to be displayed are listed • 5. The processing steps are listed • 6. It is determined that no variables are needed • Script written following six steps: CD accounting FIND "06" *.txt Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  43. Creating Batch Programs in Windows XP • Batch program (or file) • An unformatted text file with one or more commands • Has a .bat or .cmd extension • Commands in a batch file carried out as a group • Any command used at prompt can be batched • Some XP commands designed for batch programs • CALL • FOR • IF Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  44. Using Batch Parameters • Batch parameters: information passed to program • %0 - %9: separated by spaces, commas, semicolons • %0 has the name of the batch command • %1 - %9 represent strings in numerical order • Example: XCOPY %1\*.* %2 in file mycopy.dat • Run file with mycopy.bat C:\folder1 E:\folder2 • %1 is replaced by Folder1, %2 is replaced by Folder2 • Contents in Folder1 copied to Folder2 • Modifiers expand parameters to partial or full name • Example: %~d1 expands %1 to a drive letter Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  45. Using Batch Parameters (continued) Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  46. Displaying Text with the ECHO Command • ECHO: displays text to the standard output device • Syntax: ECHO [{on|off}] [message] • {on|off}: specifies whether command is on or off • message: specifies text to display on screen • Enter ECHO without parameters to display setting • Some ways to use ECHO command • Insert @ before ECHO in batch to prevent echoing • Example: @ECHO off • Type ECHO followed by a period to echo blank line Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  47. Repeating Commands with the FOR Command • for: execute command for a specific set of items • Syntax: FOR {%%variable} IN (set) DO command [CommandLineOptions] • set parameter can represent a series of text strings • Text strings may represent one or more file groups • Items in set sequentially replace %%variable • Specified command acts on each item • Sample script: @ECHO off FOR %%V IN (Blue Green Red) DO @ECHO %%V • Echo “Blue”, “Green”, and “Red” on separate lines Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  48. Branching with the GOTO Command • GOTO directs XP to a line identified by a label • Syntax: GOTO label • Label must match a label in the batch program • Label in a batch program must begin with a colon (:) • Line beginning with colon not processed as command • Response by OS if specified label not in program • Label not found Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  49. Making Decisions with the IF Command • IF: performs conditional processing in programs • Three variations on basic syntax • IF [not] errorlevel number command [else expression] • IF [not] string1==string2 command [else expression] • IF [not] exist FileName command [else expression] • Extended syntax: IF [/i] string1 CompareOp string2 command [else expression] • Conditional logic • If condition is true, following command is executed • If condition is false, following command is ignored • Command in ELSE clause, if present, is executed Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

  50. Making Decisions with the IF Command (continued) Guide to Parallel Operating Systems with Microsoft Windows XP and Linux

More Related