Presentation on theme: "UNIX chapter 07 Files and File System Structure"— Presentation transcript:
1 UNIX chapter 07 Files and File System Structure Mr. Mohammad Smirat
2 IntroductionOne of the remarkable features of the UNIX operating system is the concept of files used in it.In UNIX a file is a sequence of bytes of data that reside in semi permanent form on some stable medium.This file can contains anything you can represent as a stream of bytes. So every thing including a network interface, a disk drive, a keyboard, a printer is treated as a file.As a result, all input and output devices are treated as files in UNIX, as described under file types and file system structure.
3 Introduction (cont…)File management in the UNIX system is extremely flexible and powerful.It provides a hierarchical directory scheme.A directory is a container for a group of files and directories, directories can be included in other directories.For example dir1/goodbye refers to the file goodbye in the directory dir1.
4 Files and directoriesA file is a sequence of bytes of data that resides on medium such as (disk..).Text file are a simple example of this structure, there is an ASCII character called newline is used to delimit lines, which create a logical text structure on a file.
5 Types of FilesSimple/ordinary file, used to store info and data on secondary storage device, typically a disk.It can contain a source program, an executable program such as compilers, DB tools, pictures, audio, graphics, and so on.Unix does not treat any kind of these files differently from others. For example a C++ file is no different to UNIX than an HTML file, however the files are treated differently by C++ compiler and WEB browser.
6 Types of Files (cont…)File names are limited to 14 chars in system V and 255 chars in BSD.To avoid any problem use only letters, numbers, period and underscore.Extensions have no meaning to UNIX, they are parts of files names, used by users to mark their files types.The following are the common files extensions: .bmp bit-mapped picture file. .c c source code. .C, .cpp c++ source code .gif graphics/picture file. .html file for a web page. .o object file .ps post script code .z compressed file
7 Types of Files (cont…)Directory files, directory file contains the name of other files and/or directories (sub directory).Directories have names just like other files, and these names obey the same naming rules as normal files.A directory is a place within the file system as a whole that contains files. This is analogous to a file drawer in your desk, where you can put things. You can construct filenames that include a directory as part of the name. The slash ‘/’ char is used to separate the different components of a file name of this form.
8 Types of Files (cont…)A directory is used to store a record for each file or subdirectory it contains.This record (also called directory entry) consists of the file inode number and the file name.inode (index node) is a 4 byte number and is an index for an array on the disk.An element of this array contains file attributes such as file size.
9 Types of Files (cont…)Link files, the link file points to the existing file, allowing you to rename an existing file and share it without duplicating its contents.A link is a way to establish connection between the file to be shared and the directory entries of the user who want to access the file. To establish that link you need to set up an appropriate permission to the file then issue the ln command to link the file to a directory. There is more in chapter 11 about link files.
10 Types of Files (cont…)Special files (devices), it is a mean of accessing hardware device, including the keyboard, hard disk, CD-ROM drive…etc.Each hardware device is associated with at least one special file.A command or an application accesses the special file in order to access the corresponding device.There are two types: a character special file for a char oriented devices such as for keyboard and block special file for block oriented devices such as a disk.Usually they reside in the /dev directory.
11 File System StructureThe UNIX file system is structured hierarchically upside down treelike, so it start with root directory and can have any number of files or sub directories under it. A typical UNIX system contains hundreds of files and directories, organized as the followingrootbintmpetcusershpspasswdProj aProj b
12 File System Structure (cont…) When you log on, the UNIX system puts you in a specific directory, called your home/logon directory. You can specify your home directory by using the tilde (~) when using C or Korn shell. The directory you are in at any particular time is call Present Working Directory pwd. Also called as current directory. The pwd is also denoted . (pronounced dot) the parent of the pwd is .. (dotdot).
13 Pathnames Pathnames can be specified in three ways Starting with root directory (/), absolute pathname.Starting with pwd, relative pathname.Staring with user home directory, relative pathname.
14 Standard Directories and Files Root directory (/), at the top of the file system hierarchy and denote as a slash (/), it is the master cabinet which contains all. Try command $ls /./bin it is known as binary directory, it contains binary -executables- images of most UNIX commands, including cat, kill, mv, rm, echo, date, mkdir, ksh, pwd...etc. all file in this directory either executable files or symbolic link to executables files. Usually it is a symbolic link to /usr/bin directory./dev it is the device directory, contains files corresponding to the devices (terminals, disk drives..) connected to the computer. These are the special files mentioned earlier. Some files like lp (line printer), hd (hard drive), tty (terminal) are example of these files.
15 Standard Directories and Files (cont…) /etc, contains commands and files for system administration. A typical user not allowed to use these files and commands. Files in this directory include login, passwd, and profile./lib, contains a collection of related files for a given language in a single file called an archive. Atypical UNIX system contains libraries for C, C++ and other languages. The archive file is used by application developed by that language. Some libraries are also stored in /usr/lib directory./lost+found, it contains all the files not connected to any directory. These files are found by a UNIX tool, fsck (file system check).
16 Standard Directories and Files (cont…) /tmp, it contains temporary files, all files are deleted periodically so the disk does not get filled with temp files. The life of this is set by system administrator./users, normally hold the home directories of all users of the system. It may be located in many various part of the file system structure./usr, it may hold some directories which contains the UNIX utilities, tools, languages, libraries, and manual pages. Two of the most important sub directories in this directory are /bin and /lib./var, it contains among several other directories, the /var/spool/mail directory that receive and holds your incoming mail messages, when you read your mail, it comes from a file in this directory, once you have read the mail, it is put in a file in your home directory called mbox.
17 Standard Directories and Files (cont…) /etc/passwd, contains one line for every user on the system and describes that followinguser login name, user name known to the system and type.password, encrypted version of the password.user-id, integer between 0 and assigned to the user, 0 is for super user, 1 through 99 are reservedgroup id, identify the group the user belong to and also is an integer from 0 touser info, typically the user full name.home directory, absolute path for the user home.login shell, absolute path for the user login shell.
18 Navigating the file structure $echo $HOME /usr/local/yourid $pwd /usr/local/youridYou can browse the file system by going from your directory to other directories in the file system structure and display a directory’s contents, provided that you have permission.$ cd[directory]will change the pwd to directory, or to the home directory if no argument is specified.
19 The ls commandls[option][pathname-list] to send the names of the files in the directories and files specified in pathname list to the display screen. Options are the following-F display `/` after directories, * after binaries, after symbolic.-a display name of all the files including the hidden files.-i display inode number.-l display long list that includes access permissions, link count, owner, group, file size.
20 Creating Files and Directories You can create files by using different tools and applications, such as editors (such as vi, emacs), and directories by using the mkdir command.To create a directory use the commandmkdir[options] dirnames options-m modes, create a directory with the given access permission ( permissions in chapter 8)-p create parent directories that do not exist in the pathnames specified in dirname.To remove a directory us the commandRmdir[options] dirname To remove the empty directories specified in dirname. Option -p to remove empty parent directory as well.
21 Ls with –l option$ls -l drxwr-x ymk faculty feb 10 08:25 mid1 drxwr-x ymk faculty feb 05 10:20 mid2-l option to get a long list of a directory that gives the attribute of files.first letter is for file type.access permission, user, group, and others.number of links.owner’s login name.owner’s group namefile size in bytes.date, time of last modification.file name.
22 Other usefull commands The ls -d for directory listing to list the name of a directory not its contents.file [options][file-list]will classify all the files in the file list. (determine their types).options are –f FILE as a file or file list.
23 Standard FilesUNIX automatically opens three files for every command it executes.The command reads its input from one file and sends its output and error messages to the other two files.These files are called standard files: standard input files, standard output files, and standard error files.These default files can be changed to other files using the redirection operators: < for input, > for output and errors redirection.File descriptor is small integer associated with every open files in UNIX. The integer values 0, 1, 2 are the file descriptors STDIN, STDOUT, and STRERR respectively.