24
zef Goetz, 2012 1 Jozef Goetz contribution, 2012 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar, Robert Koretsky, Syed A. Sarwar, 2005 Addison Wesley

Jozef Goetz, 2012 1 Jozef Goetz contribution, 2012 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar,

Embed Size (px)

Citation preview

Page 1: Jozef Goetz, 2012 1 Jozef Goetz contribution, 2012 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar,

Jozef Goetz, 2012

1

Jozef Goetz contribution, 2012

Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar, Robert Koretsky, Syed A. Sarwar, 2005 Addison Wesley

Page 2: Jozef Goetz, 2012 1 Jozef Goetz contribution, 2012 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar,

Jozef Goetz, 2012

2Objectives You may ignore last slides 19 – 24

To explain the UNIX file concept To discuss various types of files supported by UNIC To describe attributes of a file To explain the notion of pathnames To explain the user view of the UNIX file system To describe the user’s interface to the UNIX file system -

browsing the file system To discuss representation of a file inside the UNIX

system To describe how a UNIX file is stored on the disk To explain the concept of standard files in UNIX To cover the commands and primitives ~ , . , .. , / ,

PATH, cd, echo, file, ls, mkdir , pwd , rmdir

Page 3: Jozef Goetz, 2012 1 Jozef Goetz contribution, 2012 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar,

Jozef Goetz, 2012

37 Types of Files1. Simple/ordinary file

2. Directory

3. Symbolic (soft) link

4. Special (device) files block special files and character

special files

5. Named pipe (FIFO)

6. Socket

Page 4: Jozef Goetz, 2012 1 Jozef Goetz contribution, 2012 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar,

Jozef Goetz, 2012

4

1. Types of Files Simple/ Ordinary File

File names – 14 letters in System V - 255 letters in BSD

UNIX doesn’t impose any naming conventions on files of any types

Page 5: Jozef Goetz, 2012 1 Jozef Goetz contribution, 2012 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar,

Jozef Goetz, 2012

5

Types of Files 2. Directory

• Inode number is 4 bytes and is an index value for an array on the disk.

• An element of this array is an index node (inode) contains such as file size.

• UNIX kernel allocates an inode whenever a new file is created

[cs253u@shell cs253u]$ ls -i 5671882 myFile• Where 5671882 is an index number

Page 6: Jozef Goetz, 2012 1 Jozef Goetz contribution, 2012 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar,

Jozef Goetz, 2012

6Types of Files 3. Symbolic Link

Link File A Link File is created by the system when a

symbolic link in created to an existing file. it allows you to rename an existing file and

share it without duplicating its contents[jgoetz@faculty ~]$ cat > myline 1<CTRL>+D

[jgoetz@faculty ~]$ link my my1[jgoetz@faculty ~]$ cat >> myline 2 <CTRL>+D

[jgoetz@faculty ~]$ cat my1line 1line 2

Page 7: Jozef Goetz, 2012 1 Jozef Goetz contribution, 2012 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar,

Jozef Goetz, 2012

7

4. Special (Device) File

A special File is a means of accessing hardware devices, including the keyboard, hard disk, CD-ROM drive, tape drive and printer.

Character Special Files Correspond to character-oriented

devices (e.g., Keyboard) Block Special Files

Correspond to block-oriented devices (e.g., a disk)

Page 8: Jozef Goetz, 2012 1 Jozef Goetz contribution, 2012 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar,

Jozef Goetz, 2012

8

4. Special (Device) File

/dev directory contains at least 1 file for every device connected to the computer e.g, fd0 – for floppy drive 0 hda - for hard disk drive a lp0 - for line printer 0 tty – for terminal

applications and cmds read/write peripheral device files in the same way that read/write an ordinary file

Page 9: Jozef Goetz, 2012 1 Jozef Goetz contribution, 2012 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar,

Jozef Goetz, 2012

9 5. Named Pipe (FIFO) 6. Sockets

Tools that enable processes to communicate with each other

client-server paradigm called interprocess communication mechanism – IPC

A FIFO is a file that allows 2 processes to communicate with each other, if Ps are on the same computer

A socket allows 2 processes to communicate with each other, if Ps are on the different computer

On System V UNIX system, a socket file type means a UNIX domain socket

