UNIX - PowerPoint PPT Presentation

1 / 71
About This Presentation
Title:

UNIX

Description:

1969 - wrote UNIX on a PDP 7. but PDP7 had a proprietary language ... name sonnet bonnet. which gives a syntax error. find ... negating options with ! ... – PowerPoint PPT presentation

Number of Views:66
Avg rating:3.0/5.0
Slides: 72
Provided by: conest
Category:
Tags: unix | bonnet

less

Transcript and Presenter's Notes

Title: UNIX


1
UNIX Linux Commands
  • David Turton
  • Conestoga College
  • Institute of Technology Advanced Learning
  • http//www.conestogac.on.ca/dturton
  • Doon 1D17 x3610

2
UNIX history
  • Ken Thompson ATT Bell labs
  • 1969 - wrote UNIX on a PDP 7
  • but PDP7 had a proprietary language
  • wrote B, to be less platform-dependent
  • Dennis Ritchie
  • wrote C as true platform-indep. language
  • rewrote UNIX in C, with Thompson

3
UNIX history (contd)
  • Released to universities, mid 1970s
  • free/cheap
  • source code was made available
  • Doctorates written improving efficiency
    security
  • commercial systems were less flexible
  • 4-year effect grads took UNIX to the world
  • UNIX adopted by DOD, late 70s
  • standards bodies intervene
  • ANSI, IEEE, ISO, etc.

4
Appeal of UNIX
  • Portable
  • written in C (available for all platforms)
  • I/O is device-independent
  • multitasking/multiuser from onset
  • network-ready built to share files
  • many interface shells window managers
  • blazingly fast, solidly reliable

5
UNIX Characteristics
  • unfriendly
  • terse
  • treacherous
  • unforgiving
  • inconsistent
  • non-mnemonic

typo
6
UNIX raison d'être
  • UNIX assumes you know what youre doing
  • Originally designed as a professional development
    environment
  • by techies for techies
  • verbose-averse
  • warns of failure, not of success
  • output of one process can be input to another

7
UNIX differs from DOS
  • UNIX is case-sensitive, DOS isnt
  • fred, Fred, FRED - are 3 different files
  • UNIX doesnt warn of destruction
  • UNIX views everything like a file off the root
    directory
  • in DOS, a printer is different from a diskette
    (A) and the primary hard drive (C)

8
Where is UNIX used?
  • Boeing cockpits
  • airline reservations
  • major government databases
  • most Internet servers
  • high-end CAD/design
  • Jurassic Park
  • Toy Story
  • However
  • It's being replaced by Linux
  • The commands are the same

9
Multitasking gt 1 task active at a time
  • To run multiple processes your must
  • Trap interrupts
  • i.e. file I/O, abends
  • Timeslice
  • tasks share available cycles
  • O/S kernel, or core, owns all the hardware
  • programs access devices via system calls to the
    kernel
  • allows kernel to take control provides platform
    independence

10
Multiuser gt1 people sharing computer resources
  • cant have multi-user w/out multitasking
  • sharing data, programs, resources
  • prime intent of UNIX
  • not until Windows 3.11 (early 90s) could
    Microsofts OS share data
  • optimizes investment
  • increase use of resources lots of empty cycles
  • necessary feature to support network servers
  • a logon process is initiated (forked) as each
    terminal connects
  • creates a process thread for user
  • could fork again, if user multitasks

11
UNIX/Linux Command Syntax
  • cp ri source destination
  • cp (copy) command
  • Lower case, no imbedded spaces
  • Command line is space-delimited
  • -ri options
  • Dash denotes option(s)
  • Multiple options can be combined (-ri)
  • Or can be separate (-r -i)
  • sequence doesn't matter
  • Parameter for an option follows it
  • Separated by a space (sort -kr -o param
    inputFile)
  • Source
  • Source files and/or directories, if any
  • Destination
  • Destination file/directory, if there is one, is
    at end

12
Standard Input, Standard Output, Standard Error
Output
  • Standard input
  • Defaults to the keyboard
  • Ctrl d or D
  • End-of-data
  • Ctrl c or C
  • Cancel command
  • Standard output
  • Defaults to the monitor
  • Standard error output
  • Defaults to the monitor
  • Independent of standard output
  • Can redirect any of these to/from somewhere else
    (later)

