The File system in UNIX and Linux

 

As you know very well that a file is a collection of related information. Similarly a UNIX file is a storehouse of information; for the most part it is simply a sequence of characters. UNIX places no restriction on the structure of file. A file contains exactly those bytes that you put in to it – be it a source program, executable code or anything else. It neither contain its own size nor its attributes, including the end of file marks. It does not contain its own name. In UNIX and LINUX, the hard disk, printers, tape drive, CD – ROM drive or terminals even shell is also treated as a file.

There are three types of files exists in UNIX and Linux. These are given below:

(1) Ordinary file: Also known as regular file. It contains only data as a stream of characters.

(2) Directory file: A folder containing the names of other files and subdirectories.

(3) Device files: It represents all hardware devices.

Moreover, you can not directly put something into a directory file, and a device file it is because it is not  really a stream of characters.

 

Ordinary file

 

The traditional file is of the ordinary or regular type. It consist of a stream of data resident on some permanent magnetic media. This includes all data, source programs, object and executable code, all UNIX commands, as well as  any files created by the user. The most common type of ordinary file is the text file. This is just a regular file containing printable characters.

 

Directory files

 

A directory file contains no external data but maintains some details of the files and subdirectories that it contains. The UNIX file system is organized with a number of such directories and subdirectories, and you can also create them as and when you need.

A directory file contains two fields for each file - its name and identification number ( every file has a number called the inode number). If a directory houses, say, 10 files, there will be 10 such entries in the directory files . You can’t write directly into a directory file; such power is given only to the kernels. When an ordinary file is created or removed, its corresponding directory  file is automatically  updated by the kernel with the relevant information about the file.

 

Device files

 

UNIX and Linux are such kind of operating system that treat the physical devices as a files. This definition include printers, tapes, floppy drives, CD – ROMs, hard disks and terminals. The files which control these devices are called devices files. The device file is special; it does not contain any data whatsoever. Any output directed to it will be reflected onto the respective physical device associated with the filename. They perform the activity like printing files, installing software and many more.

 

The File Name

 

On most UNIX systems today, a filename can consist of up to 255 characters i.e a file name in unix can contain only up to 255 characters. If you enter more than 255 characters when specifying a filename, only the first 255 characters are effectively interpreted by the system as a file name. Some system, however, report an error message.

Files may or may not have extensions. Just as you can have a filename beginning with a “dot” , you can have one which ends with a “dot” too. All these are valid file names:

Infect you should use only the following character when framing filenames:

1. Alphabets and numerals (a to z or 0 to 9)

2. The periods ( . )

3. The hyphens  ( - )

4. The underscore ( _ )

A file can have many dots embedded in its name for example “a.b.b.b.b” is a perfectly valid filename. A filename can also begin with  a dot or end with one.

Unix is sensitive to case; chap1, Chap1 and CHAP1 are three different file names, and its possible for them to coexist in the same directory.

 

 

The Parent Child Relationship

 

All files in UNIX are related to one another. The file system in UNIX is a collection of all these related files (ordinary, directory and device files) organized in a hierarchical structure. This system has also been adopted by Windows and DOS.

The top is called ROOT, and is represented by a / (frontslash). root is actually a directory file, and it has all the subdirectories of the system under it. These subdirectories, in turn, have more subdirectories and other files under them. The block diagram of Parent child relationship is given below

tt

The Unix File system

Lets see what directory store what kind of data:

1.   /bin and /usr/bin  :  These are the directories where all the commonly used UNIX commands are found.

2.   /sbin and /usr/sbin : It there’s a command that you can’t execute but the system administrator can, then it would probably be in one of these directory.

3.   /etc : This directory contains the configuration files of the system.

4.    /dev : This directory contains all device files.

5.    /home: All users are housed here , romeo. Would have his home directory in /home/romeo.

6.    /tmp : The directories where users are allowed to create temporary files. These files are wiped

away regularly by the system.

7.    /var : The variable part of the file system. Contains all your print jobs, mail queues and incoming  mail.

8.    /lib: Contains all library files.

 

File Access Permissions

 

There are types of files in UNIX. They are directory files, ordinary files and special files(device files). We will be dealing with directory and ordinary files only. Whan a user wants to access the permission to access any file, he/she must take permission to the owner of that fike. The output of the 1s -1 command shows the details clearly. Ordinary files start  with “-” and the directory files start with “d”. Hence in the following example girl and air.c are ordinary files while ashadir is a directory file.

EXAMPLE

 

 

$  1S  -1

Total     3

-rw-r—r--        1     anu      student    10    Jan         1      10:39       girl

drwxrwxr--       2     anu      student    80    Jan         10     15:30       ashadir

-rwxrwxrwx       1     anu      student    40    Jan         13     20:40       air.c

$ _

 

 

When any user creates a file, the creator is said to be the owner of that file. We can perform any operation like delete, edit or copy on that file. If a user wants other people to access his/her files, then permission has to be granted by the owner of the file. This way LINUX helps in the security of files.

There are various types of permissions available. They are read (r), write(w) and execute (x).

Read permission is used to display, copy or to compile a file. Write permission is used to write, edit or to delete a file. Execute  permissions are used to execute a file.

The 1s -1 option gives the list of permissions granted to each file . The first column of the 1s -1 command gives a list of permissions granted to all those associated with any LINUX/UNIX file.

The first three characters indicate the permission of the owner of the file. The next three position indicate the permissions of the group and the last three the permissions for others

 

As you see in the given example there are lots of coloum. Each coloum specify some special meaning.

Here :

I :   File type and permission

II:   Links (1 for File and 2 for Directory)

III:   Ownership

IV:   Group ownership

V:     File size in Bytes

VI:    Last modification and access time

VII:   File name

In the given exaple the file girl (ordinary file) can be read and write by the owner but not execute by him, only read by the group members of the owner and read by the others.

Changing the FAP (File Access Permission) of a file:

We can change the mode of any file or directory using the “chmod command”. Continuing with the above example of the output of 1s -1 option, let us take the “air.c” file. Suppose the user wants to revoke (denied) the execute permission, then the command is,

 

 

$ chmod      -x      air.c

$  _

 

If the user wants to grant the execute permission, then

 

$ chmod     +x    air.c

 

$  _

 

 

The granting and revoking of permission can be done together also like +wx for write and execute permission and –wx for revoking write and execute permissions.

FAP can be changed for one particular category or for all users. This is done by specifying the name of user before the “+/-“ sign.

‘u’  - granting or revoking of permission for the owner of the file only.

‘g’  - granting or revoking of permission for the group who need to share that file only.

‘o’  - granting or revoking of permissions for others only.

 

 


Like it on Facebook, Tweet it or share this article on other bookmarking websites.

Comments (0)

There are no comments posted here yet