chapter 4 the file structure. contents u the hierarchical file structure u directory and ordinary...

17
Chapter 4 Chapter 4 The File Structure The File Structure

Upload: kathlyn-simpson

Post on 13-Dec-2015

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Chapter 4 The File Structure. Contents u The Hierarchical File Structure u Directory and Ordinary Files u Directories u Access Permissions u Links

Chapter 4Chapter 4The File StructureThe File Structure

Page 2: Chapter 4 The File Structure. Contents u The Hierarchical File Structure u Directory and Ordinary Files u Directories u Access Permissions u Links

ContentsContents

The Hierarchical File Structure Directory and Ordinary Files Directories Access Permissions Links

Page 3: Chapter 4 The File Structure. Contents u The Hierarchical File Structure u Directory and Ordinary Files u Directories u Access Permissions u Links

The Hierarchical File StructureThe Hierarchical File Structure

ordinary file

ordinary file

ordinary file

ordinary file ordinary file directory

directorydirectorydirectory

directory

directory

Page 4: Chapter 4 The File Structure. Contents u The Hierarchical File Structure u Directory and Ordinary Files u Directories u Access Permissions u Links

Directory and Ordinary FilesDirectory and Ordinary Files

Filenames SunOS and Berkeley UNIX system - 255 characters Older version of UNIX - 14 characters Case-sensitive No two files in the same directory can have same name Filename Extensions

compute.c - a C programming language source file compute.o - the object code for the program compute - the same program as an executable file memo.0410 - a text file

Absolute Pathnames A path from the root(/) directory to the file

Page 5: Chapter 4 The File Structure. Contents u The Hierarchical File Structure u Directory and Ordinary Files u Directories u Access Permissions u Links

Directories (1/5)Directories (1/5)

The Working Directory The directory you are working in (=current directory) To access any file in the working directory, don’t need a

pathname Utility - pwd (print working directory)

Home Directory When first log in on UNIX system, the working directory is

home directory Startup Files

It gives the operating system specific information about you Bourne Shell and Korn Shell - .profile C Shell - .login

Page 6: Chapter 4 The File Structure. Contents u The Hierarchical File Structure u Directory and Ordinary Files u Directories u Access Permissions u Links

Creating a Directory Utility - mkdir [directory name]

‘ls’ does not distinguish between a directory and an ordinary file ( option: -F)

ls [directory name] - lists the contents of the directory

Directories (2/5)Directories (2/5)

[lab]/user3/kplee/work 59 > lsdong/ graph.c gu/ java/ mSQL/ project/ rand/ unix/[lab]/user3/kplee/work 60 > mkdir /user3/kplee/work/computer[lab]/user3/kplee/work 61 > lscomputer/ graph.c java/ project/ unix/dong/ gu/ mSQL/ rand/

Page 7: Chapter 4 The File Structure. Contents u The Hierarchical File Structure u Directory and Ordinary Files u Directories u Access Permissions u Links

Changing to Another Working Directory Utility - cd (change directory) Usage - cd [absolute pathname, relative pathname]

cd (with no argument) - change directory to the home directory . - synonymous with the pathname of the working directory .. - synonymous with the pathname of the parent of the working

directory

Deleting a Directory Utility - rmdir (remove directory) [rm -r] Usage - rmdir (rm -r) [absolute pathname, relative pathname] Cannot delete the working directory or a directory that

contains files

Relative Pathnames A path from the working directory to a file.

Directories (3/5)Directories (3/5)

Page 8: Chapter 4 The File Structure. Contents u The Hierarchical File Structure u Directory and Ordinary Files u Directories u Access Permissions u Links

Moving Files from One Directory to Another Utility - mv (move) Usage - mv existing-file-list destination-directory

Important Standard Directories and Files / (root)

The ancestor of all files in the file system

/home Typically each user’s home directory is subdirectories of the

/home directory

/usr Traditionally includes subdirectories that contain information

used by system

/usr/bin, /bin Contain the standard UNIX utility programs

Directories (4/5)Directories (4/5)

Page 9: Chapter 4 The File Structure. Contents u The Hierarchical File Structure u Directory and Ordinary Files u Directories u Access Permissions u Links

/usr/ucb Contain the networking utilities

/etc, /usr/etc Administrative, configuration,and other system files are kept

here /etc - includes utilities needed during the booting process /usr/etc - includes utilities that are most useful after the system

is up and running

/var Includes subdirectories contain the files that vary as the system

runs

/dev Include files that represent peripheral devices

/tmp Hold temporary files

Directories (5/5)Directories (5/5)

Page 10: Chapter 4 The File Structure. Contents u The Hierarchical File Structure u Directory and Ordinary Files u Directories u Access Permissions u Links

Access Permissions (1/3)Access Permissions (1/3)

