Unit - II: The File System
Unit - II: The File System
• 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.
• 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 $