Unix utilities
This presentation is the property of its rightful owner.
Sponsored Links
1 / 27

UNIX Utilities PowerPoint PPT Presentation


  • 98 Views
  • Uploaded on
  • Presentation posted in: General

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

Download Presentation

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


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 utilities1

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


Getting started with unix

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:


Basic unix file utilities

Basic UNIX File Utilities

  • lslist files in current directory

  • catdisplay (concatenate) file

  • more display one screen of file

  • rmremove (delete) a file

  • cpcopy source file to target file

  • mv rename or move a file

  • lprprint a file

  • manonline UNIX help manual

  • mpageprint multiple pages on postscript printer

  • vi editing a file


Unix file utilities example 1

UNIX File Utilities - Example (1)

$ ls

letter1secret

$ 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

letter1letter2secret


Unix file utilities example 2

UNIX File Utilities – Example (2)

$ mv letter1 letter3

$ ls -F

letter2letter3secret/

$ lpr -Pcll3 letter2

$ mpage -Pcll3 letter2

$ rm letter2

$ ls -F

letter3secret/


Unix file utilities example 3

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... ]


Unix file utilities example 4

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%)


Editing a file using vi

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


The unix shell

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)


Popular shells

Popular Shells

  • shBourne shell (the original shell)

  • cshC-shell (pronounced as “sea shell”)

  • tcshLike csh with more functions (default for our lab computers)

  • bash“Bourne again” shell

  • ksh Korn shell

  • zsh Z-shell


Utilities for finding info 1

Utilities for Finding Info (1)

  • whoWho 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)

  • fingerA 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


Utilities for finding info 2

Utilities for Finding Info (2)

  • writeSend 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>

    $


Utilities for interacting with other users talk 1

Utilities for Interacting with Other Users: talk (1)

  • talkchat 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?


Utilities for interacting with other users talk 2

Utilities for Interacting with Other Users: talk (2)

$ whoami

clinton

$

Message from [email protected] at 20:41 ...

talk: connection requested by [email protected]

talk: respond with: talk [email protected]

$ talk [email protected]

[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?


More utilities 1

More Utilities (1)

  • echo

  • date

  • head

  • tail

  • grep

  • sort

  • uniq


More utilities 2

More Utilities (2)

  • echoDisplay command line input to screen

    $ echo Hi, I am Bill, the President of the US!

    Hi, I am Bill, the President of the US!

  • datePrint the date and time

    $ date

    Wed Feb 3 12:13:07 HKT 1999


More utilities 3

More Utilities (3)

  • headDisplay first few lines of file

    $ head -2 letter3

    Ms. Lewinski:

    It is getting late. Please order some pizza and stop

  • tailDisplay last few lines of file

    $ tail -2 letter3

    Thanks!

    Bill

  • grepFind a pattern in a file

    $ grep ”some pizza” letter3

    It is getting late. Please order some pizza and stop


More utilities 4

More Utilities (4)

  • sortSort 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


More utilities 5

More Utilities (5)

  • uniqDisplay 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


Input output redirection 1

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


Input output redirection 2

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


Input output redirection 3

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


Input output redirection 4

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


Appending and pattern matching

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.


Pipes 1

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


Pipes 2

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


  • Login