What does the number after Unix/Linux file permissions like "-rw-rw-r--. 1 " mean in "ls -l" output

24,497

Solution 1

Some examples:

-rwxrw-r-- 1 is a file with read, write and execute privileges for the owner. The group has read and write, and others have only read. There are no links to this data.

drwxr-xr-x 10 is a directory with 8 files. The extra 2 are . and ... Only the owner can create files in this directory, others can access which files are in the directory, and read the contents of those files if the privileges allow.

-r-------- 2 is a file which only the owner can read, but cannot execute or modify. It has a link, which means there is another file reference on disk somewhere that accesses the same data. So the actual "file content" on disk has 2 "files" referencing it. These links are often created using ln without supplying -s.

So:

  • Character 1 is node type: commonly - or d indicating file or directory.
  • Characters 2, 3, 4 indicate read, write, and execute for the owner.
  • Characters 5, 6, 7 do the same for the group.
  • Characters 8, 9, 10 do the same for others.
  • The number succeeding permission characters indicates the number of links if the node is a file, and number of "sub-nodes" if the node is a directory.

See chapter The Long Format of man ls.

Solution 2

For files it is the number of hard-links to the contents of the file. 1 means no hard-links (the typical case), a number N above 1 means this and another N-1 filenames share the same contents.

For directories most but not all filesystems report a link count of 2+N where N is the number of sub-directories.

Solution 3

[max@localhost ~]$ ll

total 4

drwxrwxr-x 2 max max 4096 Sep 25 17:11 zzz

Here 2 means number of link count

now I will create 3 directories inside zzz

now value changes to 5

[max@localhost ~]$ cd zzz
[max@localhost zzz]$ mkdir a b c
drwxrwxr-x 5 max max 4096 Sep 25 17:16 .
drwx------ 5 max max 4096 Sep 25 17:12 ..
drwxrwxr-x 2 max max 4096 Sep 25 17:16 a
drwxrwxr-x 2 max max 4096 Sep 25 17:16 b
drwxrwxr-x 2 max max 4096 Sep 25 17:16 c

[max@localhost zzz]$ cd

[max@localhost ~]$ ll

total 4

drwxrwxr-x 5 max max 4096 Sep 25 17:16 zzz

That is because now 5 directories are present inside zzz 3 are a b c and 2 are hidden directories . ..

if I create file then nothing will happen to link count

[max@localhost zzz]$ touch 1 2 3
[max@localhost zzz]$ ls -al
total 20
drwxrwxr-x 5 max max 4096 Sep 25 17:26 .   ------> current directory link count
drwx------ 5 max max 4096 Sep 25 17:12 ..  ------> parent directory link count
-rw-rw-r-- 1 max max    0 Sep 25 17:26 1
-rw-rw-r-- 1 max max    0 Sep 25 17:26 2
-rw-rw-r-- 1 max max    0 Sep 25 17:26 3
drwxrwxr-x 2 max max 4096 Sep 25 17:16 a
drwxrwxr-x 2 max max 4096 Sep 25 17:16 b
drwxrwxr-x 2 max max 4096 Sep 25 17:16 c
[max@localhost zzz]$ cd
[max@localhost ~]$ ll
total 4
drwxrwxr-x 5 max max 4096 Sep 25 17:26 zzz

but if I delete any directory then link count will change

[max@localhost zzz]$ rmdir b c
[max@localhost zzz]$ cd
[max@localhost ~]$ ll
total 4
drwxrwxr-x 3 max max 4096 Sep 25 17:28 zzz
Share:
24,497

Related videos on Youtube

VAR121
Author by

VAR121

Updated on September 18, 2022

Comments

  • VAR121
    VAR121 over 1 year

    Can any one explain -rw-rw-r--. 1 and give some "detailed" information on ls -lart command.

    Specifically, what does the number 1 after the file permissions mean? Why does it change or why is it different for different files?

  • ndemou
    ndemou over 5 years
    Much (maybe too much) detail for dirs not a word for files.