Download presentation
Presentation is loading. Please wait.
1
1.1 File System Implementation A possible file system layout
2
1.2 Implementing Files Storing a file as a linked list of disk blocks
3
1.3 Index Node (inode) Each file of whatever type, stored in a disk partition, is allocated a number (called its inode number) which is actually the index number of an entry in an array stored on the disk. Each element of the array is an inode which stores the administrative information about a single file (such as, when it was created, who owns it and where the data blocks for this file are stored on the disk partition). This information can be displayed by using stat: $ stat file1 File: `file1' Size: 123 Blocks: 8 IO Block: 4096 Regular File Device: 306h/774d Inode: 32787 Links: 2 Access:(0644/-rw-r--r--)Uid:(501/rinaldi)Gid:(501/docenti) Access: 2003-03-31 12:58:37.000000000 +0200 Modify: 2003-03-31 12:58:25.000000000 +0200 Change: 2003-04-04 19:05:14.000000000 +0200
4
1.4 Implementing Files An example i-node: it contains only the first 12 addresses of the blocks of the file.
5
1.5 A UNIX i-node
6
1.6 Index Node (inode) It is the inode number of a file that is stored in a directory alongside the file's name. So, essentially, directories are just tables that associate file names with inode numbers. Each file name and inode number pair in a directory is called a link. games mail news work inode
7
1.7 Linking Files A link is a pointer to another file. Remember that a directory is nothing more than a list of the names and i-numbers of files. A directory entry can be a hard link, in which the i-number points directly to another file. When a hard link is made, then the i- numbers of two different directory file entries point to the same inode. ln utility makes link between files. $ cat > file Hello ! ^D $ ls -l file -rw-rw-r-- 1 rinaldi rinaldi 8 apr 7 14:22 file $ ln file fileln $ ls -li file* 12004 -rw-rw-r-- 2 rinaldi rinaldi 8 apr 7 14:22 file 12004 -rw-rw-r-- 2 rinaldi rinaldi 8 apr 7 14:22 fileln $ rm file $ ls -l fileln -rw-rw-r-- 1 rinaldi rinaldi 8 apr 7 14:22 fileln
8
1.8 Linking Files If the last argument is the name of a directory, then the hard link is made from the directory to all the specified filenames $ mkdir ~/didattica/corsi $ ln file* ~/didattica/corsi $ ls -l -rw-rw-r-- 2 rinaldi rinaldi 8 apr 7 14:22 fileln $ cd $ rm fileln $ ls -l ~/didattica/corsi/ -rw-rw-r-- 1 rinaldi rinaldi 8 apr 7 14:22 fileln A hard link may not be created from a file on one file system to a file on a different file system. To get around this problem, create a symbolic link instead.
9
1.9 Linking Files By default, ln makes hard links, with the “-s” option, it makes symbolic (or "soft") links. $ ln -s /usr/include/stdio.h stdio.h $ ls -l stdio.h lrwxrwxrwx 1 rinaldi rinaldi 20 apr 7 14:46 stdio.h -> /usr/include/stdio.h $ ln -s ~/didattica/corsi/fileln file $ ls -l file lrwxrwxrwx 1 rinaldi rinaldi 37 apr 7 14:50 file -> /home/rinaldi/didattica/corsi/fileln $ rm ~/didattica/corsi/fileln $ ls –l file lrwxrwxrwx 1 rinaldi rinaldi 37 apr 7 14:50 file -> /home/rinaldi/didattica/corsi/fileln $ cat fileln cat: fileln: No such file or directory
10
1.10 File Attributes The time stamp: each file has three dates associated with it: The creation time The last modification time The last access time The owner: every file is owned by one user of the system The group: every file has also a group of users associated with it. The most common group for user files is called users which is usually shared by all the users account on the system The permissions: every file has permissions associated with it which tell who can access to that file, or change it, or in the case of programs, execute it. Each of this permission can be toggled separately for the owner, the group and all the other users.
11
1.11 File Attributes The information of the files can be obtained by means of the command ls –l $ ls -l totale 28 drwxrwxr-x 4 rinaldi rinaldi 4096 mar 27 16:52 Desktop/ drwxrwxr-x 2 rinaldi rinaldi 4096 mar 21 17:35 didattica/ drwxr-xr-x 2 rinaldi rinaldi 4096 mar 14 19:21 Documents/ -rwx------ 1 rinaldi rinaldi 1999 mar 31 13:25 file* -rw-r--r-- 1 rinaldi rinaldi 123 mar 31 12:58 file1 drwxrwxr-x 2 rinaldi rinaldi 4096 mar 21 17:35 ricerca/ drwx------ 2 rinaldi rinaldi 4096 mar 14 18:50 tmp/ In addition to the name of each file, print the file type, permissions, number of hard links, owner name, group name, size in bytes, and timestamp, normally the modification time.
12
1.12 Permissions Everything in UNIX is managed via files, even access to devices (via the device files in '/dev') like printers, modems, sound cards etc. If you do not have the permission on a file which represents a device, you can't use that device. The first concept of permissions is ownership. You either own a file or a directory you have created or that has been handed over to you by using the chown command. If you own a file, you can do whatever you want with it, usually. Often more than one account needs access to a file or device. Changing the ownership of this file every time someone else needs access to it would be very tedious to say the least. This is why ownership is not only provided for single accounts but also for groups. Groups are defined in /etc/group, an entry in this file looks like this: group_name:x:group_ID:group_member
13
1.13 Permissions To see a list of groups your current account is a member of, use the command $ groups So, if you are member of a group and that group has permissions on a file, you can do something with that file, even if you are not its owner. An average UNIX system has some 60.000 files and more. A majority of them has to be accessible in some way by all the users on a system. One way to achieve this could be to create a 'catch-all' group which would unite all the accounts on a system and assign all these files to this group. So, we can divide file permissions into 3 categories: Owner permissions Group permissions Other permissions
14
1.14 Permissions The output of the ls -l command shows the permissions of a file/directory $ ls -l drwxrwxr-x 4 rinaldi rinaldi 4096 mar 27 16:52 Desktop/ drwxr-xr-x 2 rinaldi rinaldi 4096 mar 14 19:21 Documents/ -rwx------ 1 rinaldi rinaldi 1999 mar 31 13:25 file* -rw-r--r-- 1 rinaldi rinaldi 123 mar 31 12:58 file1 drwxrwxr-x 2 rinaldi rinaldi 4096 mar 21 17:35 ricerca/ drwx------ 2 rinaldi rinaldi 4096 mar 14 18:50 tmp/ the flag 'r' is for reading, 'w' for writing, and 'x' is for executing. The first field has three options, d, l or -, where d indicates a directory, l a symbolic link, and - a file. The other nine fields indicate the owner permissions, group permissions and 'all others' permissions. Owner | Group | Others = rw- | r-- | r-- ( file1)
15
1.15 Permissions on directories Permissions on directories are different from permissions on files. Here: drwxrwxr-x 4 rinaldi rinaldi 4096 mar 27 16:52 Desktop/ drwxr-xr-x 2 rinaldi rinaldi 4096 mar 14 19:21 Documents/ drwx------ 2 rinaldi rinaldi 4096 mar 14 18:50 tmp/ r indicates that the contents of the directory can be listed w indicates that the contents of the directory can be changed (copy, move, create new files) x indicates that users can " cd " to that directory, read, write, execute programs and search in the directory.
16
1.16 Changing permission settings The command, chmod lets you change the permission mode settings of a file/directory. You also need to specify 3 digits with the chmod command. These digits dictate what permissions will be applied. The first digit determines the permissions for the owner, the second digit determines the permissions for the group, and the third for others. To change the permissions of the file “ file1 ” type: chmod XYZ file1 where XYZ represents 3 digits e.g. 666 The first digit is the sum of 4 for read permission, 2 for write permission and 1 for execute permissions. user group others chmod 640 file1 rw- r-- --- chmod 754 file1 rwx r-x r-- chmod 664 file1 rw- rw- r--
17
1.17 Changing permission settings chmod a+rw hello.c chmod o-w hello.c chmod og+rx prog* chmod g=rw rep* chmod +w * The option -R changes recursively the permissions of a directory and its contents WhoActionPermission u = user+ = addr = read g = group- = deletew = write o = other= = assignx = execute a = all
18
1.18 Changing Groups If you are member of several groups and you create a file, what is the group id of the file ? Although you may be a member of several groups, only one of them is your effective group at any given time. When a process creates a file, the group id of the file is set to the effective group id. The system administrator chooses which one of your groups is used as your login shell’s effective group id. However, you may create a shell with a different effective group id by using newgrp utility $ date > ~/test1 … creates “test1” from a “rinaldi” group shell $ newgroup informatica $ date > ~/test2 … creates “test2” from a “informatica” group shell ^D $ ls –lg test* -rw-r--r-- 1 rinaldi 30 mar 27 16:52 test1 -rw-r--r-- 1 informatica 30 mar 27 16:52 test1
19
1.19 The Linux Proc File System The proc file system does not store data, rather, it creates a directory for each process. The name of the directory is the PID of the process $ cd /proc ; ls 1/1023/1089/1111/… 1839/ … 2289/ … $ ps PID TTYTIMECMD 1839pst/200.00.00 bash 2289pst/200.00.00 ps A proc directory collects the appropriate information about the process (command line, environ strings, status, …) $ cd 1839 ; ls cmline cwd environ exe fd maps mem mounts stat statm status So, proc directories contain many information about the CPU, disk partitions, devices,... The user programs can obtain these information for learning many information about the behavior of the system in a safe way. pstree: shows the depencies between all the active processes kill: kills a process
20
1.20 Mounting The operating system attaches a physical file system to its virtual file system by means of the command mount. This operation is called mounting and its format is: $ mount –t type device mount-point Examples: $ mount –t ext2 /dev/hda6 / The partition of ext2 is called hda6. ( hd for hard drive, a for the first of these, and 6 for the sixth partition). The documentation of the devices is in /usr/src/linux/Documentation/devices.txt. $ mount –t vfat /dev/hda1 /mnt/windows $ mount –t msdos /dev/fd0 /mnt/floppy $ mount –t iso9660 /dev/hdc /mnt/cdrom The command mount is used by the super-user. The operating system performs mount –a during the boot. This command mounts the file systems listed in /etc/fstab. We can establish the mounted devices by typing in: $ mount We can unmount the file system by using umount umount /mnt/floppy
21
1.21 Compressing Files The compressed file types in Linux are: file.Z -- compressed with the compress : $ compress file1 $ uncompress file1.Z file.z, file.gz -- compressed with the GNU zip program: zip, gzip. $ gzip –-best huge_file $ gunzip huge_file.gz file.bz2 -- compressed with bzip2 $ bzip2 –9 huge_file $ bunzip2 huge_file.bz2 We can view a file in a compressed archive without extracting it, by means of zcat or bzcat $ zcat huge_file.gz $ bzcat huge_file.bz2
22
1.22 Archiving Files We can use tar to store files in an archive, to extract them from an archive, and to do other types of manipulation. The synopsis of tar is: $ tar options tarfilename filelists Some options are -c create an archive -x extract from an archive -t list the contents of an archive -v encourage verbose output -u update only files that are more recent than those archived -f use the “tarfilename” as filename of the archive (the name of “tarfilename” is /dev/rmt0 by default) Example: tar -cvf logfile.tar logs.* tar -tvf logfile.tar tar -xvf logfile.tar tar -cvzf logfile.tar.gz logs.*
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.