Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

Why does the number change after "-rw-rw-r--. 1 " <----

share|improve this question

migrated from stackoverflow.com Sep 21 '12 at 9:59

This question came from our site for professional and enthusiast programmers.

3  
en.wikipedia.org/wiki/… –  Karoly Horvath Sep 21 '12 at 10:03
1  
Have you tried finding information yourself (manual pages, etc.)? Was the information unclear? –  Daniel Andersson Sep 21 '12 at 10:14
    
@yi_H, I don't see any information on the number after the permissions. –  Shahbaz Sep 21 '12 at 10:25
    
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). –  RedGrittyBrick Sep 21 '12 at 10:40
    
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 '12 at 12:03

2 Answers 2

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.

share|improve this answer
    
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 '12 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 '12 at 15:17

[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|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.