Unix file types
From Wikipedia, the free encyclopedia
For normal files in the file system, Unix does not impose or provide any internal file structure. This implies that from the point of view of the operating system, there is only one file type.
The structure and interpretation thereof is entirely dependent on how the file is interpreted by software.
Unix does however have some special files. These special files can be identified by the ls -l
command which displays the type of the file in the first alphabetic letter of the file system permissions field. A normal file is indicated by a dash ('-
').
Contents |
[edit] Directory
The most common special file is the directory. The layout of a directory file is defined by the filesystem used. As several filesystems, both native and non-native, are available under Unix, there is not one directory file layout.
A directory is marked with a d as the first letter of the permissions field.
e.g
drwxr-xr-x /
[edit] Symbolic link
A symbolic link is a reference to another file. This special file is stored as a textual representation of the referenced file's path.
A symbolic link is marked with an l (lower case L) as the first letter of the permissions string.
e.g
lrwxrwxrwx termcap -> /usr/share/misc/termcap
[edit] Named pipe
One of the strengths of Unix has always been interprocess communication. Amongst the facilities provided by the OS are so called pipes. These pipes connect the output of one Unix process to the input of another. This is fine if both processes are living in the same parent process space, started by the same user. There are however circumstances where the communicating processes must use named pipes. One such circumstance is that the processes have to be executed under different user names and permissions.
These named pipes are special files that can exist anywhere in the file system. These named pipe special files are made with the command mkfifo
as in mkfifo mypipe
.
A named pipe is marked with a p as the first letter of the permissions string.
e.g
prw-rw---- mypipe
[edit] Socket
A socket is a special file used for inter-process communication. These allow communication between two processes running on the same machine. In addition to sending data, processes can send file descriptors across a Unix domain socket connection using the sendmsg() and recvmsg() system calls.
A socket is marked with a s as the first letter of the permissions string.
e.g
srwxrwxrwx X0
[edit] Device file
In Unix almost all things are handled as files and have a location in the file system - even hardware devices like hard drives. The great exception for devices and the files that represent them are network devices that do not turn up in the file system but are handled separately.
These files are used to apply access rights and to direct operations on the files to the appropriate device drivers.
Unix makes a distinction between character devices and block devices. The distinction is roughly as follows:
- Character devices provide only a serial stream of input or output.
- Block devices are randomly accessible.
A character device is marked with a c as the first letter of the permissions string. Likewise, a block device is marked with a b.
e.g
crw------- /dev/kbd brw-rw---- /dev/hda
[edit] Door
A door is a special file for inter-process communication between a client and server, currently implemented in the Sun Solaris operating system only.
A door is marked with a D (upper case) as the first letter of the permissions string.
e.g
Dr--r--r-- name_service_door