Download presentation
Presentation is loading. Please wait.
Published byChristian Oliver Modified over 9 years ago
1
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi
2
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:2 Files A file is a sequence of bytes. It can be created by a text editor (xemacs or pico) a computer program (such as a C program)
3
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:3 Files It may contain a program, data, a document, or other information. Files that contain other files are called directories (sometimes called folders).
4
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:4 Linux Filenames Restrictions May not contain blanks or other reserved characters. Have a maximum length. Are case sensitive. It is best to stick with filenames that contain letters (uppercase or lowercase), numbers, and the underscore ( _ ) for now.
5
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:5 Organization of Files Under Linux, files are organized in a tree-like structure. The top of the tree is represented by the root directory, indicated by “/”, and each of the braches is a directory which can contain sub-directories, or files.
6
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:6 Organization of Files A directory is a special file. Each directory contains a catalogue of names of its files and sub-directories. Two particular entries exist in all directories:. (the directory itself) and.. (the parent directory)
7
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:7 Directories Directories contain files or other directories called subdirectories. They may also be empty. Directories are organized in a hierarchical fashion. They help us to keep our files organized.
8
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:8 Directories (con’t) /afs/umbc.edu/users/j/d/jdoe28 junkrecipes notes piescookies CMSC104 apple peach choc_chip apple peach choc_chip
9
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:9 Subdirectories Are used for organizing your files For example, make a subdirectory for CMSC104 make subdirectories for each projectCMSC104 project1 project2... project8 project1 project2... project8
10
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:10 File Types The file type is used by the system in order to determine the use to which the file will be put. Linux file types directory a catalogue of file names normal files designed to contain data belonging to users.
11
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:11 File Types symbolic link a pointer to another file When a link is the subject of an action, the file pointed to is accessed. special file assigned to a device controller embedded in the kernel.
12
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:12 File Types When a special file is accessed, the physical device associated to it is actually acted upon.
13
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:13 Directories, Files and Inodes In the case of the root directory, that parent is itself. A directory is a file that contains a table listing the files contained within it, giving file names to the inode numbers in the list. The information about all the files and directories is maintained in INODE TABLE
14
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:14 Inodes An Inode (Index Nodes) is an entry in the table containing information about a file (metadata) including file permissions, UID, GID, size, time stamp, pointers to files data blocks on the disk etc. Every directory and file is listed in its parent directory.
15
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:15 UNIX File System
16
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:16 File System Each node is either a file or a directory of files, where the latter can contain other files and directories. You specify a file or directory by its path name, either the full, or absolute, path name or the one relative to a location.
17
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:17 File System The full path name starts with the root, /, and follows the branches of the file system, each separated by /, until you reach the desired file, e.g.: /home/condron/source/xntp
18
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:18 File System A relative path name specifies the path relative to another, usually the current working directory that you are at. Two special directories:. the current directory.. the parent of the current directory
19
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:19 File System So if I'm at /home/frank and wish to specify the path above in a relative fashion I could use: ../condron/source/xntp This indicates that I should first go up one directory level, then come down through the condron directory, followed by the source directory and then to xntp.
20
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:20 Structure of Standard Directories in Unix/Linux / The ancestor of all directories on the system; all other directories are subdirectories of this directory, either directly or through other subdirectories. /boot It is a directory with the operating system kernel, loaded into memory during system startup, static files of the boot loader.
21
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:21 Structure of Standard Directories in Unix/Linux /bin Essential tools and other programs (or binaries). /dev Files representing the system's various hardware devices. For example, you use the file `/dev/cdrom' to access the CD−ROM drive. /etc Miscellaneous system configuration files, startup files, etc.
22
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:22 Structure of Standard Directories in Unix/Linux /home The home directories for all of the system's users. /lib Essential system library files used by tools in `/bin'.
23
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:23 Structure of Standard Directories in Unix/Linux / proc Files that give information about current system processes. /root The superuser's home directory, whose username is root. (In the past, the home directory for the superuser was simply `/'; later, `/root' was adopted for this purpose to reduce clutter in `/'.)
24
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:24 Structure of Standard Directories in Unix/Linux sbin Essential system administrator tools, or system binaries. /tmp Temporary files. /usr Subdirectories with files related to user tools and applications.
25
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:25 Pathnames Pathnames provides a flexible method of identifying files and directories within the file system. A pathname can be thought of as describing a route or “Path” through the file system hierarchy to the file or directory.
26
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:26 Absolute and Relative Pathnames There are two types of pathname: Absolute and relative. Absolute: An absolute pathname describes the path to the file or directory starting from the root (/) directory. /usr /bin /tty
27
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:27 Relative Pathname Relative: A relative pathname describes the path to the file or directory from the current directory. bin/tty The current directory is the reference point if the pathnames does not start with a /
28
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:28 Home directory Every user on the system has a “home directory” It is a user’s start location when the user logs in Becomes the working (current) directory at login time
29
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:29 Home directory Startup and configuration files reside here. Session customization files, such as profile, login, kshrc Application startup files, such as Xdefaults.
30
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:30 Moving in the Directory Tree (dot) is the current directory. .. (dot-dot) is the parent directory. Use the Linux command cd to change directories. Use dot-dot to move up the tree. Use the directory name to move down. Use the complete directory name (path name) to move anywhere.
31
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:31 Wildcard Characters You will find wildcard characters useful when manipulating files (e.g., listing or moving them). The wildcard characters are * and ? ? is used to represent any single character. * is used to represent 0 or more characters.
32
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:32 Directory Commands cd Change directory cd Change to home directory pwd Print working directory
33
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:33 Listing directories ls command is used to list directories, the commonly used options that can be given to the command are : ls[options] [files] Options are: -llong (full) listing -a list all files including hidden dot files. -C/ -xlist in columns sorted down /across
34
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:34 List options -Rrecursive listing of subdirectories -tsort by time rather than name -dlist directory itself, not it’s contents. -sshow size of the files in blocks not in bytes -hshow the size in human readable format (4K, 16M,1G etc). This option should be used in conjunction with the –s option. $ls –al command is used for long listing of directories
35
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:35 Listing It shows the Type of file: - plain file, d directory, / symbolic link Permissions: r read, w write, x execute Link count File ownership: user and group Size in bytes Date and time of last modification Filename
36
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:36 File List Example: $ ls –l - rw-r--r-- 1 einstein metal 19514 may 10 13:45 chap01 -rw-r--r-- 1 einstein metal 4174 may 10 15:01 chap02 -rw-rw-rw- 1 einstein metal 84 feb 12 12:30 dept.lst -rw-r--r-- 3 dennis metal 9156 mar 12 1999 genie.sh drwxr-xr-x 2 einstein metal 64 may 9 10:31 helpdir drwxr-xr-r 2 einstein metal 320 may 9 09:57 progs Permissions Link countUser and group Size in bytes Date and time of last modification File name File Type
37
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:37 Making directory Syntax # mkdir directory name Example # mkdir hello
38
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:38 Removing directory (i) To delete an empty directory Syntax # rmdir directory name Example # rmdir hello
39
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:39 To delete directory recursively (ii) To delete a directory and all of it’s contents recursively, including subdirectories and their contents. Syntax # rm -r directory name Example # rm –r myfile
40
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:40 Copying files or directory (i)Syntax: # cp source file target file Example # cp myfile /home/Simi (ii) To copy directory, subdirectory and files recursively # cp –r chat./rat # cp –r chat./rat
41
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:41 Renaming files or directory Syntax # mv oldfilename/directory newfilename/directory Example # mv ABC xyz
42
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:42 Looking File contents (i) The command that is used to type a file to the screen is cat (for concatenation). It will copy the specified file to the screen. Example: Example: # cat filename
43
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:43 Creating new file (ii) The command used to create a new file with specified filename is Syntax # cat > filename Example: # cat > hello ….. ….. Ctrl+d - to save the file. Example: # cat > hello ….. ….. Ctrl+d - to save the file.
44
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:44 Appending a file To append an already existing file: Syntax: # cat >> filename # cat >> filename Example: # cat >> hello
45
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:45 More and Less commands To show a file one screen full at a time, the more command can be used. Syntax # more # more To interactively scroll through a file, the less command should be used. Syntax # less # less
46
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:46 WC command The wc command counts words, lines, and characters in a file. –w, -l and –c options to restrict the count to the obvious parameters. Syntax wc [-cwl] [file…] wc [-cwl] [file…]
47
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:47 Counting characters in file To count the number of characters in file. Syntax wc –c filename ( for characters) Example wc –c hello
48
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:48 To count number of lines Syntax wc –l filename( for lines) Example wc –l hello wc –l hello
49
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:49 File Linkages Conventional link (hard link) It is possible to associate several names to the same file. Any operation may be carried out by citing arbitrarily any link name. The kernel maintains a count of the links assigned to each file.
50
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:50 File Linkages When a link is created, this number is incremented. When a link is deleted, the number is decremented. When the number becomes zero, the file contents are effectively deleted, and the space on the disk is made free
51
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:51 File Linkages Cons It is impossible to create links to directories. It is impossible to create links between files residing on different file systems
52
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:52 Symbolic link (soft link) Symbolic link (soft link) While conventional links are additional names to a file, symbolic links are pointers to other files. Can point to any sort of file, even non- existent ones. A symbolic link is a special type of file whose contents specify the name of the target file.
53
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:53 Creating Links The ln command creates a link to a file Syntax ln [-snf] file target where [snf] are the options -ssymbolic or soft link -ndon’t overwrite existing filenames -fforce overwrite of existing filename
54
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:54 Symbolic links symbolic link can be created with ln command: $ ln –s /path/to/file1.txt file2.txt $ ls –l
55
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:55 Symbolic links Above command will create a symbolic link to file1.txt, file1.txt is target file name and file2.txt is symbolic filename. Listing of all the link files with inode number is $ls -il
56
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:56 Hard links It must be within a file system, only root can link to directories. Hard links cannot links directories, cannot cross file system boundaries. Hard links always refer to the source, even if moved or removed. Inodes are associated with precisely one directory entry at a time.
57
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:57 Hard links With hard links it is possible to associate multiple directory entries with a single inode. In hard link one file is accessed by many files but inode number is same for all the files accessing the files.
58
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:58 Hard links To create a hard link ln command is used. # ln /root/file1 /root/file2 # ls –l Above commands create a link to file1.
59
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:59 File Attributes Attributes its size in bytes the owner identifier of the file, that is, the user who created the file the group identifier of users who own the file. the number of links. the access permissions. the dates of access and modification.
60
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:60 File Attributes Access permissions the permission to read/write/execute data for the owner, the owning group and the rest of users. For a directory read permission: the contents of a file may be listed
61
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:61 Elements of a Block Group write permission: entries in the directory may be added or deleted execute permission: the directory may be examined. Super block Magic number: for ext2, 0xEF53 Revision Level Block group number Block size Blocks per group
62
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:62 Elements of a Block Group Free blocks Free inodes First inode: the inode number of the first inode in the file system ( the directory entry for the “/” directory)
63
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:63 Elements of a Block Group Descriptors The block number of the block (allocation) bitmap The block number of the inode (allocation) bitmap The block number of the starting block for the inode table
64
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:64 Inode Every file and directory in the file system is described by one and only one inode. The inodes for each block group are kept in the inode table together with an inode (allocation) bitmap. Elements mode: permissions owner information
65
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:65 Inode The user and group identifiers size timestamps The time that the inode was created Datablocks Pointers to the blocks that contains the data The first 12 are direct pointers to data blocks The last three entries are for indirect blocks.
66
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:66 Thank You Thank You
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.