0% found this document useful (0 votes)
46 views24 pages

Unit - II: The File System

This document provides an overview of files and file systems in Unix/Linux. It discusses the basics of files including what they contain and how programs access them. It also describes directories and filenames, file permissions, inodes, the directory hierarchy, and commands to view and modify files like file, chmod, chown, and chgrp. The file system organizes files and provides metadata to define access permissions and ownership.

Uploaded by

Siva Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views24 pages

Unit - II: The File System

This document provides an overview of files and file systems in Unix/Linux. It discusses the basics of files including what they contain and how programs access them. It also describes directories and filenames, file permissions, inodes, the directory hierarchy, and commands to view and modify files like file, chmod, chown, and chgrp. The file system organizes files and provides metadata to define access permissions and ownership.

Uploaded by

Siva Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Unit -II

The File System


Contents
 The Basics of Files
 What’s in a File?
 Directories and Filenames
 Permissions
 Inodes
 The Directory Hierarchy
 The File Command-Knowing the File type
Contents contd...
 The chmod command-Changing File
Permissions.
 The chown command-Changing the Owner of
the File
 The chgrp command-Changing the Group of a
file
The Basics of Files
• A file is a sequence of bytes

• Create a file using ‘ed’


$ed
a
now is the time
For all good people
.
w junk
36
q
$
• ‘cat’ shows what the file looks like
$cat
now is the time
for all good people
$
• ‘od’ prints a visible representation of all the bytes of a file
$od –c junk
0000000 n o w i s t h e t i m e \n
0000020 f o r a l l g o o d p e o
0000040 p l e \n
0000044
$
• Programs retrieve the data in a file by ‘read’ system call
• When a program reads from the terminal, each input line is given to the program by
the kernel only when you type its new line

• Buffered output from cat


$ cat
123
456
789
Ctrl+d
123
456
789

• Un Buffered Output from cat


$cat
123
123
456
456
789
789
Ctrl+d
What’s in a file
• The ‘file’ command makes an educated guess

$file /bin /bin/ed /usr/src/cmd/ed.c /usr/man/man1/ed1.1


/bin: directory
/bin/ed: pure executable
/usr/src/cmd/ed.c: c program text
/usr/man/,man1/ed1.1: roff,nroff, or eqn input text

• A runnable program is marked by a binary “magic number” at its beginning


$od /bin/ed
0000000 000410 025000 000462 011444 0000000 000000 000000 000001
0000020 170011 016600 000002 005060 177776 010600 162706 000004
000040 016616 000004 005720 010066 000002 005720 001376 020076
.........
Directories and Filenames
• The command pwd identifies the current directory
$pwd
/usr/you
• The real purpose of current directory is organizational
$pwd
/usr/you
$mkdir recipes
$cd recipes
$pwd
/usr/you/recipes
$mkdir pie cookie
$ed pie/apple
...
$ed cookie/choc.chip
....
$
• The piece of file system can be shown pictorially as

• The du (disc usage) command was written to tell


how much space is consumed by the files in a
directory
• The du has an option –a , for all, that causes it to
print out all the files in a directory
• The output of du –a can be piped through
grep to look for specific files

• Every directory begins with two entries,’ .’ and


‘..’.The directory ‘/’ is called the root of the file
system
Permissions
• Every file has a set of permissions associated
with it, which determine who can do what
with that file
• The file /etc/passwd is the password file.it
contains all the login information about the
user.
• There are three kinds of permissions for each file:read(i.e. examine its
contents),write(i.e. change it contents), and execute (i.e run it as a
program).
• The –l option of ls prints the permissions information, among other
things.
• /etc/password is owned by login-id root, group adm, is 5115 bytes long,
was last modified on Aug 30 at 10:40 am and has one link. The string –rw-
r—r– is the permissions of the file. The first – indicates that it is a ordinary
file. The next three(rw-) encode owner’s permissions, the next three(r--)
encode group’s (adm’s)permission and next(r--) for everyone else.
• Directory permissions operates a little differently, but tbe basic idea is same.

• The –d option of ls tells about that ‘.’ is the directory. An r field means that
we can find out what files are in it with ls. A w means that you can create
and delete files in the directory and the x field means search.

• The chmod command changes permissions on files

• Allowa everyone to execute the command

• Turns off write permission for every user including owner


Inodes
• A file has several components :a name, contents
and administrative information such as
permissions and modification times.The
administrative information is stored in inode.
• There are three times in the inode
– The time that contents of the file were last
modified(written)
– The time that the file was last used(read or executed)
– The time that the inode itself was last changed (for
example to set the permissions)
• Changing the contents of the file doesnot
affect its usage time as reported by ls-
lu,changing the permissions effects only the
inode change time as reported by ls –lc.
• The –t option combined with –c and –u to
report the order in which the inodes were
changed or files are read.

• ls –i reports the i-number in decimal


• Two links to a file point to the same inode, and hence have the same i-number

• Cp makes copies of files. The i-numbers of junk and copyofjunk are different
beacuse they are different files eventhough same contents
• Sameoldjunk has same inode number as
junk,only its name – the directory entry
associated with the inode 15768 has been
changed
The directory hierarchy
The File Command
• Sometimes, apart from classifying Unix files as regular files, directories,
device files and other files they are also classified as text files, executable
files, and directories. This classification is based on the contents of the file
• The file command is used to identify the type of the files on the basis of
their contents..
• But Unix has nothing to do with extension names. This is because Unix
puts no restriction on extensions in filenames. Certain category of files
such as executables are recognized by the information stored on their
headers—the information stored in the first-byte. This first byte
information is known as the magic number. This magic number is
consistent for ..../etc/magic. For example the octal 410 is the magic
number of executable files. These magic numbers can be verified by
taking the octal dump of the relevant file.
The chmod command
• The chmod command is used to change the permissions of a file after its creation. Only
the owner or the super user can change file permissions. The general syntax of this
command is
$chmod assigenment_expression filename
The assignment expression holds the following information.
– The information about the category of users {user –u, group –g, others –o, all –a}.
– The information about granting or denial of the permission {the operators +, – and =}.
– The information about the type of permission {read –r, write –w, execute –x}.
• Although we generally consider only three types of users such as the owner,
the group and others, a fourth category called all {a} that refers to all the three
conventional categories is also considered.
• Further the + (plus) operator is used for granting the permission, the – (minus) operator
is used for removing the permission and the = (equal to) operator is used for assigning
absolute permission. Obviously the different permissions that are either granted or
denied are the read permission (r), the write permission (w) and the execute permission
(x).
The chown command
• every file has a owner. When a file is created, the creator becomes
the owner of the file. Only the owner can change the major attributes
of a file (of course, the system administrator also can do it).
• Sometimes it is necessary to change the ownership of a file. There
are two ways in which the ownership can be changed—by copying
the file in to the target user’s directory, and by using
the chown command.
• For example, the file sample from the directory of hmk is copied to
the home directory of someone else, say mgv. Then mgv becomes the
new owner of the file sample. If, now, the oldfile and newfile are
listed using the ls –l command, one sees that every detail will be
same except the owner.
The chgrp command
• In Unix, all files not only belong to an owner but also to
a group. One may need to change the group of a file
under certain circumstances such as when new groups
are set up on a system or when files are copied to a new
system. This is done by using the chgrp command. Only
the owner of a file can change the group (of course, the
system administrator also can do the same).
• This command also takes two arguments; the name of
the new group and the name of the file. For example,
$chgrp planning sample $

You might also like