System Administration Introduction to Unix Session 2 - PowerPoint PPT Presentation

About This Presentation
Title:

System Administration Introduction to Unix Session 2

Description:

The Unix Programming Environment, Kernighan & Pike, ISBN 0-13-937681-X. Albert Lingelbach, Jr. ... 24 lines, 80 columns. default shell: Bourne shell. to open a tty: ... – PowerPoint PPT presentation

Number of Views:108
Avg rating:3.0/5.0
Slides: 34
Provided by: redo2
Category:

less

Transcript and Presenter's Notes

Title: System Administration Introduction to Unix Session 2


1
System AdministrationIntroduction to
UnixSession 2 Fri 02 Nov 2007
  • Reference
  • chapter 1, The Unix Programming Environment,
    Kernighan Pike, ISBN 0-13-937681-X
  • Albert Lingelbach, Jr.alingelb_at_yahoo.com

2
History of Unix
  • Begun in 1969 at Bell Labs
  • Timesharing / MultiuserOne computer, many
    terminals
  • Programming
  • Typesetting
  • Group Communication

3
Architecture
  • Kernel
  • Windowing System
  • Gnome
  • Shell
  • Programs

4
The shell environment
  • tty (teletype) / terminal
  • text only
  • 24 lines, 80 columns
  • default shell Bourne shell
  • to open a tty right-click on desktop, choose
    Open Terminal
  • echo
  • print text to the tty
  • try echo Hello
  • what shell is running ?echo 0

5
Simple commands
  • bash
  • compatible with sh, added features
  • command history with up arrow
  • editable command line
  • backspace (vs. delete)?
  • date
  • system date and time
  • who
  • what users are on the system

6
Flow Control characters
  • ctrl-C
  • stop a running command
  • try troff
  • ctrl-S / ctrl-Q
  • pause/unpause output
  • try countdown 1000
  • end input
  • ctrl-D

7
Command Arguments / Parameters
  • mis-typed command
  • gold not found
  • command arguments / parameters
  • try who am i
  • try gold coins

8
User Communication
  • news
  • get local system news (written by the system
    administrator)?
  • try news
  • write
  • write messages to another user on the system
    like IM but local
  • try
  • pair off
  • using who, find userid of your partner
  • write userid(and your partner does
    same)exchange messages

9
Manual Pages
  • You have seen the following commands
  • date
  • who
  • news
  • write
  • sh
  • bash
  • How to find more about them ?
  • command -?often returns a short command synopsis
  • man commandreturns the complete manual page
    reference for the command

10
Files
  • As in any computer system, data is stored in
    files
  • Most Unix files are (ASCII) text
  • Many Unix commands manipulate text files

11
File Naming
  • case sensitive
  • spaces are problematic
  • dot and underscore are useful separators

12
File Commands 1
  • current (working) directory
  • pwd
  • print the working directory
  • ls
  • list the files in the working directory
  • cd path
  • change the working directory

13
File Paths 1
  • filenames without a path default to the current
    directory
  • example myfile.txt
  • / is the root or top of the file system tree
  • a file path contains directories separated by
    /(not \ as in DOS/windows)?
  • example /home/export/staff/alingelb/file.txt

14
File Paths 2
  • relative paths (not starting with /) start at
    the current directory
  • current directory (.)?
  • parent directory (..)?
  • relative to any preceding directory
  • examples
  • ./file.txt (the same as file.txt)?
  • ../../student/kate/file.txt
  • in general, any command that takes a file as an
    argument, will accept a path file (path/file)?

15
File Commands - 2
  • touch filename
  • create an empty file
  • example touch myfile.txt
  • rm filename
  • delete a file (forever be careful!)?
  • example rm myfile.txt
  • cp original_file new_file
  • copy a file
  • example cp myfile.txt copy_of_myfile.txt

16
File Commands - 3
  • mv original_file new_filename
  • mv original_file new_location
  • new_location must already exist
  • file keeps same name
  • mv original_file new_location/new_filename
  • move a file
  • examples mv myfile.txt newname.txtmv
    myfile.txt ..mv myfile.txt /usr/bin/students.txt

17
File Commands - 4
  • cat file
  • cat file1 file2 ...
  • display the contents of the file(s) on the screen
  • more file
  • display the contents of the file on the screen,
    on screenful at a time (press space for the next
    screen, return to advance one line)?
  • gedit file
  • edit the file in the gnome graphical editor

