23

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?

5
  • 4
    en.wikipedia.org/wiki/… Sep 21, 2012 at 10:03
  • 2
    Have you tried finding information yourself (manual pages, etc.)? Was the information unclear? Sep 21, 2012 at 10:14
  • 1
    @yi_H, I don't see any information on the number after the permissions.
    – Shahbaz
    Sep 21, 2012 at 10:25
  • 1
    I was sure user1688102's question had already been asked and answered but can't find it. @Shahbaz: it;s the number of references to the same inode, i.e. the number of hard-links, i.e. the number of different names for the same file (excluding soft-links). Sep 21, 2012 at 10:40
  • 1
    I've seen the man ls page. The information was not clear and no information was provided regarding permissions in man ls @Daniel
    – VAR121
    Sep 21, 2012 at 12:03

3 Answers 3

20

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.

3
  • As @sapht said the number(for a directory) at the end implies the number of files in a directory is wrong I guess. Because I have thousands of files in directory and it is still showing 2
    – VAR121
    Sep 21, 2012 at 12:08
  • I've never seen an ls that doesn't print directory subnode count using long format. Which OS/distribution are you on? Gnu ls, , busybox and darwin all print the node count. Is it really a directory and not another node type?
    – sapht
    Sep 21, 2012 at 15:17
  • My distro (Linux Mint 18.3) doesn’t have such a chapter in ls’s man page. None of the fields are explained there. I think it’s the same for Ubuntu.
    – bleistift2
    Feb 20, 2020 at 16:42
6

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.

1

[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
1
  • Much (maybe too much) detail for dirs not a word for files.
    – ndemou
    Jan 16, 2019 at 16:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .