File System in Linux
File System in Linux
Types of files:
A simple description of the UNIX system is this: “On a UNIX system, everything
is a file; if something is not a file, it is a process.”
A UNIX system makes no difference between a file and a directory, since a
directory is just a file containing names of other files. Programs, services, texts, images,
and so forth, are all files. Input and output devices, and generally all devices, are
considered to be files, according to the system.
Most files are just files, called regular files; they contain normal data, for example
text files, executable files or programs, input for or output from a program and so on.
While it is reasonably safe to suppose that everything you encounter on a UNIX system
is a file, there are some exceptions.
Special files or Device Files: All devices and peripherals are represented by files. To
read or write a device, you have to perform these operations on its associated file. Most
special files are in /dev.
(Domain) sockets: a special file type, similar to TCP/IP sockets, providing inter−process
networking protected by the file system's access control.
Named pipes: act more or less like sockets and form a way for processes to
communicate with each other, without using network socket semantics. (Pipes will be
discussed).
This is the most common file type. An ordinary file can be either a text file or a
binary file.
A text file contains only printable characters and you can view and edit them. All
C and Java program sources, shell scripts are text files. Every line of a text file is
terminated with the newline character.
A binary file, on the other hand, contains both printable and nonprintable
characters that cover the entire ASCII range. The object code and executables that you
produce by compiling C programs are binary files. Sound and video files are also binary
files.
Directory File
A directory contains no data, but keeps details of the files and subdirectories that
it contains. A directory file contains one entry for every file and subdirectory that it
houses. Each entry has two components namely, the filename and a unique
identification number of the file or directory (called the inode number). (About inode we
will discuss).
When you create or remove a file, the kernel automatically updates its
corresponding directory by adding or removing the entry (filename and inode number)
associated with the file.
Device File
All the operations on the devices are performed by reading or writing the file
representing the device. It is advantageous to treat devices as files as some of the
commands used to access an ordinary file can be used with device files as well.
Device filenames are found in a single directory structure, /dev. A device file is not really
a stream of characters. It is the attributes of the file that entirely govern the operation of
Filenames
Alphabets and numerals. The period (.), hyphen (-) and underscore (_).
UNIX imposes no restrictions on the extension. In all cases, it is the application
that imposes that restriction. Eg. A C Compiler expects C program filenames to end with
.c, Oracle requires SQL scripts to have .sql extension.
A file can have as many dots embedded in its name. A filename can also begin
with or end with a dot. UNIX is case sensitive; cap01, Chap01 and CHAP01 are three
different filenames that can coexist in the same directory.
A file is a set of data that has a name. The information can be an ordinary text, a
user-written computer program, results of a computation, a picture, and so on. The file
name may consist of ordinary characters, digits and special tokens like the underscore,
except the forward slash (/). It is permitted to use special tokens like the ampersand (&)
or spaces in a filename. Unix organizes files in a tree-like hierarchical structure, with the