Three type of users Owner Group Other

Three type of access Read Write Execute

Page 11: Chapter 4 The File Structure. Contents u The Hierarchical File Structure u Directory and Ordinary Files u Directories u Access Permissions u Links

The ls Utility with the -l and -g Options$ ls -lg letter.0610 check_spell

-rw-r--r-- 1 alex pubs 3355 May 2 10:52 letter.0610

-rwxr-xr-x 2 alex pubs 852 May 5 14:03 check_spell

the type of file (first character) ; d : directory, - : file the file’s access permissions (the next nine characters) the number of links to the file the name of the owner of the file the name of the group that has group access to the file the size of the file in characters (bytes) the date and time the file was created or last modified the name of the file

Access Permissions (2/3)Access Permissions (2/3)

Page 12: Chapter 4 The File Structure. Contents u The Hierarchical File Structure u Directory and Ordinary Files u Directories u Access Permissions u Links

Changing Access Permissions The owner of the files can modify the access permissions Utility - chmod (change mode) Usage - chmod [a,g,o][+,-]{r,w,x} filename Example

$ chmod a+rw letter.0610

$ ls -lg letter.0610

-rw-rw-rw- 1 alex pubs 3355 May 2 10:52 letter.0610

$ chmod o-rw check_spell

$ ls -lg check_spell

-rwxr-x--- 2 alex pubs 852 May 5 14:03 check_spell

Directory Access Permissions Directory cannot be executed

It means you can search through the directory

Access Permissions (3/3)Access Permissions (3/3)

Page 13: Chapter 4 The File Structure. Contents u The Hierarchical File Structure u Directory and Ordinary Files u Directories u Access Permissions u Links

Links (1/5)Links (1/5)

Link is a pointer to a file Objective - Sharing files Creating Additional Links

To share a file with another user Give the user permission to read and write to the file Allow the user to create a link to the file

Examplecorrespondence

personal memos business

to_do to_do to_do

to_do

personal memos business

Page 14: Chapter 4 The File Structure. Contents u The Hierarchical File Structure u Directory and Ordinary Files u Directories u Access Permissions u Links

Using ln to Create a Link Utility - ln (link) Usage - ln to-be-linked-filename new-filename Example (working directory is /home/jenny)

$ ln /home/alex/letter draft

Links (2/5)Links (2/5)

/

home

jennyalex

memo planning

/home/alex/letter and /home/jenny/draft

Page 15: Chapter 4 The File Structure. Contents u The Hierarchical File Structure u Directory and Ordinary Files u Directories u Access Permissions u Links

Links (3/5)Links (3/5)

Example ( 실습 )

$ cat file_aThis is file A.$ ln file_a file_b$ cat file_bThis is file A.$ vi file_b

$cat file_bThis is file B after the change.$cat file_aThis is file B after the change.

$ cat file_cThis is file C.$ cp file_c file_d$ cat file_dThis is file C.$ vi file_d

$cat file_dThis is file D after the change.$cat file_cThis is file C.

$ ls -l file_a file_b file_c file_d

$ ls -i file_a file_b file_c file_d

Page 16: Chapter 4 The File Structure. Contents u The Hierarchical File Structure u Directory and Ordinary Files u Directories u Access Permissions u Links

Links (4/5)Links (4/5)

Removing Links Use rm utility When last link is removed, OS release the space the file

occupied on the disk

Symbolic Links Comparison

Hard link - a pointer to a file Symbolic link - Indirect pointer to a file

– 실제 파일의 경로를 내용으로 가진 디렉토리 엔트리 필요성

디렉토리에 대한 hard link 는 superuser 만이 만들 수 있다 . 다른 파일 시스템 사이에는 hard link 를 사용할 수 없다 .

Page 17: Chapter 4 The File Structure. Contents u The Hierarchical File Structure u Directory and Ordinary Files u Directories u Access Permissions u Links

Symbolic Links (Cont.) Creating a Symbolic Link

Removing Hard and Symbolic Links A file exits only as long as a hard link to it exits When remove a file, be sure to remove all symbolic link to it

Links (5/5)Links (5/5)

[lab]/user3/kplee 42 > ln -s ./work/computer/ course[lab]/user3/kplee 44 > ls -al courselrwxrwxrwx 1 kplee archilab 15 Aug 13 19:43 course -> ./work/computer/[lab]/user3/kplee 45 > cd course[lab]/user3/kplee/course 46 > lstest_a test_b[lab]/user3/kplee/course 59 > pwd/user3/kplee/work/computer[lab]/user3/kplee/course 61 > echo $cwd/user3/kplee/course[lab]/user3/kplee/course 66 > cd ..[lab]/user3/kplee/work 67 > echo $cwd/user3/kplee/work