13
Sign-on, Navigating the File Structure
  • David Turton
  • Conestoga College, room 1B43
  • dturton_at_conestogac.on.ca
  • 748-5220 x8182

14
Logging in and out
  • Login screen presented after power-up
  • type your userid password
  • passwords and userids are case sensitive
  • Older systems typos can't be corrected
  • Logging out
  • type exit and press Enter
  • startx
  • Starts GUI interface from command interface
  • Right-click on resulting window select "new
    terminal" to get a command-prompt window

15
passwd
  • Command to change passwords
  • follow the prompts
  • confirm current
  • enter new
  • confirm new
  • suggestions
  • 6 characters long
  • upper and lower case
  • include numbers

16
wwho am i
  • Used to find out who is on the system
  • who am i
  • shows your userid, terminal type, logon time
  • w shows more information than who
  • such as idle time, cpu load, current task, etc.

17
UNIX directory structure
18
Addressing
  • Essentially the same concept as in DOS
  • Working directory
  • View path pwd (present working directory)
  • Relative addressing
  • Absolute addressing
  • However
  • Use "/" to separate directory/file names
  • /home/tom/docs/resume
  • There is no "drive letter"
  • There's only one file system
  • Everything is a file under the root

19
Directory Navigation
  • pwd
  • Print (display) the working directory path
  • cd
  • Change the working directory
  • mkdir
  • Make a directory
  • rmdir
  • Remove a directory
  • ls
  • List a directory's contents
  • Refers to your home directory when used as part
    of a file's path
  • cat more
  • Used mainly to look at file contents

20
pwd
/
  • Print the working directory
  • absolute addressing (from the root)
  • pwd
  • /usr/tom

bin
usr
dev
carol
tom
You are here
21
cd path
  • Change the working directory
  • use either relative or absolute addressing
  • with no arguments, sends you to your home
    directory
  • pwd
  • /usr/tom
  • cd docs
  • pwd
  • /usr/tom/docs
  • cd
  • pwd
  • /usr/tom

22
mkdir path
  • Make a new directory
  • use either relative or absolute addressing
  • Note
  • mkdir docs/team/status
  • Creates directory status at end of given path
  • Path (docs/team/) must already exist
  • ls -F
  • docs/ project.chart
  • mkdir accounting
  • ls -F
  • accounting/ docs/ project.chart

23
rmdir directory
  • Removes (deletes) a directory
  • directory must be empty
  • absolute or relative
  • last directory in given path deleted
  • ls
  • accounting docs project.chart
  • rmdir accounting
  • ls
  • docs project.chart
  • rmdir /usr/home/tom/docs
  • ls
  • project.chart

24
ls options path
  • List the contents of a directory
  • Default working directory
  • the path could be relative or absolute
  • the path may specify a file-name pattern
  • if path ends in a file name, will show
    information about the file
  • options
  • -l long descriptions
  • -a all (incl. hidden)
  • -F indicate file-type
  • -r reverse order
  • -d directory info only
  • (not its contents)
  • -R recursive
  • (directory all subdirectories)

25
ls examples
  • ls
  • docs project.chart
  • ls -a
  • .profile docs project.chart
  • ls -al or ls -a -l
  • -rw-r--r-- 1 tom grp1 1036 Sep 12 1102 .profile
  • drwxr-x--- 1 tom eng 512 Sep 13 0935 docs
  • -rw-rw-r-- 1 tom grp1 4096 Sep 23 1002
    project.chart

Hidden file
26
cat options file-list
  • concatenates files together
  • two files, each of 3 lines, concat to 6 lines
  • writes to the standard output device
  • Commonly used just to list file contents
  • if no file name provided
  • reads from the standard input device
  • terminated by D (end-of-data)

27
more options file-list
  • Used for long files
  • uses standard output device like 'cat'
  • but only displays a page at a time
  • at the bottom of the screen, shows
  • --More--(37)
  • meaning 37 of the file has been displayed
  • can enter prompts here, like h (help), b
    (back), space (forward a page), enter (forward a
    line), etc.
  • ie keystrokes are commands
  • 'q' to quit

