0% found this document useful (0 votes)
31 views

More File Attributes

The document discusses various file attributes stored in the inode of each file in Unix/Linux file systems. It describes that the inode contains metadata about the file like its type, permissions, owner, size, timestamps and disk block pointers, but not the filename or contents. It also explains hard links and soft links, how file permissions are set using umask, and commands like touch, tee and find to modify timestamps, duplicate output to files, and search for files respectively.

Uploaded by

Pranav Paste
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

More File Attributes

The document discusses various file attributes stored in the inode of each file in Unix/Linux file systems. It describes that the inode contains metadata about the file like its type, permissions, owner, size, timestamps and disk block pointers, but not the filename or contents. It also explains hard links and soft links, how file permissions are set using umask, and commands like touch, tee and find to modify timestamps, duplicate output to files, and search for files respectively.

Uploaded by

Pranav Paste
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

More File Attributes

File System And Inodes


• Every file is associated with a table that
contains all the attributes except its filename
and its contents
• This table is called the inode(shortened from
index node) and is accessed by the inode
number
• The inode contains the following attributes of
file
File System And Inodes
• File type(regular,directory,device,etc)
• File permissions(the nine permissions)
• Number of links(the number of aliases the file
has)
• The UID of the owner
• The GID of group owner
• File size in bytes
• Date and time of last modification
• Date and time of last access
• Date and time of last change of inode
• An array of pointers that keep track of all disk
blocks used by the file

• Observe that niether the name of the file nor


the inode number is stored in the inode
Hardlinks
• We can access a particular file by any of its links
• All names provided to a single file have one thing in
common; they all have same inode number
• $ ls

-rwxr-xr--2 kumar metal 163 jul 13 21:36 backup.sh


-rwxr-xr--2 kumar metal 163 jul 13 21:36restore.sh
• $ls –li backup.sh restore.sh

47824 -rwxr-xr-- 2 kumar metal 163 jul 13 21:36


backup.sh
47824 -rwxr-xr-- 2 kumar metal 163 jul 13 21:36
restore.sh
• Both files indeed have the same inode number
so there is actually one file with single copy on
disk

• We cant refer them as two “files” but only as


two “filenames”
ln:Creating Hard links
• A file is linked with the ln(link) command which
takes two filenames as arguments
Creating hard links

$ln emp.lst employee (employee must not exist)


$ls –li emp.lst employee
29518 –rwxr-xr-x 2 kumar metal 915 may 4 09:58
emp.lst
29518 –rwxr-xr-x 2 kumar metal 915 may 4 09:58
employee
$ln employee emp.dat;ls –l emp*

29518 –rwxr-xr-x 3 kumar metal 915 may 4


09:58 emp.dat

29518 –rwxr-xr-x 3 kumar metal 915 may 4


09:58 emp.lst

29518 –rwxr-xr-x 3 kumar metal 915 may 4


09:58 employee
$ rm emp.dat; ls –l emp.lst employee

• –rwxr-xr-x 2 kumar metal 915 may 4 09:58


emp.lst
• –rwxr-xr-x 2 kumar metal 915 may 4 09:58
employee
Symbolic links and ln
• Symbolic link is the fourth file type which is
considered
• Unlike hard link a symbolic link does not have
the file contents but simply provides the
pathname of the file that actually has the
contents .
• You can create symbolic link(softlink) with the
help of –s option
• $ ln –s note note.sym

• $ls –li note note.sym

9948 -rw-r-r-- 1 kumar group 80 feb 16 14:52


note
9952 lrwxrwxrwx 1 kumar group 4 feb 16 15:07
note.sym->note
HardLink SoftLink
Created using ln command Created using ln with s
ln option ln -s
Used to link to a file in theUsed to link to a file(s) in a
same filesystem different filesystem
No of links to the file Since the linked file(s)
increase,inode number resides in a different
remains same filesystem inode numbers
differ
Deleting a link just reduces Deleting the original file
the link count by one but removes the file the soft
file remains intact links(names) then links to
an empty hole
umask:Default file and directory
permissions
• The unix system has the following default
permissions for all files and directories
rw-rw-rw-(octal 666) for regular files
rwxrwxrwx(octal 777) for directories
• This default is transformed by subtracting the
user mask from it to remove one or more
permissions
$umask
022(current value of usermask)
• This is an octal number which has to be
subtracted from the system default to obtain
the actual default

• This becomes 644(666-022) for ordinary files


and 755(777-022) for directories
Modification and Access Times
A unix file has three timestamps associated
with it
• Time of last file modification ls –l
• Time of last access ls –lu
• Time of last inode modification ls –lc
• When you add the –t option to –l or –lu the
files are actually displayed in order of
respective timestamps
• ls –lt displays listing in order of their
modification time
• Ls -lut displays listing in order of their
access time
touch:Changing the timestamps
• You may sometimes need to set the
modification and access times to predefined
values
• The touch command changes these times and
is used in following manner
• touch options expression filenames(s)
• When touch is used without options or
expressions,both time are set to current time
• $ touch emp.lst
(both times are set to current time)
When touch is used with expression
It changes both times
$ touch 03161430 emp.lst;ls –l emp.lst
-rw-r--r-- 1 kumar metal 870 mar 16 14:30
emp.lst
• $ ls –lu emp.lst
• -rw-r--r-- 1 kumar metal 870 mar 16 14:30
emp.lst
• It is also possible to change the two times
individually
• The –m and –a option change the
modification and access times,respectively
• $ touch –m 02281030 emp.lst;ls –l emp.lst
• -rw-r--r-- 1 kumar metal 870 feb 28 10:30
emp.lst

• $ touch –a 01261650 emp.lst;ls –lu emp.lst


• -rw-r--r-- 1 kumar metal 870 jan 26 16:50
emp.lst
Tee:Creating a tee
• It handles a character stream by duplicating its
input
• It saves one copy in a file and writes the other
to standard output
• Being a filter tee can be placed anywhere in
the pipeline
• Tee doesn’t perform any filtering action on its
input;it gives out exactly what it takes
Tee:Creating a tee
• The foll command sequence uses tee to display the
output of who and saves this output in file as well

• $who | tee user.txt


Sumit pts/5 sep 7 08:41 (pc122.heavens.com)

$who | tee user.txt | wc –l


Sumit pts/5 sep 7 08:41 (pc122.heavens.com)
1
Find:Locating files
• It recursively examines a directory tree to
look for files matching some criteria, and then
take some action on selected files
• Syntax
find path_list selection_criteria action
This is how find operates:
• First it recursively examines all files in the
directories specified in the path_list
Find:Locating files
• It then matches each file for one or more
selection_criteria
• Finally it takes some action on those selected
files
Example:
lets use find to locate all files named a.out
$ find /-name a.out –print
/home /kumar/scripts/a.out
/home /sharma/a.out
Find:Locating files
Other examples
• find . –name “*.c” –print
all the files beginning with extension.c

• find .-name ‘[A-Z]*’ –print


Searches for all those files whose
names begin with an uppercase letter
Find operators(!,-o and –a)
• The ! Operator is used before an option to negate its
meaning.

find .! –name “*.c” –print

• To look for both shell and perl scripts use the –o


operator which represents the OR condition

• We need to use an escaped pair of parentheses here:


Find operators(!,-o and –a)
• find /home \(-name “*.sh” –o –name “*.pl” \) –
print

• The ( and ) are special characters that are


interpreted by the shell to group commands

• The –a operator represents the AND condition


and is implied by default whenever the two
selection criteria are placed together

You might also like