66
Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Embed Size (px)

Citation preview

Page 1: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:1

Lesson 2: The File System

By Simi

Page 2: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:2

Files

A file is a sequence of bytes.A file is a sequence of bytes.

It can be created byIt can be created by a text editor (xemacs or pico) a computer program (such as a C

program)

Page 3: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:3

Files

It may contain a program, data, a It may contain a program, data, a document, or other information.document, or other information.

Files that contain other files are called Files that contain other files are called directories (sometimes called folders).directories (sometimes called folders).

Page 4: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:4

Linux Filenames

RestrictionsRestrictions May not contain blanks or other

reserved characters. Have a maximum length. Are case sensitive.

It is best to stick with filenames that It is best to stick with filenames that contain letters (uppercase or lowercase), contain letters (uppercase or lowercase), numbers, and the underscore ( _ ) for numbers, and the underscore ( _ ) for now.now.

Page 5: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:5

Organization of Files

Under Linux, files are organized in a Under Linux, files are organized in a tree-like structure.tree-like structure.

The top of the tree is represented by the The top of the tree is represented by the root directory, indicated by “/”, and each root directory, indicated by “/”, and each of the braches is a directory which can of the braches is a directory which can contain sub-directories, or files.contain sub-directories, or files.

Page 6: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:6

Organization of Files

A directory is a special file.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)

Page 7: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:7

Directories

Directories contain files or other Directories contain files or other directories called subdirectories. They directories called subdirectories. They may also be empty.may also be empty.

Directories are organized in a Directories are organized in a hierarchical fashion.hierarchical fashion.

They help us to keep our files organized.They help us to keep our files organized.

Page 8: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:8

Directories (con’t)

/afs/umbc.edu/users/j/d/jdoe28/afs/umbc.edu/users/j/d/jdoe28

junkjunk recipes notesrecipes notes

piespies cookies CMSC104cookies CMSC104

apple peach apple peach choc_chipchoc_chip

Page 9: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:9

Subdirectories

Are used for organizing your filesAre used for organizing your files For example,For example,

make a subdirectory for CMSC104 make subdirectories for each project

CMSC104CMSC104

project1 project2 . . . project8project1 project2 . . . project8

Page 10: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:10

File Types

The file type is used by the system in The file type is used by the system in order to determine the use to which the order to determine the use to which the file will be put.file will be put.

Linux file typesLinux file types directory

a catalogue of file names normal files

designed to contain data belonging to users.

Page 11: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA 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.

Page 12: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:12

File Types

When a special file is accessed, the physical device associated to it is actually acted upon.

Page 13: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA 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 thefiles contained within it, giving file names to theinode numbers in the list.

The information about all the files and directories ismaintained in INODE TABLE

Page 14: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:14

Inodes

An Inode (Index Nodes) is an entry in the tablecontaining information about a file (metadata)including file permissions, UID, GID, size, timestamp, pointers to files data blocks on the disk etc.

Every directory and file is listed in its parent directory.

Page 15: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:15

UNIX File System

Page 16: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:16

File System

Each node is either a file or a Each node is either a file or a directory of files, where the latter directory of files, where the latter can contain other files and can contain other files and directories. directories.

You specify a file or directory by its You specify a file or directory by its path name, either the full, or path name, either the full, or absolute, path name or the one absolute, path name or the one relative to a location. relative to a location.

Page 17: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:17

File System

The full path name starts with the The full path name starts with the root, /, and follows the branches of root, /, and follows the branches of the file system, each separated the file system, each separated by /, until you reach the desired by /, until you reach the desired file, e.g.: file, e.g.:

/home/condron/source/xntp/home/condron/source/xntp

Page 18: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:18

File System

A relative path name specifies the path A relative path name specifies the path relative to another, usually the current relative to another, usually the current working directory that you are at. Two working directory that you are at. Two special directories:special directories:

. the current directory

.. the parent of the current directory

Page 19: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:19

File System

So if I'm at /home/frank and wish to So if I'm at /home/frank and wish to specify the path above in a relative specify the path above in a relative fashion I could use: fashion I could use:

../condron/source/xntp