18
Directory Commands
  • mkdir dirname
  • mkdir path/dirname
  • create the directory
  • rmdir dirname
  • remove the directory (it must be empty)?

19
Shell filename wildcards 1
  • it can be useful to match filenames by pattern
  • matches any set of characters (or no
    characters)?
  • ? matches one character
  • examples
  • filematches any filename containing file
  • .txtmatches any filename that ends in .txt
  • thismatches any filename that starts with this

20
Shell filename 2 wildcards
  • More examples

21
Shell filename wildcards 3
  • More examples
  • cat chapter.txtwill output to the screen all
    files that start in chapter and end in .txt
  • ls .txtwill list all files that end in .txt
  • mv .txt /export/home/alingelbwill move all
    files ending in .txt to the directory
    /export/home/alingelb

22
More useful (text) file commands 1
  • grep pattern filesearch for the pattern in the
    file, and output the line(s) containing the
    pattern
  • sort filesort the lines of the file in
    alphabetical order
  • head filedisplay the first 10 lines of the file

23
More useful (text) file commands 2
  • tail filedisplay the last 10 lines of the file
  • wc filecount the number of lines, words, and
    characters in the file
  • diff file1 file2display the differences between
    the two files

24
File permissions 1
  • Every file has read, write, and execute
    permissions (RWX)?
  • These are set by the owner, for the owner, the
    group, and everyone else so there are 9
    permissions total (plus a few special ones to be
    discussed later).

25
File permissions 2
  • ls -lwill display file permissions, along with
    the group and owner
  • example ls -ltotal 3-rwxr-xr-x 2 alingelb
    staff 512 Nov 2 1038 Desktopdrwxr-xr-x
    3 alingelb staff 512 Oct 16 1115
    Documents-rw------- 1 alingelb staff
    40 Nov 2 1213 foonly.txt

26
File permissions 3
  • chmod fileis used to change file permissions
  • the first is owner permissions
  • the second is group permissions
  • the third is everyone else permissions
  • the is composed of(add the numbers)
  • 4 for read
  • 2 for write
  • 1 for execute

27
File permissions 4
  • chmod example
  • chmod 744 file
  • sets owner to read/write/execute
  • sets group to read
  • sets everyone else to read

28
Shell theory
  • The shell is a command interpreter
  • It interfaces between the user and programs and
    the kernel
  • It has its own syntax
  • In addition to providing access to programs and
    to the kernel, the shell has some powerful
    features of its own, including
  • wildcards
  • I/O redirection
  • scripting

29
I/O management 1
  • Every process has 3 channels of information
  • standard input
  • standard output
  • error output
  • These can be controlled by the shell
  • command gt file
  • sends the standard output of the command to a
    file
  • command lt file
  • sends the contents of a file to the standard
    input of the command
  • command gtgt file
  • appends the standard output of the command to the
    end of a file

30
std I/O management
  • Examples
  • ls gt listing.txt
  • echo this is a test gt test.txt
  • echo the test continues gtgt test.txt
  • echo 6 6 gt math.txt
  • bc lt math.txt

31
more I/O management
  • More I/O redirection
  • There is a special empty file/dev/null
  • it discards all output
  • command 2gt /dev/null
  • discards all error output
  • exampletouch testfilechmod 000 testfilecat
    testfile 2gt /dev/null
  • command1 command2
  • send the output of command1 as the input of
    command 2
  • example ls wc

32
I/O management pipe
  • Advanced example of pipe
  • wanted list of users on system. build it
    incrementally using pipe.
  • who gives list of users, but there are
    duplicates (because user appears once for each
    session)also, who gives too much information
  • using cut to remove extraneous informationwho
    cut -d\ -f1gives list of users, still with
    duplicates
  • who cut -d\ -f1 sortsorts list, putting
    duplicates together
  • who cut -d\ -f1 sort uniqremoves
    duplicates this is the desired list

33
Review
  • Concepts
  • Unix history, multiuser/timesharing, kernel,
    shell, man pages, file permissions
  • Flow control
  • ctrl-C, ctrl-S, ctrl-Q, ctrl-D
  • Commands
  • echo, bash, date, who, pwd, ls, cd, touch, rm,
    cp, mv, cat, more, gedit, mkdir, rmdir, grep,
    sort, head, tail, wc, diff, chmod, bc
  • File paths wildcards
  • , ?
  • I/O management
  • gt, gtgt, lt, , 2gt
Write a Comment
User Comments (0)
About PowerShow.com