Page 10: Jozef Goetz, 2012 1 Jozef Goetz contribution, 2012 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar,

Jozef Goetz, 2012

10File System Structure File System Organization – => Home and Present Working

Directories $HOME, ~, $home - Home Working

Directory pwd - Present Working Directory . – current working directory .. – parent of the present working

directory

Pathnames: Absolute – starting from the root Relative - starting from the present

working dir

Multiple disk drives: files mounted on the same file system

structure can be accessed as if they are part of the file structure one disk

Some Standard Directories and Files Root directory (/), /bin, /dev, /etc, /lib…

Page 11: Jozef Goetz, 2012 1 Jozef Goetz contribution, 2012 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar,

Jozef Goetz, 2012

11

A Typical UNIX File System Structure

Page 12: Jozef Goetz, 2012 1 Jozef Goetz contribution, 2012 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar,

Jozef Goetz, 2012

12Standard Directories and Files Some Standard Directories and Files

/ - Root directory /bin – binary files /dev – device files /etc – cmds and files for system

administration inetd.conf, login, printcap, rc.d, services,

termcap,… passwd –a contains info for users, each

line (7 fields) is as follows: login_name:password:user_ID:user_info:

home_directory:login_shell From /etc use cmd: cat passwd or cat /etc/passwd

/lib – all essential lib /users – hold all the users (home

directories) /usr – utilities, tools, language lib, and

manual pages /bin - binary images of utilities, tools etc. /lib - language lib

/var – other directories and /spool/mail that receives and holds incoming –emails

/unix or /kernel – binary image of UNIX kernel loaded into memory at bootup time

Page 13: Jozef Goetz, 2012 1 Jozef Goetz contribution, 2012 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar,

Jozef Goetz, 2012

13Navigating the File Structure

Determining the Absolute Pathname for Your Home Directory

echo [string] echo $HOME

Browsing the File System cd [directory] ls [options] [pathname-list]

Page 14: Jozef Goetz, 2012 1 Jozef Goetz contribution, 2012 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar,

Jozef Goetz, 2012

14Navigating the File Structure

[cs253u@shell cs253u]$ ls -ls * // display the content of each directory from the current one // -l use a long listing format

// -s, --size print size of each file, in blocks – 1st number at the column // -S sort by file size 4 -rwxrw-r-- 1 cs253u cs253u 18 Apr 19 11:24 case_demo 4 -rwxrw-r-- 1 cs253u cs253u 155 Apr 26 16:23 d 4 -rwxrw-r-- 1 cs253u cs253u 280 Apr 18 22:48 ex_add_all_ch16 4 -rwxrw-r-- 1 cs253u cs253u 1174 Apr 19 17:20 ex_add_param_my 4 -rwxrwxrwx 1 cs253u cs253u 114 Mar 31 00:31 ex_input 4 -rwxrw-r-- 1 cs253u cs253u 425 Apr 19 14:21 ex_nslookup_lab10_ex6 4 -rwxr-xr-x 1 cs253u cs253u 27 Apr 12 09:48 ex_simple 4 -rwxrw-r-- 1 cs253u cs253u 466 Apr 18 23:11 ex_sum_nat_#_ch16 4 -rw-rw-r-- 1 cs253u cs253u 269 Apr 18 18:47 ex_while 4 -rwxrw-r-- 1 cs253u cs253u 269 Apr 12 01:16 ex_while1 0 -rw-rw-r-- 1 cs253u cs253u 0 Apr 12 15:24 sort

mail:total 8 4 -rwx------ 1 cs253u cs253u 505 Feb 9 17:03 saved-messages 4 -rwx------ 1 cs253u cs253u 918 Feb 9 17:05 sent-mail

personal:total 0

professional:total 0

temp:total 0[cs253u@shell cs253u]$

Page 15: Jozef Goetz, 2012 1 Jozef Goetz contribution, 2012 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar,

Jozef Goetz, 2012

15

Navigating the File Structure

Page 16: Jozef Goetz, 2012 1 Jozef Goetz contribution, 2012 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar,

Jozef Goetz, 2012

16

Creating Files pico, vi, emacs

Creating and Removing Directories mkdir [options] dirnames, rmdir [options] dirnames

Determining File Attributesls –l, ls –i, ls –al, ls –F, ls -RC -F, --classify = append indicator (one of */=@|) to entries; @ - symbolic link, unix* - executable -R, --recursive = list subdirectories recursively -C list entries by columns

