1 / 39

Shell: Quick Review

Shell: Quick Review. A Quick Review of the Basics. Some Basic Commands (1/2) Displaying the Data and Time: The date command The date command tells the system to print the date and time: Finding Out Who’s Logged In: The who Command

argus
Download Presentation

Shell: Quick Review

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. Shell: Quick Review

  2. A Quick Review of the Basics • Some Basic Commands (1/2) • Displaying the Data and Time: The date command • The date command tells the system to print the date and time: • Finding Out Who’s Logged In: The who Command • The who command can be used to get information about all users who are currently logged into the system: $ date Sat Oct 29 15:40:52 EDT 1983 $ $ who pat tty29 Oct 29 14:40 ruth tty37 Oct 29 10:54 steve tty25 Oct 29 15:52 $

  3. A Quick Review of the Basics • Some Basic Commands (2/2) • Finding Out Who’s Logged In: The who Command • Echoing Characters: The echo Command • The echo command prints at the terminal whatever else you happen to type on the line $ who am i pat tty29 Oct 29 14:40 $ $ echo this is a test this is a test $ echo why not print out a longer line with echo? why not print out a longer line with echo? $ echo A blank line is displayed

  4. A Quick Review of the Basics • Working with Files (1/3) • The UNIX system recognizes only three basic types of files: • ordinary files • any file on the system that contains data, text, program instructions, or just about anything else • directory files • special files • A special file has a special meaning to the UNIX system, and its typically associated with some form of I/O

  5. A Quick Review of the Basics • Working with Files (2/3) • Listing Files: The ls Command • To see what files you have stored in your directory • Displaying the Contents of a File: The cat Command $ ls READ_ME names rje $ $ cat names Susan Jeff Henry Allan Ken $

  6. A Quick Review of the Basics • Working with Files (3/3) • Counting the Number of Words in a File: The wc Command • The number of lines contained in the file • The number of words contained in the file • The number of characters contained in the file $ wc names 5 5 27 names $

  7. A Quick Review of the Basics • Command Options • Most UNIX commands allow the specification of options at the time that a command is executed • Let’s generalize by saying that command options should precede file names on the command line $ wc –l names 5 names $ wc –c names 27 names $ wc –w names 5 names $

  8. A Quick Review of the Basics • Making a Copy of a File: The cp Command • In order to make a copy of a file, the cp command is used $ cp source_file destination_file $ cp names saved_names $

  9. A Quick Review of the Basics • Renaming a File: The mv Command • A file can be renamed with the mv command • The arguments to the mv command follow the same format as the cp command • When executing a mv or cp command, the UNIX system does not care whether the file specified as the second argument already exists $ mv saved_names hold_it $

  10. A Quick Review of the Basics • Removing a File: The rm Command • You can remove more than one file at a time with the rm command by simply specifying all such files on the command line $ rm wb collect mon $

  11. documents programs plan dact sys.A new.hire no.JSK AMG.reply wb collect mon A Quick Review of the Basics • Working with Directories (1/14) [Fig. 1] Example directory structure documents programs memos proposals letters wb collect mon plan dact sys.A new.hire no.JSK AMG.reply [Fig. 2] Directories containing subdirectories

  12. usr steve pat ruth documents programs wb collect mon plan dact sys.A new.hire no.JSK AMG.reply A Quick Review of the Basics • Working with Directories (2/14) • The Home Directory and Path Names • The UNIX system always associates each user of the system with a particular directory • When you log into the system, you are placed automatically into a directory called your home directory … memos proposals letters [Fig. 3] Hierarchical directory structure

  13. A Quick Review of the Basics • Working with Directories (3/14) • The Home Directory and Path Names • relative path names • absolute path names • The directory that is one level higher • The directory name . . • current directory • The directory name .

  14. A Quick Review of the Basics • Working with Directories (4/14) • Displaying Your Working Directory: The pwd Command • Changing Directories: The cd Command $ pwd /usr/steve $ $ ls documents programs $ cd documents $ pwd /usr/steve/documents $ cd .. $ pwd /usr/steve $

  15. usr steve pat ruth documents programs wb collect mon plan dact sys.A new.hire no.JSK AMG.reply A Quick Review of the Basics • Working with Directories (5/14) memos proposals letters [Fig. 4] Current Working directory is steve usr steve pat ruth documents programs memos proposals letters wb collect mon plan dact sys.A new.hire no.JSK AMG.reply [Fig. 5] cd documents

  16. A Quick Review of the Basics • Working with Directories (6/14) usr steve pat ruth documents programs memos proposals letters wb collect mon plan dact sys.A new.hire no.JSK AMG.reply [Fig. 6] cd .. usr steve pat ruth documents programs memos proposals letters wb collect mon plan dact sys.A new.hire no.JSK AMG.reply [Fig. 7] cd documents/letters

  17. A Quick Review of the Basics • Working with Directories (7/14) • More on the ls Command $ ls documents letters memos proposals $ ls documents/memos dact plan $ ls documents/memos/plan documents/memos/plan

  18. A Quick Review of the Basics • Working with Directories (8/14) • More on the ls Command $ ls -l total 2 drwxr-xr-x 5 steve DP3725 80 Jun 25 13:27 documents drwxr-xr-x 2 steve DP3725 96 Jun 25 13:31 programs $ $ ls –l programs total 4 -rwxr-xr-x 1 steve DP3725 358 Jun 25 13:31 collect -rwxr-xr-x 1 steve DP3725 1219 Jun 25 13:31 mon -rwxr-xr-x 1 steve DP3725 89 Jun 25 13:30 wb $

  19. A Quick Review of the Basics • Working with Directories (9/14) • Creating a Directory: The mkdir Command • To create a directory, the mkdir command must be used $ mkdir misc $ ls documents misc programs $ usr steve pat ruth misc documents programs memos proposals letters wb collect mon plan dact sys.A new.hire no.JSK AMG.reply [Fig. 8] Directory structure with newly created misc directory

  20. A Quick Review of the Basics • Working with Directories (10/14) • Copying a File from One Directory to Another • The cp command can be used to make a copy of a file from one directory into another $ cp programs/wb misc/wbx $ $ cp programs/wb misc/wb $ $ cp programs/wb misc $ $ cp wb collect mon ../misc $ $ pwd /usr/steve/misc $ cp ../program/collect . …

  21. A Quick Review of the Basics • Working with Directories (11/14) • Moving Files between Directories • The mv command can be used to rename a file $ cd documents $ $ mv memos/plan proposals/plan $ $ mv memos/plan proposals $ pwd /usr/steve/programs $ mv wb collect mon ../misc $ $ mv programs bin $

  22. A Quick Review of the Basics • Working with Directories (12/14) • Linking Files: The ln Command • The ln command provides an easy way for you to give more than one name to file ln from to $ cp wb writeback $ $ ln wb writeback $ $ ls -l total 5 -rwxr-xr-x 1 steve DP3725 358 Jun 25 13:31 collect -rwxr-xr-x 1 steve DP3725 1219 Jun 25 13:31 mon -rwxr-xr-x 2 steve DP3725 89 Jun 25 13:30 wb -rwxr-xr-x 2 steve DP3725 89 Jun 25 13:30 writeback $

  23. A Quick Review of the Basics • Working with Directories (13/14) • Linking Files: The ln Command • You can link a bunch of files at once into a directory using the format $ pwd /usr/pat/bin -rwxr-xr-x 1 pat DP3822 1358 Jan 15 11:01 lcat -rwxr-xr-x 2 pat DP3822 504 Apr 21 18:30 xtr $ ln /usr/steve/wb . $ ls -l -rwxr-xr-x 1 pat DP3822 1358 Jan 15 11:01 lcat -rwxr-xr-x 2 steve DP3725 89 Jun 25 13:30 wb -rwxr-xr-x 2 pat DP3822 504 Apr 21 18:30 xtr $ ln files directory

  24. A Quick Review of the Basics • Working with Directories (14/14) • Removing a Directory: The rmdir Command • You can remove a directory with the rmdir command $ rmdir /usr/steve/misc rmdir: /usr/steve/misc not empty $ $ rm –f dir

  25. A Quick Review of the Basics • File Name Substitution (1/2) • The Asterisk(*) • The shell automatically substitute the names of all of the files $ ls chapt1 chapt2 chapt3 chapt4 $ echo * chapt1 chapt2 chapt3 chapt4 $ $ ls a b c chapt1 chapt2 chapt3 chapt4 $ echo chapt* chapt1 chapt2 chapt3 chapt4 $ echo *t1 chapt1 $ echo *t* chapt1 chapt2 chapt3 chapt4 $ echo *x *x $

  26. A Quick Review of the Basics • File Name Substitution (2/2) • Matching Single Characters • The question mark (?) matches exactly one character • Square brackets ([ ]) • One character matching • [abc] matches one letter a, b or c • Range of characters matching • [0-9] matches the characters 0 through 9 • cf) [z-f] is not valid!!

  27. Standardoutput Standardinput Command A Quick Review of the Basics • Standard Input, Standard Output, and I/O Redirection (1/6) • Standard Input and Standard Output [Fig. 9] Typical UNIX command

  28. A Quick Review of the Basics • Standard Input, Standard Output, and I/O Redirection (2/6) • Standard Input and Standard Output • Example – sort command $ sort Tony Babara Harry Dick Ctrl + D Babara Dick Harry Tony $ Tony Babara Harry Dick Babara Dick Harry Tony sort [Fig. 10] sort command

  29. Standardoutput Standardinput Command file A Quick Review of the Basics • Standard Input, Standard Output, and I/O Redirection (3/6) • Output Redirection [Fig. 11] output redirection

  30. A Quick Review of the Basics • Standard Input, Standard Output, and I/O Redirection (4/6) • Output Redirection • Output redirection character : >, >> • > : redirect • >> : append • Examples $ who > users $ cat users oko tty01 sep 12 07:30 ai tty15 sep 12 13:32 ruth tty21 sep 12 10:10 pat tty24 sep 12 13:07 steve tty25 sep 12 13:03 $ $ cat file1 This is in file1. $ cat file2 This is in file2. $ cat file1 >> file2 $ cat file2 This is in file1. This is in file2.

  31. Standardinput Standardoutput Command file A Quick Review of the Basics • Standard Input, Standard Output, and I/O Redirection (5/6) • Input Redirection

  32. A Quick Review of the Basics • Standard Input, Standard Output, and I/O Redirection (6/6) • Input Redirection • Input of a command be redirected from a file • Input redirection character : < • Different output.. Why?? $ who > users $ wc –l users 5 users $ wc –l < users 5

  33. Output of Command 1 Input of Command 1 Input of Command 2 Output of Command 2 Command1 Command2 pipe A Quick Review of the Basics • Pipe (1/2)

  34. oko tty01 sep 12 07:30 ai tty15 sep 12 13:32 ruth tty21 sep 12 10:10 pat tty24 sep 12 13:07 steve tty25 sep 12 13:03 A Quick Review of the Basics • Pipe (2/2) • Example – who & wc $ who > users $ wc –l < users 5 $ who | wc –l 5 Output of who Input of wc -l Output of wc -l who wc -l pipe

  35. A Quick Review of the Basics • Standard Error • Most UNIX command write their error messages • Associated with terminal by default • Error redirection character : 2> $ ls x* x* not found $ ls x* > foo x* not found $ cat foo $ • How we can redirect the message?? $ ls x* 2> errors $ cat errors x* not found $

  36. A Quick Review of the Basics • More on Commands (1/2) • Typing More Than One Command on a Line • Separate each command with a semicolon (;) • Sending a Command to the Background • Using ampersand character (&) $ date; pwd Wed Arp 25 20:14:32 EST 2005 /usr/pat/bin $ $ sort data > out & Send the sort to the background 1258 Process id $ date your terminal is immediately available to do other work Thu Apr 26 13:45:09 EST 2005 $

  37. A Quick Review of the Basics • More on Commands (2/2) • The ps Command $ ps PID TTY TIME COMMAND 195 01 0:21 sh The shell 1353 01 0:00 ps This ps command 1258 01 0:10 sort The previous sort $ Process ID Terminal number Amount of computer time that process has used Name of process

  38. A Quick Review of the Basics • Command summary

  39. A Quick Review of the Basics • Command summary

More Related