This indicates that I should first go up This indicates that I should first go up one directory level, then come down one directory level, then come down through the condron directory, followed through the condron directory, followed by the source directory and then to xntp. by the source directory and then to xntp.

Page 20: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:20

Structure of Standard Directories in Unix/Linux

/ / The ancestor of all directories on the The ancestor of all directories on the system; all other directories are system; all other directories are subdirectories of this directory, either subdirectories of this directory, either directly or through other subdirectories.directly or through other subdirectories.

/boot It is a directory with the /boot It is a directory with the operating system kernel, loaded into operating system kernel, loaded into memory during system startup, static memory during system startup, static files of the boot loader.files of the boot loader.

Page 21: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:21

Structure of Standard Directories in Unix/Linux

/bin Essential tools and other programs /bin Essential tools and other programs (or binaries).(or binaries).

/dev Files representing the system's /dev Files representing the system's various hardware devices. For example, various hardware devices. For example, you use the file `/dev/cdrom' to access you use the file `/dev/cdrom' to access the CD−ROM drive.the CD−ROM drive.

/etc Miscellaneous system configuration /etc Miscellaneous system configuration files, startup files, etc.files, startup files, etc.

Page 22: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:22

Structure of Standard Directories in Unix/Linux

/home The home directories for all of the /home The home directories for all of the system's users.system's users.

/lib Essential system library files used by /lib Essential system library files used by tools in `/bin'.tools in `/bin'.

Page 23: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:23

Structure of Standard Directories in Unix/Linux

//proc Files that give information about proc Files that give information about current system processes.current system processes.

