Advanced UNIX CIS 118 Intro to UNIX 1 . The File Structure (Ch. 4 , - - PowerPoint PPT Presentation

advanced unix
SMART_READER_LITE
LIVE PREVIEW

Advanced UNIX CIS 118 Intro to UNIX 1 . The File Structure (Ch. 4 , - - PowerPoint PPT Presentation

Advanced UNIX CIS 118 Intro to UNIX 1 . The File Structure (Ch. 4 , Sobell) Objectives to supplement the Introduction to UNIX slides with extra information on files 1 CIS 118 Intro to UNIX Overview 1 . Access Permissions 2 . Links 2


slide-1
SLIDE 1

CIS 118 Intro to UNIX 1

Advanced UNIX

 Objectives

– to supplement the “Introduction to UNIX” slides with extra information on files

CIS 118 Intro to UNIX

  • 1. The File Structure

(Ch.4, Sobell)

slide-2
SLIDE 2

CIS 118 Intro to UNIX 2

Overview

1. Access Permissions 2. Links

slide-3
SLIDE 3

CIS 118 Intro to UNIX 3

  • 1. Access Permissions

1.1 Types of Users and Access 1.2 More File Information 1.3 Access Permission Characters 1.4 Changing Permissions

slide-4
SLIDE 4

CIS 118 Intro to UNIX 4

1.1. Types of User and Access

 Types of user:

– creator / owner u – group g – others

  •  Types of access:

– read r – write w – execute x

slide-5
SLIDE 5

CIS 118 Intro to UNIX 5

1.2. More File Information

$ ls -lF

  • rwxr-xr-x 1 ad users 443275 Sep 26 15:02 BLP.gz*
  • rwxr-xr-x 2 ad users 852 May 5 14:03 check_spell

drwxr-xr-x 2 ad users 1024 Sep 26 16:04 curses/

  • rw-r--r-- 1 ad users 3355 May 2 10.52 letter.txt

 Meaning (left to right):

– file type (first char) – file access permission (9 chars) – number of links – owner’s name – group name

  • byte size of file
  • creation time/

last modified

  • name, with / or *

ending

slide-6
SLIDE 6

CIS 118 Intro to UNIX 6

1.3. Access Permission Chars

 First 3 chars:

– refer to creator/owner (u)

 Middle 3 chars:

– refer to group (g)

 Last 3 chars:

– refer to everyone else (o)

slide-7
SLIDE 7

CIS 118 Intro to UNIX 7

 The 3 characters for u, g, and o have the

same format:

– First character indicates whether the file can be read (r). For a directory, this means you can do a ls. – Second character indicates whether the file can be written to (w). For a directory, you can add/remove files. – Third character indicates whether the file can be executed (x). For a directory, you can do a cd. A bit hard to remember

slide-8
SLIDE 8

CIS 118 Intro to UNIX 8

1.4. Changing Permissions

chmod who+what file

// add a permission

chmod who-what file // remove who: u, g, o, a (all) what: r, w, x

and combinations

 Examples:

chmod u+x foo-p chmod a+rw letter.txt chmod o-rx check_spell

slide-9
SLIDE 9

CIS 118 Intro to UNIX 9

$ chmod a+rw letter.txt $ ls -lg letter.txt

  • rw-rw-rw- 1 ad staff 3355 May 2 10:52 letter.txt

$ chmod o-rx check_spell $ ls -lg check_spell

  • rwxr-x--- 2 ad staff 852 May 5 14:03 check_spell
slide-10
SLIDE 10

CIS 118 Intro to UNIX 10

Warning

 Your files and directories are automatically

protected correctly.

 Don’t change their permissions unless you

really know what you are doing.

slide-11
SLIDE 11

CIS 118 Intro to UNIX 11

Directory Access

 Let everyone ls, add/remove and cd to my

info directory:

$ chmod a+rwx /home/ad/info  Check permissions: $ ls -ldF /home/ad/info drwxrwxrwx 3 ad staff 112 Apr 15 11:05 /home/ad/info

slide-12
SLIDE 12

CIS 118 Intro to UNIX 12

  • 2. Links

2.1 What is a Link? 2.2 Creating a Link 2.3 Seeing Links 2.4 Removing a Link 2.5 Symbolic Links

slide-13
SLIDE 13

CIS 118 Intro to UNIX 13

2.1. What is a Link?

 A link is a pointer to a file.  Useful for sharing files:

– a file can be shared by giving each person their

  • wn link (pointer) to it.
slide-14
SLIDE 14

CIS 118 Intro to UNIX 14

2.2. Creating a Link

ln existing-file new-pointer

 Jenny types:

ln draft /home/ad/letter

/ home ad jenny memo planning /home/jenny/draft and /home/ad/letter

slide-15
SLIDE 15

CIS 118 Intro to UNIX 15

 Changes to a file affects every link: $ cat file_a This is file A. $ ln file_a file_b $ cat file_b This is file A. $ vi file_b : $ cat file_b This is file B after the change. $ cat file_a This is file B after the change.

slide-16
SLIDE 16

CIS 118 Intro to UNIX 16

2.3. Seeing Links

 Compare status information:

$ ls -l file_a file_b file_c file_d

  • rw-r--r-- 2 ad 33 May 24 10:52 file_a
  • rw-r--r-- 2 ad 33 May 24 10:52 file_b
  • rw-r--r-- 1 ad 16 May 24 10:55 file_c
  • rw-r--r-- 1 ad 33 May 24 10:57 file_d

 Look at inode number: $ ls -i file_a file_b file_c file_d 3534 file_a 3534 file_b 5800 file_c 7328 file_d

slide-17
SLIDE 17

CIS 118 Intro to UNIX 17

 Directories may appear to have many links:

drwxr-xr-x 23 ad users 1024 Jan 12 2000 BLP/

 This is because subdirectories (e.g.

directories inside BLP/) have a link back to their parent.

slide-18
SLIDE 18

CIS 118 Intro to UNIX 18

2.4. Removing a Link

 Deleting a link does not remove the file.  Only when the file and every link is gone

will the file be removed.

slide-19
SLIDE 19

CIS 118 Intro to UNIX 19

2.5. Symbolic Links

 The links described so far are often called

hard links

– a hard link is a pointer to a file which must be

  • n the same filesystem

 A symbolic link is an indirect pointer to a

file

– it stores the pathname of the pointed-to file – it can link across filesystems

slide-20
SLIDE 20

CIS 118 Intro to UNIX 20

 Jenny types:

ln -s shared /home/ad/project

/ home ad jenny memo planning /home/jenny/shared and /home/ad/project separate filesystem

slide-21
SLIDE 21

CIS 118 Intro to UNIX 21

 Symbolic links are listed differently:

$ ln -s pics /home/ad/images $ ls -lF pics /home/ad/images drw-r--r-- 1 ad staff 981 May 24 10:55 pics lrwxrwxrxw 1 ad staff 4 May 24 10:57 /home/ad/images --> pics

slide-22
SLIDE 22

CIS 118 Intro to UNIX 22

 Symbolic links can confuse:

$ ln -s /home/ad/grades /tmp/grades-old

$ cd /tmp/grades-old $ pwd /home/ad/grades $ echo $cwd (C Shell only) /tmp/grades-old $ cd .. $ echo $cwd /home/ad