28
A shortcut to creating files using gt
  • gt redirects standard output to a file
  • cat gt fileX
  • accepts data from the standard input device
  • (no input file-name given)
  • Standard output is redirected to fileX
  • fileX is created, empty, before the command
    executes
  • If fileX exists before command is run
  • It will be deleted recreated empty.
  • redirection/pipes/filters are covered later

29
man -k command UNIX help or manual pages
  • To get help on a command like ls, type
  • man ls
  • Will show
  • Command syntax,
  • Options,
  • Examples
  • If dont know command, use keyword search
  • man k list
  • Will show all commands with list coded as a
    keyword

30
Moving/copying/deleting/finding files
  • David Turton
  • Conestoga College - 1B43, x8182
  • dturton_at_conestogac.on.ca

31
File Manipulation
  • cp
  • copy file
  • mv
  • move file (copy remove)
  • rm
  • remove (delete) file
  • touch
  • update last used date
  • create file if doesn't exist

32
copycp options source source-list destination
  • if destination is a directory, copies the source
    file(s) to that directory
  • otherwise, creates a copy with given name
  • if the file already existed, its now gone
  • options
  • i interactive warn of override
  • r recursive copy source dir contents
    sub-dirs
  • can use . to denote working dir
  • cp /usr/tom/status.txt .
  • Note destination must be specified

33
movemv options source source-list destination
  • Move or rename a file
  • current name to new name
  • existing file(s) to an existing dir
  • existing dir to new dir
  • options
  • -f force - dont warn of permissions
  • -I interactive - warn of overriding a file

34
Remove/Deleterm options file-list
  • Removes/deletes a link to a file
  • Normally won't delete a directory (see r)
  • need execute write permission to directory
  • options
  • -f - force
  • -i - interactive (ask if really want to)
  • -r - recursive directory its contents

35
touch option file-list
  • Update a files modification time
  • creates file if doesnt exist
  • option
  • -c don't create file(s)

36
find path options
  • Finds names of files and directories that meet
    given criteria
  • including those in subdirectories
  • displays in absolute format
  • ls /mydir find /mydir -print
  • myfile.txt subdir tmp /mydir
  • /mydir/myfile.txt
  • /mydir/subdir
  • /mydir/subdir/anotherfile
  • /mydir/tmp
  • etc

37
Options for find
  • -print
  • use std output
  • usually not required
  • -type d
  • directory names only
  • -type f
  • file names only
  • note syntax
  • -option whitespace parameter
  • -ctime 3
  • files changed 3 days ago
  • -ctime -3
  • files changed within last 3 days
  • -atime 3
  • files accessed more than 3 days ago
  • -newer fred
  • display files that have been changed after the
    given file

38
File-name searches
  • -name pattern
  • Files/directories matching the given pattern
  • Pattern usually contains glob (wild card)
    constructs
  • example
  • find . -name ?onnet
  • Note quotes
  • the pattern is quoted so the shell does not
    resolve it first
  • find . -name ?onnet
  • becomes
  • find . -name sonnet bonnet
  • which gives a syntax error

39
find negating options with !"!" also known
as a "bang", "blast" or "not"
  • Use ! as in
  • find . ! -name ?onnet all files that dont
    match pattern
  • find . ! -ctime -365 changed more than a year
    ago
  • find . ! -newer sonnet files/dir not newer than
    sonnet
  • note you can combine options, as in
  • find /mydir -type f -newer ./sonnet
  • Find just files that are newer than sonnet
  • exercise does ! negate everything or just the
    next option?

40
Redirection, sort wildcards
  • David Turton
  • Conestoga College - 1B43, x8182
  • dturton_at_conestogac.on.ca

41
Redirection Operators
  • Redirect std output to file gt gtgt
  • redirect std error output 2gt 2gtgt
  • redirect std input from file lt
  • pipe std out to std in
  • tee pipe - file - pipe tee

42
Redirecting Standard i/o
  • Most utilities are not specifically designed to
    work together
  • most use standard input standard output
  • the shell allows you to piece utilities together
  • whosort gt user.list
  • "list everyone on the system, sort results by
    userid store in file user.list "