ls -RC

.:

dead.letter m mail mydir myPATH new1

./mail:

saved-messages sent-mail

./mydir:

Navigating the File Structure

Page 17: Jozef Goetz, 2012 1 Jozef Goetz contribution, 2012 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar,

Jozef Goetz, 2012

17

Navigating the File Structure

drwxrwxrwx 1 sarwar faculty 512 May 12 23:44 solutions

Page 18: Jozef Goetz, 2012 1 Jozef Goetz contribution, 2012 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar,

Jozef Goetz, 2012

18Navigating the File Structure

$ ls -i

12329 courses 22876 memos 12487 personal

$ ls -al ~/courses/ee446/exams

drwxr-x-- 1 sarwar faculty 512 Mar 16 08:24 .

drwxr-x-- 1 sarwar faculty 512 Jan 29 13:27 ..

-rwxr--r-- 1 sarwar faculty 1863 Mar 16 11:10 mid1

-rwxr--r-- 1 sarwar faculty 459 Apr 11 14:34 mid22

drwxrwxrwx 1 sarwar faculty 512 May 12 23:44 solutions

$ ls -F /

bin/ dev/ etc/ install@ lost+found/ tmp/ usr/ unix*

install@ - symbolic link

unix* - executable

$ ls -l ~/courses/ee446/lab[^5]*.c

[^5] – cannot be 5

$ ls ~/[^0-9]*.[c,C]

- not start with a digit and end with c. or C.

Page 19: Jozef Goetz, 2012 1 Jozef Goetz contribution, 2012 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar,

Jozef Goetz, 2012

19Determining the Type of a File’s Contents

file [options] file-list$ file * - all files in pwd

$ file /* in rootall.backup: POSIX tar archivebin: directorydev: directoryetc: directoryinstall: symbolic link to var/lib/LSTlost+found: directorytmp: directoryusr: directoryunix: ELF 32-bit LSB executable$

Page 20: Jozef Goetz, 2012 1 Jozef Goetz contribution, 2012 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar,

Jozef Goetz, 2012

20File Representation and Storage in UNIX

•attributes of a file are stored in a

data structure on the disk , called inode:•Link Count - # of different names the file has within the system•File Mode – what the file was open for read, write, etc•User ID – the owner of the file•Access Permissions – who can access the file•File’s Location on Disk – a direct or indirect pointers to the disk

blocks containing file data

Page 21: Jozef Goetz, 2012 1 Jozef Goetz contribution, 2012 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar,

Jozef Goetz, 2012

21File Representation and Storage in UNIX

UNIX kernel maps the inode of the file lab1.c to its contents on disk

use of id # to index the inode table

•Link Count - # of different names the file has within the system•File Mode – what the file was open for read, write, etc•User ID – the owner of the file•Access Permissions – who can access the file•File’s Location on Disk – a direct or indirect pointers to the disk

blocks containing file data

Page 22: Jozef Goetz, 2012 1 Jozef Goetz contribution, 2012 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar,

Jozef Goetz, 2012

22

Standard Files and File Descriptors

uses to index

uses to index

To open and the issue a

file I/O operations: read, write, seek, etc. UNIX automatically opens 3 files for every cmd it executes: sdin, stout and sderr.

File descriptor: a small integer that the UNIX kernel attaches with every open filestandard input (sdin) — file descriptor 0standard output (stout) — file descriptor 1 standard error (sderr) — file descriptor 2

Page 23: Jozef Goetz, 2012 1 Jozef Goetz contribution, 2012 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar,

Jozef Goetz, 2012

23

Standard Files and File Descriptors•The input, output and errors of a command

can be redirected to other files by using file redirection facilities in UNIX

Here the sdin input – default keyboardstout output – default display screensderr error – default display screen

Page 24: Jozef Goetz, 2012 1 Jozef Goetz contribution, 2012 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar,

Jozef Goetz, 2012

24

Standard Files and File Descriptors

•The input, output and errors of a command can be redirected to other files by using file redirection facilities in UNIX

Here the sdin input 0– default keyboardstout output 1 – default display screensderr error 2 – was redirected to lab1.c

The other descriptors usually range from 3 through 19 are called user-defined file descriptors.