The UNIX - PowerPoint PPT Presentation

About This Presentation
Title:

The UNIX

Description:

Title: Comp111 Slides Author: Andrew Horner Last modified by: CSD Created Date: 6/16/1996 12:02:10 AM Document presentation format: On-screen Show Company – PowerPoint PPT presentation

Number of Views:40
Avg rating:3.0/5.0
Slides: 21
Provided by: AndrewH164
Category:
Tags: unix | bush | george

less

Transcript and Presenter's Notes

Title: The UNIX


1
Software Tools
  • The UNIX
  • Shell

2
Basic Shell Syntax
  • command -options arg arg
  • The name of the command is first
  • Options are normally single letters that turn an
    option on or off. They can be combined or given
    separately.
  • ls -dil
  • ls -l -d -i
  • Options sometimes also take a value. The value
    can usually be either given right after the
    option or separately
  • ypcat -d ug.cs.ust.hk passwd

3
Command Options
  • Most commands require you to give all options
    before filename arguments. The following command
    works in Linux, but not SunOS
  • cat names -n
  • George W. Bush
  • Bill Gates
  • Bill Gates
  • Bill Clinton
  • George W. Bush
  • cat cannot open n
  • Spaces separate options. To turn something with
    spaces into a single argument, use quotes
  • grep vote thing letter1
  • grep cant open thing
  • letter1You have the Florida vote thing
  • grep vote thing letter1
  • You have the Florida vote thing

4
Command Options
  • Double quotes and single quotes are a bit
    different. For now, you can use them
    interchangeably.
  • grep vote thing letter1
  • You have the Florida vote thing
  • To escape a single character (prevent it from
    being treated specially) proceed it with a
    backslash
  • grep We\ll letter2
  • by my office. We'll tidy up a few more things
    before
  • echo
  • echo
  • echo \
  • echo
  • letter1 letter2 names secret/

5
How Does the Shell Find a Command?
  • The shell searches a list of directories for an
    executable file with the same name.
  • The list of directories is stored in the PATH
    variable for Bourne shells and in the path array
    for csh/tcsh
  • PATH/usr/local/binPATH sh
  • set path(/usr/local/bin path) csh, tcsh
  • If there is a match in more than one directory,
    the shell uses the first one it finds.
  • If you want to run a command that is not in one
    of these directories, you can give a pathname
    (relative or absolute) instead.
  • horner/bin/csound

6
How Does the Shell Find a Command?
  • A few commands are built into the shell. This
    varies from shell to shell. The echo command, for
    example, is often builtin, for efficiency.
  • You can find out where the shell is getting a
    particular command using the which command in
    any shell
  • which echo
  • echo shell built-in command.
  • which cat
  • /bin/cat
  • which grep
  • /bin/grep
  • which ls
  • ls aliased to ls --colortty

Makes directories blue, executables green, and
soft links aqua
7
Alias
  • The C Shell has the alias command, which allows
    you to create command shortcuts.
  • alias ls "ls -F"
  • alias rm "rm -i"
  • alias "chmod ux "
  • alias - "chmod u-x "
  • alias 111 "cd horner/111"
  • pwd
  • /bin
  • 111
  • pwd
  • /homes/horner/111
  • On most Unix machines (except Mandriva/Mandrake
    in CSLab2), if you put the alias commands in your
    .cshrc file, you can use them every time you
    login.

8
Standard Input
  • Every time you login, or run a shell, you are
    connected to the computer on a particular
    terminal.
  • who
  • horner pts/3 Feb 14 1023
    (csnt1.cs.ust.hk)
  • horner pts/0 Feb 14 1157
    (csz096.cs.ust.hk)
  • These devices (pts/0) are actually files in the
    directory /dev. So, if you are logged in on
    pts/0, this works just fine
  • date gt /dev/pts/0
  • Mon Feb 14 170821 HKT 2005

9
Standard Input
  • In fact, you can redirect stdout to a different
    device (e.g., pts/3), if you have permission.
    (The write command works this way.)
  • You can find out which terminal a particular
    shell is connected to using the tty command
  • tty
  • /dev/pts/0
  • echo "Hi Andrew!" gt /dev/pts/3

10
Tee
  • A special command called tee acts like a T-joint
    in plumbing
  • who
  • horner pts/3 Feb 14 1023 (csnt1.cs.ust.hk)
  • horner pts/0 Feb 14 1157
    (csz096.cs.ust.hk)
  • who sort tee sortedwho wc -l
  • 2
  • cat sortedwho
  • horner pts/0 Feb 14 1157
    (csz096.cs.ust.hk)
  • horner pts/3 Feb 14 1023 (csnt1.cs.ust.hk)
  • In this example, the output of sort is placed
    in a file sortedwho and piped to wc -l, which
    counts the number of lines.

11
Background Jobs
  • A simple command or pipeline can be put into the
    background by following it with the
    character
  • sort names gt names.sort
  • 1 3236
  • The shell will print the process ID (PID), and a
    job number (1, in this case).
  • In some shells, you will be notified when the job
    is done (you may have to hit return again)
  • sort names gt names.sort
  • 1 3236
  • 1 Done sort names gt names.sort

