Jozef Goetz, expanded by Jozef Goetz, 2009 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, Objectives 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
Jozef Goetz, Types of Files 1. 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
Jozef Goetz, Types of Files Simple/ Ordinary File File names – 14 letters in System V letters in BSD UNIX doesn’t impose any naming conventions on files of any types
Jozef Goetz, 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]$ ls -i myFile Where is an index number
Jozef Goetz, Types 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
Jozef Goetz, 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)
Jozef Goetz, 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
Jozef Goetz, 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
Jozef Goetz, File 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…
Jozef Goetz, A Typical UNIX File System Structure
Jozef Goetz, Standard 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 – s /unix or /kernel – binary image of UNIX kernel loaded into memory at bootup time
Jozef Goetz, Navigating 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]
Jozef Goetz, Navigating the File Structure 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 – 1 st 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 cs253u cs253u 505 Feb 9 17:03 saved-messages 4 -rwx cs253u cs253u 918 Feb 9 17:05 sent-mail personal: total 0 professional: total 0 temp: total 0 cs253u]$
Jozef Goetz, Navigating the File Structure
Jozef Goetz, Creating Files pico, vi, emacs Creating and Removing Directories mkdir [options] dirnames, rmdir [options] dirnames Determining File Attributes ls –l, ls –i, ls –al, ls –F, ls -RC -F, --classify = append indicator (one of to - 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
Jozef Goetz, Navigating the File Structure drwxrwxrwx 1 sarwar faculty 512 May 12 23:44 solutions
Jozef Goetz, Navigating the File Structure $ ls -i courses memos 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/ lost+found/ tmp/ usr/ unix* - 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.
Jozef Goetz, Determining the Type of a File’s Contents file [options] file-list $ file * - all files in pwd $ file /* in root all.backup: POSIX tar archive bin:directory dev:directory etc:directory install:symbolic link to var/lib/LST lost+found:directory tmp:directory usr:directory unix:ELF 32-bit LSB executable $
Jozef Goetz, File Representation and Storage in UNIX attributes of a file are stored in a data structure on the disk, called inode:
Jozef Goetz, File 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
Jozef Goetz, 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 file standard input (sdin) — file descriptor 0 standard output (stout) — file descriptor 1 standard error (sderr) — file descriptor 2
Jozef Goetz, 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 keyboard stout output – default display screen sderr error – default display screen
Jozef Goetz, 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 keyboard stout output 1 – default display screen sderr error 2 – was redirected to lab1.c The other descriptors usually range from 3 through 19 are called user-defined file descriptors.