43
Redirection gt gtgt lt
  • Redirect std output to a file
  • cat gt new.file 2gtbad.msg
  • new.file is deleted recreated
  • any error messages go to file bad.msg
  • cat gtgt file2
  • append std output to file2 (current data
    unaffected)
  • Redirect std input to come from a file
  • mail fred lt broadcast.mail
  • have mail take its input from file, not keyboard

44
Pipe
  • reconnect std output of one command to std input
    to another command
  • same as two redirection commands but without an
    intervening file
  • whosort
  • same as
  • who gt temp.file
  • sort lt temp.file
  • rm temp.file

45
Pipe vs. redirection hints
  • View the redirection symbol as a funnel going to
    or coming from a container or file
  • gt gtgt lt
  • view a pipe as a pipeline between two continuous
    processes
  • ls -lR more
  • remember UNIX command-lines must start with a
    command and flow left to right
  • you cant lead with an input file name
  • the shell acts on the redirection before
    executing the command
  • the command doesnt know about it or see it

46
sort options sort-keys file-list
  • sort one (or more) files
  • if no files, uses std input (sorts from start of
    line to end of line)
  • if no -o option, uses std output
  • options
  • -d dictionary ignore punctuation
  • -f force to lowercase
  • -n numeric honour decimal, minus
  • -tc fields separated by character c (default
    blank or tab)
  • -o filename output file

47
sort keys -k m.noptions
  • m sort field
  • .n (optional) character from start of sort field
  • Options (applied to this key)
  • d dictionary order (ignore punctuation)
  • f sort as if all lowercase letters
  • M sort by month name
  • n sort as a number
  • r reverse order
  • Assume the following data
  • -rw-r--r-- 1 dturton wheel 29 Apr 17 1707
    people
  • sort -k 9f means
  • sort by file-name (people), force to use lower
    case

48
grep options string file-list
  • Returns all lines with the given string
  • From contents of given files
  • Std input used if no filenames given
  • Great for data piped from another command
  • options (some)
  • -c just count records that meet criteria
  • -i ignore case
  • ls -l grep fred
  • display records from directory listing that have
    fred in them

49
UNIX naming conventions
  • Up to 255 characters long
  • any character but /
  • recommend only use
  • A-Z
  • a-z
  • 0-9
  • . _ - (- not as 1st character)
  • otherwise the shell may misinterpret
  • i.e. variable names -r, togtfrom

50
Wildcard or glob constructs
  • - zero or more, any character
  • ? - 1 only 1, any character
  • 125-9 - 1 only 1 of given characters
  • ! - not version of above
  • \ - do not resolve wildcard(s)
  • Used for file-name "patterns"
  • Shell will resolve before command executes

51
? Single any-char substitution
  • means 1 and only 1 character
  • can be interpreted as any character
  • ls
  • memo memo1 memo10 memo2
  • echo memo?
  • memo1 memo2
  • memo 10 has 2 characters after memo
  • memo has 0 characters after memo

52
Multiple character substitution
  • means 0 or more characters
  • can be any character (or none)
  • ls
  • memo memo1 memo10 memo2
  • echo memo
  • memo memo1 memo10 memo2
  • echo memo1
  • memo1 memo10
  • echo memo3
  • memo3 note no files, passed as a string

53
single specific substitution
  • means 1 and only 1 character
  • matching only characters between braces
  • can use ranges, such as a-f
  • memo123 memo1 memo2 memo3
  • memo1-35 memo1 memo2 memo3 memo5
  • memo1-35 memo15 memo25 memo35

54
Wild Card Interpretation
  • Shell interpolates file name(s) from the working
    (or given) directory
  • passes file names found to command
  • if none found, passes string as given
  • ls
  • memo memo1 memo10 memo2
  • ls memo?
  • memo1 memo2
  • touch memo3?
  • ls
  • memo memo1 memo10 memo2 memo3?

55
Quoting
  • override the shells interpretation of a
    character
  • to exempt a single character
  • precede with \
  • grep \gt means look for gt sign inside the file
  • to exempt one or more characters
  • put between a pair of quotes (single or double)
  • grep gt
  • cp normal.var my long variable name