12
Background Jobs
  • Put a job in the background by typing CTRL-Z
  • ypcat passwd sort gtpasswd.sort
  • Z
  • Suspended
  • The job is suspended - not running - until you
    either place it in the background using bg
  • bg
  • 1 ypcat passwd sort gt passwd.sort
  • or back to the foreground using fg
  • fg
  • ypcat passwd sort gtpasswd.sort

13
Jobs
  • The jobs command tells you what jobs are running
  • ypcat passwd sort gt passwd.sort
  • Z
  • Suspended
  • jobs
  • 1 Suspended ypcat passwd sort gt
    passwd.sort
  • You can stop a job with the kill command
  • ypcat passwd sort gt passwd.sort
  • 1 3414 3415
  • kill 1
  • 1 Terminated ypcat passwd
  • Exit 2 sort gt passwd.sort
  • The 1 means job 1. You can also use the PID.

14
Jobs
  • The ps command is the main way to find out about
    jobs
  • ps
  • PID TTY TIME CMD
  • 1401 pts/0 001 csh
  • ypcat passwd sort gt passwd.sort
  • 1 3476 3477
  • ps
  • PID TTY TIME CMD
  • 3477 pts/0 000 sort
  • 1401 pts/0 001 csh
  • 3476 pts/0 001 ypcat

15
Jobs
  • Note that if you put something into the
    background, you better redirect stdout, or the
    output will appear on your screen anyway!
  • ypcat passwd
  • ma_wmkaauq2jXK0sFQ8Jg367475000Woo Man
    Kei,,EXP.2001.05.30nc99S/homes/ma_h
  • ma_chyaaCS9wq.1zOxnhI354355000Chu How Yin
    Agnes,,EXP.2001.05.30nc98F/homs
  • ee_tkcaa9LtI7Tipk2Ca6356515000Tsang Kong
    Chau,,EXP.2001.05.30nc99S/homesh
  • eg_cckyi7XtKxxP5KaQ4355510010Cheung Chi
    Keung,,ce98_yr1/homes/eg_cck/bin/h
  • cs_wksdtjvwifI2G7v22451410001Wong Kin
    Shing,,cs98_yr1/homes/cs_wks/bin/tch
  • cs_lwkOWiGoJRXSjn.s2403210001Leung Wai Kei
    Ricky,,cs98_yr2/homes/cs_lwk/bh
  • ph_chyacCSJUo9e2KGqKg359555000Chan Hoi
    Yan,,EXP.2001.05.30nc98F/homes/phs
  • ee_wkkabdfbi3GqWjvf5U356445000Wong Ka
    Keung,,EXP.2001.05.30nc99S/homes/eh
  • ph_lcyCSwGgr5IeIvqc366895000Lam Chi
    Yin,,EXP.2001.05.30nc99S/homes/ph_lcx
  • C
  • ypcat passwd gtfile

16
More Pattern Matching
  • The notation abcd matches any single one of
    the enclosed characters.
  • ls il
  • it it1 ith its_at_ letter1
    letter4
  • The notation a-z matches any lowercase
    letter.
  • The notation 0-9 matches any digit character.
  • The notation 0-59 matches any the digit
    characters 0, 1, 2, 3, 4, 5, and 9.
  • ls letter
  • letter1 letter4
  • ls letter0-35
  • letter1
  • ls letter0-24
  • letter1 letter4

17
More Pattern Matching
  • Most shells allow you to give a list of strings
    in curly brackets, comma separated
  • ls 1,.sort
  • NAMES1 it1 names.sort s1_at_
  • f1 letter1 passwd.sort
  • secret1
  • secret1 Permission denied

18
Switching Shells
  • You can switch shells by just typing its name
  • csl2wk01.cs.ust.hkgt ps
  • PID TTY TIME CMD
  • 3496 pts/0 001 csh
  • csl2wk01.cs.ust.hkgt tcsh
  • csl2wk01.cs.ust.hkgt ps
  • PID TTY TIME CMD
  • 3650 pts/0 000 tcsh
  • 3496 pts/0 001 csh
  • csl2wk01.cs.ust.hkgt sh
  • ps
  • PID TTY TIME CMD
  • 3650 pts/0 000 tcsh
  • 3496 pts/0 001 csh
  • 3659 pts/0 000 sh
  • D
  • csl2wk01.cs.ust.hkgt ps
  • PID TTY TIME CMD
  • 3650 pts/0 000 tcsh

19
Combining Commands
  • Multiple pipelines can be input on one command
    line by separating them with semicolons.
  • When entering a long command, use a backslash (\)
    to continue the command on the next line.
  • date sort names \
  • who
  • Mon Feb 14 194028 HKT 2005
  • Bill Clinton
  • Bill Gates
  • Bill Gates
  • George W. Bush
  • George W. Bush
  • horner pts/3 Feb 14 1023
    (csnt1.cs.ust.hk)
  • horner pts/0 Feb 14 1911
    (csz096.cs.ust.hk)

20
Combining Commands
  • Commands can be grouped together using
    parentheses
  • There are two main reasons to group commands
  • To create a single command out of a group of
    commands (especially useful before a pipe)
  • (cat letter1 head -2 names) sort gtlist
  • To run a set of commands in their own subshell
    (especially when trying to limit the effect of a
    cd command)
  • (cd secret ls wc -l) ls wc -l
  • 3
  • 25
  • This line has the effect of counting the files
  • in secret, and then counting the files in the
  • current directory.
Write a Comment
User Comments (0)
About PowerShow.com