What does the first character of UNIX mode string indicate?
It means that the file is a character special file - basically a device file that provides serial access (as opposed to a block special device such as a disk drive). For example terminals and serial devices are interfaced through character special files (/dev/tty1
, /dev/ttyS0
and so on).
For a brief introduction to device files, see Linux / UNIX: Device files [cyberciti.biz]. For a more detailed discussion see this stackexchange answer Understanding /dev and its subdirs and files. To learn about the underlying data structures refer to Chapter 4 of The Linux Kernel Module Programming Guide: Character Device Files [tldp.org]
The first character identifies the Unix File Type: A character device is marked with a c
as the first letter of the mode string. Likewise, a block device is marked with a b
,
$ ls -l /dev/null
crw-rw-rw- 1 root root 1, 3 Jan 21 21:50 /dev/null
$ ls -l /dev/sda
brw-rw---- 1 root disk 8, 0 Jan 21 21:50 /dev/sda
there are more of these special devices (files in a sense that everything is a file in Linux),
d : directory
s : socket
p : pipe
D : Door
l : symbolic link etc.
See this wikipedia page for more details.
ls -l
outputs a 10 symbol UNIX string of information popularly known as permission string. e.g.
-rw-rw-r-- 1 userName groupName 13200650 Dec 13 21:23 fileName
The first character of permission string or mode string, known as the file descriptor, indicates the file type and the remaining nine taken in groups of three indicate the permissions for the file concerned, where:
- the first group of three characters (after the first character among the 10) indicate owner's permissions,
- the second group of three designate permissions for the group,
- the last group of three designate permissions for others (or the world).
Here, in above example the first character/symbol the "-" indicates a normal file.
While in the following examples,
crw-rw-rw- 1 root root 1, 3 Dec 29 20:58 /dev/null
crw-rw-rw- 1 root root 1, 5 Jan 13 20:56 /dev/zero
the permission strings' first character is "c" and like stated above, it is a file-type indicator which indicates a character device.
Apart from the -
, c
some other file descriptors are:
-
d
-> directory -
l
-> symbolic link -
s
-> Unix socket -
b
-> block device -
p
-> pipeline -
D
-> Door
References:
- Device file
- Unix Permissions
- Modes
The first character in the first column, i.e., 'c ' in crw-rw-rw- above, tells an informed user the type of the file, in this case a character device.