1 / 27

UNIX Utilities

UNIX Utilities. Learning Objectives: To understand the some basic utilities of UNIX File To compare UNIX shell and popular shell To learn Input/Output Redirection and the Pipe function. UNIX Utilities. Table of Content Getting Started with UNIX Basic UNIX File Utilities

akiko
Télécharger la présentation

UNIX Utilities

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. UNIX Utilities Learning Objectives: To understand the some basic utilities of UNIX File To compare UNIX shell and popular shell To learn Input/Output Redirection and the Pipe function

  2. UNIX Utilities Table of Content • Getting Started with UNIX • Basic UNIX File Utilities • UNIX File Utilities – Example • The UNIX Shell • Popular Shells • Utilities for Finding Info • Utilities for Interacting with Other Users • More Utilities • Input/Output Redirection • Pipes

  3. Getting Started with UNIX • The machines in CS Lab2 are named csl2su1 .. csl2su40. • csl2su3 means “CSLab2, Sun#3” • The full machine name for csl2su4 is: csl2su4.cs.ust.hk • You can access these computers with telnet from other computers via the Internet: telnet csl2su4.cs.ust.hk (from other UNIX computers or even Windows) • You need to log in to a UNIX computer with a valid account and password: UNIX(r) System V Release 4.0 (csl2su4) login: kwchiu Password:

  4. Basic UNIX File Utilities • ls list files in current directory • cat display (concatenate) file • more display one screen of file • rm remove (delete) a file • cp copy source file to target file • mv rename or move a file • lpr print a file • man online UNIX help manual • mpage print multiple pages on postscript printer • vi editing a file

  5. UNIX File Utilities - Example (1) $ ls letter1 secret $ cat letter1 Ms. Lewinski: It is getting late. Please order some pizza and stop by my office. We’ll tidy up a few more things before calling it a night. Thanks! Bill $ cp letter1 letter2 $ ls letter1 letter2 secret

  6. UNIX File Utilities – Example (2) $ mv letter1 letter3 $ ls -F letter2 letter3 secret/ $ lpr -Pcll3 letter2 $ mpage -Pcll3 letter2 $ rm letter2 $ ls -F letter3 secret/

  7. UNIX File Utilities – Example (3) $ man ls Reformatting page. Wait... done User Commands ls(1) NAME ls - list contents of directory SYNOPSIS /usr/bin/ls [ -aAbcCdfFgilLmnopqrRstux1 ] [ file... ] /usr/xpg4/bin/ls [ -aAbcCdfFgilLmnopqrRstux1 ] [ file... ]

  8. UNIX File Utilities – Example (4) DESCRIPTION For each file that is a directory, ls lists the contents of the directory; for each file that is an ordinary file, ls repeats its name and any other information requested. The output is sorted alphabetically by default. When no argu- ment is given, the current directory is listed. When several arguments are given, the arguments are first sorted appropriately, but file arguments appear before directories and their contents. There are three major listing formats. The default format for output directed to a terminal is multi-column with --More--(5%)

  9. Editing a file using vi • vi is a powerful and robust editor • It works almost anywhere on a terminal • vi has two modes: command mode and input mode • The appendix online gives some useful commands • http://www.cs.ust.hk/~qyang/111/Labs/vi.txt

  10. The UNIX Shell • The UNIX shell listens to what you type and executes commands at your request. ls, lpr, mv, rm, telnet, netscape, ... Command Library Printers Files Memory User command: lpr file UNIX Kernel UNIX Shell result or status results (on screen)

  11. Popular Shells • sh Bourne shell (the original shell) • csh C-shell (pronounced as “sea shell”) • tcsh Like csh with more functions (default for our lab computers) • bash “Bourne again” shell • ksh Korn shell • zsh Z-shell

  12. Utilities for Finding Info (1) • who Who is logged on, where & when$ whohorner pts/0 Jan 29 09:52 (csz096.cs.ust.hk)clinton pts/1 Jan 29 10:43 (csnt1.cs.ust.hk) • finger A bit more login information$ fingerLogin Name TTY Idle When Wherehorner Andrew Horner pts/0 12 Fri 09:52 csz096.cs.ust.hkclinton Bill Clinton pts/1 121 Fri 10:43 csnt1.cs.ust.hk

  13. Utilities for Finding Info (2) • write Send message to another user $ whoami horner $ write clinton Bill, you’ve been idle for a long time! What are you doing? [hit CTRL-D to end write message] $ --------------------------------------------------------- $ whoami clinton Message from horner on csz096.cs.ust.hk [ Fri Jan 29 20:18:47 . Bill, you’ve been idle for a long time! What are you doing? <EOT> $

  14. Utilities for Interacting with Other Users: talk (1) • talk chat for UNIX $ whoamihorner$ talk clinton[Waiting for your party to respond][Connection established]Hi Bill, what’s up?+-----------------------------------------------------+Hi! I’m a little busy right now. Is it okay if I call you back latter?

  15. Utilities for Interacting with Other Users: talk (2) $ whoami clinton $ Message from Talk_Daemon@csz096.cs.ust.hk at 20:41 ... talk: connection requested by horner@csz096.cs.ust.hk. talk: respond with: talk horner@csz096.cs.ust.hk $ talk horner@csz096.cs.ust.hk [Waiting for your party to respond] [Connection established] Hi! I’m a little busy right now. Is it okay if I call you back latter? +-----------------------------------------------------+ Hi Bill, what’s up?

  16. More Utilities (1) • echo • date • head • tail • grep • sort • uniq

  17. More Utilities (2) • echo Display command line input to screen $ echo Hi, I am Bill, the President of the US! Hi, I am Bill, the President of the US! • date Print the date and time $ date Wed Feb 3 12:13:07 HKT 1999

  18. More Utilities (3) • head Display first few lines of file $ head -2 letter3 Ms. Lewinski: It is getting late. Please order some pizza and stop • tail Display last few lines of file $ tail -2 letter3 Thanks! Bill • grep Find a pattern in a file $ grep ”some pizza” letter3 It is getting late. Please order some pizza and stop

  19. More Utilities (4) • sort Sort the lines in lexical order $ sort letter3 Bill It is getting late. Please order some pizza and stop Ms. Lewinski: Thanks! by my office. We'll tidy up a few more things before calling it a night. $ sort -r letter3 calling it a night. by my office. We'll tidy up a few more things before Thanks! Ms. Lewinski: It is getting late. Please order some pizza and stop Bill

  20. More Utilities (5) • uniq Display file with duplicate adjacent lines removed $ cat names Bill Clinton Bill Gates Bill Gates Bill Clinton Monica Lewinski $ uniq names Bill Clinton Bill Gates Bill Clinton Monica Lewinski

  21. Input/Output Redirection (1) • On UNIX, the standard input (stdin) is the keyboard; the standard output (stdout) is the display screen. $ sort waits for you to type in the data from the keyboard and displays the sorted data on the screen. keyboard sort display

  22. Input/Output Redirection (2) • Using the “>” character after a command to redirect output to a named file: $ sort names > names.sort $ uniq names.sort Bill Clinton Bill Gates Monica Lewinski • This will create a file test: $ cat > test type line 1 type line 2 <ctrl-d> $ cat test type line 1 type line 2 names sort names.sort uniq display

  23. Input/Output Redirection (3) • Using the “>>” character after a command to redirect output to APPEND to a named file: • Typing to the end of a file $ cat >> test type line 3 type line 4 <ctrl-d> $ cat test type line 1 type line 2 type line 3 type line 4 • Append file1 to file2 $ cat file1 >> file2

  24. Input/Output Redirection (4) • Using the “<” character after a command to redirect input from a named file: $ uniq < names.sort This is the same as: $ uniq names.sort • Using input and output redirection together: $ sort < names > names.sort names.sort uniq display names sort names.sort

  25. Appending and Pattern Matching • We have seen input redirection (cat <file) and output redirection (cat >file). We can also append to a file using >> $ date > file $ who >> file • Simple file pattern matching • The * pattern matches any number of characters: $ ls -l letter* lists all files in the working directory that start with “letter” • The ? pattern matches any single character: $ ls -l letter? lists all files in the working directory that start with “letter” followed by exactly one character.

  26. Pipes (1) • The standard output of a program can be “piped” into the standard input of another program: $ sort names | uniq Bill Clinton Bill Gates Monica Lewinski names sort uniq display

  27. Pipes (2) • Several pipes can be connected: $ sort names | uniq | grep "Bill" Bill Clinton Bill Gates • Pipes and I/O redirection can be used together: $ sort -r names | uniq >names.rev $ cat names.rev Monica Lewinski Bill Gates Bill Clinton

More Related