56
Echo
  • echoes everything on the command line
  • outputs to standard output device
  • good debug for wildcards
  • good for building a file line-by-line using gtgt
  • echo this is a free sentence
  • this is a free sentence
  • ls
  • memo memo1 memo10 memo2
  • echo memo?
  • memo1 memo2 lt--------shell interpreted before
    command was executed

57
Editors vi or Pico
58
UNIX Regular Expressions
  • Patterns for data, not file names

59
grep options string file-listusing regular
expressions on data
  • who grep 'cpa'
  • Return lines that contain "cpa"
  • who grep "cpa"
  • return lines that start with cpa

60
Wildcards or glob constructs
  • Examples
  • zero or more, any character
  • ? 1 and only 1, any character
  • 1 and only 1 of the given characters
  • ! 1 and only 1, not of the given characters
  • Used to generate a list of file names
  • I.e. not used when working with file content

61
Regular Expressions
  • Following match 1 character
  • start of line
  • end of line
  • 1 of given chars
  • . 1 of any char
  • \d 1 number, like 0-9
  • used when searching file content
  • not interpreted the same as wildcards used in
    file names
  • quote regular expressions
  • Else shell will interpret as file-name patten

62
Special consideration . and
  • How do you search for a period?
  • Use \ to override a special interpretation
  • grep \. nursery
  • all lines that end with a period
  • How do you say not one of these characters?
  • Use within braces
  • grep a-zhe nursery
  • matches She, The, but not she or the

63
Regular Expression Modifiers
  • For example
  • (http//)?
  • http// is optional, occurring once, if at all
  • a
  • At least 1 a, but there may be more
  • a-z1,3
  • At least 1, and no more than 3, lower-case
    letters
  • (webftp)? server
  • web server, ftp server or server at
    start-of-line
  • NAL.c
  • NAL followed by zero or more of any char, then
    c
  • Apply to preceding expression or character
  • zero or more
  • ? zero or one
  • one or more
  • n,m n to m times
  • Can act on
  • Single character
  • constructs
  • ( ) constructs
  • Special chars, like .

64
Where else are regular expressions used?
  • Anything looking at data
  • search-and-replace in vi
  • searching in more
  • tr, sed, awk, etc.
  • Netscape Proxy Server
  • JavaScript

65
File Permissions
  • David Turton
  • Conestoga College - 1B43 x8182
  • dturton_at_conestogac.on.ca

66
File Access Restrictions
  • Unix was designed to share data programs
  • but not everythings for everyone
  • limit HR/payroll access
  • control production code changes
  • 3 independent permission classifications
  • the owner/creator
  • the group the owner belongs to
  • everyone else

67
File Permission
  • Viewed via ls -l
  • drwxr-xr-x 1 dturton group1 2984 May 5 1005
    sub-dir
  • -rw-rw-r-- 1 dturton group1 256 May 7 1100
    file-a
  • owner owners group
  • (r--)others
  • (rw-) owners group
  • (rw-) owner
  • - file, d directory, l symbolic link

68
Directories are people too!
  • A directory is a file
  • which contains info pointers to other files
  • whose permissions say what you can do to it and
    its contents
  • you execute a directory to display its contents
    intelligently
  • you write to a dir. to add or delete a file

69
File vs Directories
  • Files
  • r - read
  • w - write (modify contents)
  • x - execute
  • Directory
  • r - read(list) directory contents
  • w - write to directory(add/del files sub-dirs)
  • x - required with read

70
chmod -R ugoa-rwx file-list
  • To change file permissions
  • -R recursive apply to all subsequent files/dir
  • ugoa user/owner, group, others, all three
  • - add(), remove(-), or set only() the
    following permissions
  • rwx read, write, execute
  • chmod go-r my.file
  • remove read permission to my.file for my group
    and others

71
chmod 777 file-list(absolute version)
  • 777- 1 digit each for owner, group, others
  • 4 - read sum, to get a
  • 2 - write single-digit
  • 1 - execute permission setting
  • examples
  • 644 - owner(read/write), groupothers(read only)
  • 755 - owner(read/write/exec), groupothers(read/ex
    ec)
Write a Comment
User Comments (0)
About PowerShow.com