Unix File Types (Unix 文件類型)
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 (regular) file is indicated by a hyphen-minus '-'.
Regular file (一般常規文件)
$ ls -dl /etc/passwd
-rw-r--r-- ... /etc/passwd
$ ls -dl /
drwxr-xr-x 26 root root 4096 Sep 22 09:29 /
Symbolic link (軟鏈接＝win中的快捷方式)
A symbolic link is a reference to another file. This special file is stored as a textual representation of the referenced file's path (which means the destination may be a relative path, or may not exist at all).
lrwxrwxrwx ... termcap -> /usr/share/misc/termcap
lrwxrwxrwx ... S03xinetd -> ../init.d/xinetd
Named pipe (管道)
In computing, a named pipe (also known as a FIFO for its behavior) is an extension to the traditional pipe concept on Unix and Unix-like systems, and is one of the methods of inter-process communication (IPC).
gzip -9 -c < my_pipe > out.gz &
cat file > my_pipe
prw-rw---- ... mypipe
A socket is a special file used for inter-process communication. These allow communication between two processes. In addition to sending data, processes can send file descriptors across a Unix domain socket connection using the sendmsg() and recvmsg() system calls.
Unlike named pipes sockets are fully duplex-capable.
srwxrwxrwx ... /tmp/.X11-unix/X0
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.
Device 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;
character devices(字符设备)的內容沒有的特殊結構，就只有簡單的字串流，而block devices的讀取方式是以block為單位的，可以做到隨機讀取的效果，比如硬盤就屬於block devices，serial ports屬於character devices。
crw------- ... /dev/null
brw-rw---- ... /dev/sda