33
1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX The LINUX Filesystem Filesystem

1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

Embed Size (px)

Citation preview

Page 1: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

1© 2001 John Urrutia. All rights reserved.

Chapter 4

The LINUX FilesystemThe LINUX Filesystem

Page 2: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

2© 2001 John Urrutia. All rights reserved.

TopicsThe Hierarchical File System

Directory and Ordinary Files

Working With Directories

Access Permissions

Links

Page 3: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

3© 2001 John Urrutia. All rights reserved.

Hierarchical File SystemsStructured like an upside-down

tree

Grandparents at the top

Parents follow

Then Children

Topics

Page 4: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

4© 2001 John Urrutia. All rights reserved.

Child 1 Child 2 Child 3

Grandparent

Parent aunt uncle

/Alice /Bobby /Carol

/home /tmp /bin

Hierarchical Structure/

(aka root)

Page 5: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

5© 2001 John Urrutia. All rights reserved.

Hierarchical File SystemsDirectories and ordinary files

Directories / sub-directoriesSpecial files used for grouping

Ordinary FilesContain the kitchen sink

Page 6: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

6© 2001 John Urrutia. All rights reserved.

Directory assistanceDirectories provide an organized

method to access ordinary files.path –

A series of directory files traveling from the root to the ordinary file.

pathname – The sequenced listing of directory names

from the root to the ordinary file.

Page 7: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

7© 2001 John Urrutia. All rights reserved.

FilenamesFilenames

Max length 255 characters

A thru Z, a thru z, 0 thru 9 _ . ,Some file systems limit these to 14 characters

Make them meaningful30952344 IMd12CRU OOicu812

Page 8: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

8© 2001 John Urrutia. All rights reserved.

Filename ExtensionsBegins with a period

Generally are optional

Used by applications to identify specific file needed by the applicationExamples: CPP TXT INI

Page 9: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

9© 2001 John Urrutia. All rights reserved.

Invisible FilesMust start with a period

Normally not displayed

Used by Unix for special purposes

Use “ls –a” to see these

˜

Page 10: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

10© 2001 John Urrutia. All rights reserved.

TopicsThe Hierarchical File System

Directory and Ordinary Files

Working With Directories

Access Permissions

Links

Page 11: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

11© 2001 John Urrutia. All rights reserved.

Creating a directorymkdir – utility creates a directory

The argument can either specify an absolute pathname or a relative pathname

mkdir mydirectoryIn this example “mydirectory” will be

created under the current or working directory

Page 12: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

12© 2001 John Urrutia. All rights reserved.

Directory fileTwo invisible files are created for

each directory createdOne is the pathname of the working

directory named “”

Two is the pathname of the parent directory named “ ”cat ./Test.filecat Test.file

Page 13: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

13© 2001 John Urrutia. All rights reserved.

Path (to glory or destruction)

Every file has a PATHNAMEAbsolute Pathnames begin with the root

(/)

Each directory in the hierarchy from the root to the file is separated by a slash

Page 14: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

14© 2001 John Urrutia. All rights reserved.

Test.file

Path example:

/Alice /Bobby /Carol

/home /tmp /bin

//

/home

/Bobby

Test.file

/home/Bobby/Test.file

Page 15: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

15© 2001 John Urrutia. All rights reserved.

Absolute & Relative PathAbsolute path is fully qualified

cat /home/Bobby/Test.file

Relative path is based on the working directorypwd – Print Working Directory

/home/Bobbycat Test.file

Page 16: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

16© 2001 John Urrutia. All rights reserved.

The Working DirectoryYou’re working directory is assigned

by the login process.

To access files in working directory simply refer to the filename no path is needed.

Files outside your working directory require a pathname.

Page 17: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

17© 2001 John Urrutia. All rights reserved.

Your Working DirectoryGenerally you’re working directory

will be/home/userid

Page 18: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

18© 2001 John Urrutia. All rights reserved.

Important Directories and FilesThe root - / (of all evil)

/root – Home directory for root

/boot – static files of the boot loader

/bin – files needed to boot the system

/sbin – /usr/sbin system admin. utilities

/dev – device files

/etc – admin. and configuration files

Page 19: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

19© 2001 John Urrutia. All rights reserved.

Important Directories and Files/tmp – temporary files

/home – user home directories

/lib – shared libraries

/mnt – mount point of temporary partitions

/tmp – temporary files

/usr – 2nd major hierarchy – rarely change

/proc – kernel and process information

Page 20: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

20© 2001 John Urrutia. All rights reserved.

Changing working directorypwd – displays your working directory

cd - change directoryBy default places you in your working

directory(ie /home/userid)

cd ~ (will do the same thing)

cd path/path1 – changes relative to your working directory

Page 21: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

21© 2001 John Urrutia. All rights reserved.

Access PermissionsEvery file has access “permissions”

associated with them.r – read

w – write

x – execute

Page 22: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

22© 2001 John Urrutia. All rights reserved.

Access PermissionsEvery ordinary file has three access

groups.Owner or User

User who created the file

GroupUsers who are associated

OthersThe rest of the world

Page 23: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

23© 2001 John Urrutia. All rights reserved.

Access PermissionsDirectory file access “permissions”

r – read the directory

w – write the directory

x – search the directory

Page 24: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

24© 2001 John Urrutia. All rights reserved.

Access PermissionsSetting default “permissions”

umask 000One digit each for U,G,OOctal value representing the 3 bits

R W X R W X R W X

4 2 1 4 2 1 4 2 1

Page 25: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

25© 2001 John Urrutia. All rights reserved.

Directory Utilitieschmod – change access mode

u – User or owner

g – group

o – others

+ – add permission

- – remove permission

Page 26: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

26© 2001 John Urrutia. All rights reserved.

Directory Utilitiesmkdir – Make Directory

mkdir –p directory-listThe –p option creates the parent

directory if it doesn’t existdirectory-list

One or more directories separated by space

Page 27: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

27© 2001 John Urrutia. All rights reserved.

Directory Utilitiesrmdir – remove Directory

rmdir directory-listdirectory-list

One or more directories separated by space

Page 28: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

28© 2001 John Urrutia. All rights reserved.

Directory Utilitiesrm – remove

rm –r directory-listThe –r option removes recursively. All

subdirectories are removeddirectory-list

One or more directories separated by space

Page 29: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

29© 2001 John Urrutia. All rights reserved.

Directory Utilitiescd – change directory

cd directory The directory (pathname) becomes the

working directory

Page 30: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

30© 2001 John Urrutia. All rights reserved.

Linksaka – Also Known As

Creates an entry in the directory that point to an existing file or directory.

Doesn’t create a copy of the file

Page 31: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

31© 2001 John Urrutia. All rights reserved.

Links – Hard and SymbolicHard links

Behave just like a file

Cannot distinguish the original filename from the link

Cannot cross file systems

Directory links by superuser only

Page 32: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

32© 2001 John Urrutia. All rights reserved.

Links – Hard and SymbolicSymbolic links

Indirect pointer to file or directory

Can be created by anyone

Can reside anywhere

Can become an orphan

Page 33: 1 © 2001 John Urrutia. All rights reserved. Chapter 4 The LINUX Filesystem

33© 2001 John Urrutia. All rights reserved.

Link Utilityln – Make a link entry

ln [–s] filename linkname

ln [–s] file-list directory