/root The superuser's home directory, /root The superuser's home directory, whose username is root. (In the past, the whose username is root. (In the past, the home directory for the superuser was home directory for the superuser was simply `/'; later, `/root' was adopted for simply `/'; later, `/root' was adopted for this purpose to reduce clutter in `/'.)this purpose to reduce clutter in `/'.)

Page 24: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:24

Structure of Standard Directories in Unix/Linux

sbin Essential system administrator sbin Essential system administrator tools, or system binaries.tools, or system binaries.

/tmp Temporary files./tmp Temporary files.

/usr Subdirectories with files related to /usr Subdirectories with files related to user tools and applications.user tools and applications.

Page 25: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:25

Pathnames

Pathnames provides a flexible method of Pathnames provides a flexible method of identifying files and directories within identifying files and directories within the file system.the file system.

A pathname can be thought of as A pathname can be thought of as describing a route or “Path” through the describing a route or “Path” through the file system hierarchy to the file or file system hierarchy to the file or directory.directory.

Page 26: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:26

Absolute and Relative Pathnames

There are two types of pathname: There are two types of pathname: Absolute and relative.Absolute and relative.

• Absolute: An absolute pathname describes the path to the file or directory starting from the root (/) directory./usr /bin /tty

Page 27: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA 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 /

Page 28: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:28

Home directory

Every user on the system has a “home Every user on the system has a “home directory”directory”

It is a user’s start location when the user logs in

Becomes the working (current) directory at login time

Page 29: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA 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.

Page 30: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:30

Moving in the Directory Tree

(dot) is the current directory.(dot) is the current directory. . . (dot-dot) is the parent directory. . (dot-dot) is the parent directory.. Use the Linux command cd to change Use the Linux command cd to change

directories.directories. Use dot-dot to move up the tree.Use dot-dot to move up the tree. Use the directory name to move down.Use the directory name to move down. Use the complete directory name (path Use the complete directory name (path

name) to move anywhere.name) to move anywhere.

Page 31: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:31

Wildcard Characters

You will find wildcard characters useful You will find wildcard characters useful when manipulating files (e.g., listing or when manipulating files (e.g., listing or moving them).moving them).

The wildcard characters are * and ?The wildcard characters are * and ? ? is used to represent any single ? is used to represent any single

character.character. * is used to represent 0 or more * is used to represent 0 or more

characters.characters.

Page 32: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:32

Directory Commands

cd <directory_name>cd <directory_name> Change Change directorydirectory

cdcd Change to home Change to home directorydirectory

pwdpwd Print working directoryPrint working directory

Page 33: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:33

Listing directories

ls command is usedls command is used to list directories, the to list directories, the commonly used options that can be given to commonly used options that can be given to the command are :the command are :

lsls [options] [files][options] [files] Options are:Options are: -l-l long (full) listinglong (full) listing -a-a list all files including hidden dot list all files including hidden dot

files.files. -C/ -x-C/ -x list in columns sorted down /acrosslist in columns sorted down /across

Page 34: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:34

List options

-R-R recursive listing of subdirectoriesrecursive listing of subdirectories -t-t sort by time rather than namesort by time rather than name -d-d list directory itself, not it’s contents.list directory itself, not it’s contents. -s-s show size of the files in blocks not in show size of the files in blocks not in

bytesbytes -h-h show the size in human readable show the size in human readable

format (4K, 16M,1G etc). This option should be format (4K, 16M,1G etc). This option should be used in conjunction with the –s option.used in conjunction with the –s option.

$ls –al $ls –al command is used for long listing of command is used for long listing of directories directories

Page 35: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:35

Listing

It shows the Type of file: - plain file, d It shows the Type of file: - plain file, d directory, / symbolic linkdirectory, / symbolic link

Permissions: Permissions: r read , w write , x r read , w write , x executeexecute

Link countLink count File ownership: File ownership: user and groupuser and group Size in bytesSize in bytes Date and time of last modificationDate and time of last modification FilenameFilename

Page 36: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:36

File List Example: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 count User and group

Size in bytes

Date and time of last modification

File name

File Type

Page 37: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:37

Making directory

SyntaxSyntax# mkdir # mkdir directory namedirectory name

ExampleExample# mkdir # mkdir hellohello

Page 38: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:38

Removing directory

(i) To delete an empty directory(i) To delete an empty directorySyntaxSyntax# rmdir directory name # rmdir directory name

ExampleExample# rmdir hello# rmdir hello

Page 39: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:39

To delete directory recursively

(ii) To delete a directory and all of it’s (ii) To delete a directory and all of it’s contents recursively, including contents recursively, including subdirectories and their contents.subdirectories and their contents.

SyntaxSyntax# rm -r directory name# rm -r directory name

ExampleExample# rm –r myfile# rm –r myfile

Page 40: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:40

Copying files or directory

(i)(i) Syntax:Syntax:

# cp source file target file# cp source file target file ExampleExample

# cp myfile /home/Simi# cp myfile /home/Simi (ii) To copy directory, subdirectory (ii) To copy directory, subdirectory

and files recursivelyand files recursively

# cp –r chat ./rat# cp –r chat ./rat

Page 41: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:41

Renaming files or directory

SyntaxSyntax# mv oldfilename/directory # mv oldfilename/directory newfilename/directorynewfilename/directory

ExampleExample# mv ABC xyz# mv ABC xyz

Page 42: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:42

Looking File contents

(i) The command that is used to type a (i) The command that is used to type a file to the screen is cat (for file to the screen is cat (for concatenation). It will copy the specified concatenation). It will copy the specified file to the screen.file to the screen.

Example:Example: # cat filename# cat filename

Page 43: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:43

Creating new file

(ii) The command used to create a new (ii) The command used to create a new file with specified filename isfile with specified filename isSyntaxSyntax# cat > filename# cat > filename

Example:Example:# cat > hello# cat > hello…..…..…..…..Ctrl+d - to save the file.Ctrl+d - to save the file.

Page 44: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:44

Appending a file

To append an already existing file: To append an already existing file: Syntax:Syntax:

# cat >> filename# cat >> filename

Example:Example:

# cat >> hello# cat >> hello

Page 45: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:45

More and Less commands

To show a file one screen full at a time, To show a file one screen full at a time, the more command can be used. the more command can be used.

SyntaxSyntax # more <filename># more <filename>

To interactively scroll through a file, the To interactively scroll through a file, the lessless command should be used. command should be used.

SyntaxSyntax # less <filename># less <filename>

Page 46: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:46

WC command

The wc command counts words, lines, The wc command counts words, lines, and characters in a file. –w, -l and –c and characters in a file. –w, -l and –c options to restrict the count to the options to restrict the count to the obvious parameters. obvious parameters.

SyntaxSyntax

wc [-cwl] [file…]wc [-cwl] [file…]

Page 47: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:47

Counting characters in file

To count the number of characters in To count the number of characters in file.file.

SyntaxSyntaxwc –c filename ( for characters)Example wc –c hello

Page 48: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:48

To count number of lines

SyntaxSyntax

wc –l filename( for lines)wc –l filename( for lines)

ExampleExample

wc –l hellowc –l hello

Page 49: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:49

File Linkages

Conventional link (hard link)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.

Page 50: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA 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

Page 51: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA 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

Page 52: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:52

Symbolic link (soft link)

Symbolic link (soft link)Symbolic link (soft link)While conventional links are additional While conventional links are additional names to a file, symbolic links are names to a file, symbolic links are pointers to other files.pointers to other files.

Can point to any sort of file, even non-Can point to any sort of file, even non-existent ones.existent ones.

A symbolic link is a special type of file A symbolic link is a special type of file whose contents specify the name of the whose contents specify the name of the target file.target file.

Page 53: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:53

Creating Links

The The lnln command creates a link to a file command creates a link to a file SyntaxSyntax ln [-snf] ln [-snf] filefile target target

where [snf] are the optionswhere [snf] are the options

-s-s symbolic or soft linksymbolic or soft link

-n-n don’t overwrite existing filenamesdon’t overwrite existing filenames

-f-f force overwrite of existing filenameforce overwrite of existing filename

Page 54: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:54

Symbolic links

symbolic linksymbolic link can be created with ln can be created with ln command:command:

$ ln –s /path/to/file1.txt file2.txt$ ln –s /path/to/file1.txt file2.txt

$ ls –l$ ls –l

Page 55: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:55

Symbolic links

Above command will create a symbolic Above command will create a symbolic link to file1.txt, file1.txt is target file link to file1.txt, file1.txt is target file name and file2.txt is symbolic filename.name and file2.txt is symbolic filename.

Listing of all the link files with inode Listing of all the link files with inode number isnumber is

$ls -il$ls -il

Page 56: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:56

Hard links

It must be within a file system, only root It must be within a file system, only root can link to directories.can link to directories.

Hard links cannot links directories, Hard links cannot links directories, cannot cross file system boundaries. cannot cross file system boundaries.

Hard links always refer to the source, Hard links always refer to the source, even if moved or removed.even if moved or removed.

Inodes are associated with precisely one Inodes are associated with precisely one directory entry at a time. directory entry at a time.

Page 57: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:57

Hard links

With hard links it is possible to associate With hard links it is possible to associate multiple directory entries with a single multiple directory entries with a single inode.inode.

In hard link one file is accessed by many In hard link one file is accessed by many files but inode number is same for all the files but inode number is same for all the files accessing the files.files accessing the files.

Page 58: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:58

Hard links

To create a hard link To create a hard link lnln command is command is used.used.

# ln /root/file1 /root/file2# ln /root/file1 /root/file2# ls –l# ls –l

Above commands create a link to file1. Above commands create a link to file1.

Page 59: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:59

File Attributes

AttributesAttributes 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.

Page 60: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:60

File Attributes

Access permissionsAccess 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

Page 61: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA 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 blockSuper block Magic number: for ext2, 0xEF53 Revision Level Block group number Block size Blocks per group

Page 62: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA 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)

Page 63: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:63

Elements of a Block Group

DescriptorsDescriptors 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

Page 64: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:64

Inode

Every file and directory in the file Every file and directory in the file system is described by one and only system is described by one and only one inode.one inode.

The inodes for each block group are The inodes for each block group are kept in the inode table together with kept in the inode table together with an inode (allocation) bitmap.an inode (allocation) bitmap.

ElementsElements mode: permissions owner information

Page 65: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA 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.

Page 66: Copyrights© 2008 BVU Amplify DITM DATA BASE MANAGEMENT system Page:1 Lesson 2: The File System By Simi

Copyrights© 2008 BVU Amplify DITM

DATA BASE MANAGEMENT systemDATA BASE MANAGEMENT system

Page:66

Thank YouThank You