On my Linux machine, I have the following file:
drwxr-xr-x 2 jsgdr Unix_31 4096 Dec 2 17:46 jsgdr
How to change the permission 2 to 4 so that I will this:
drwxr-xr-x 4 jsgdr Unix_31 4096 Dec 2 17:46 jsgdr
On my Linux machine, I have the following file:
drwxr-xr-x 2 jsgdr Unix_31 4096 Dec 2 17:46 jsgdr
How to change the permission 2 to 4 so that I will this:
drwxr-xr-x 4 jsgdr Unix_31 4096 Dec 2 17:46 jsgdr
The 2
and 4
are not permissions, but a count of the number of hard links to the file. From the GNU documentation (the POSIX specification of ls
specifies this, but this wording is clearer, IMHO):
‘-l’
‘--format=long’
‘--format=verbose’
In addition to the name of each file, print the file type, file mode bits,
number of hard links, owner name, group name, size, and timestamp (see
Formatting file timestamps), normally the modification time. Print question
marks for information that cannot be determined.
For example:
$ touch a
$ ls -l
total 0
-rw-r--r-- 1 root root 0 Dec 2 21:48 a
$ ln a b
$ ls -l
total 0
-rw-r--r-- 2 root root 0 Dec 2 21:48 a
-rw-r--r-- 2 root root 0 Dec 2 21:48 b
$ ln a c
$ ls -l
total 0
-rw-r--r-- 3 root root 0 Dec 2 21:48 a
-rw-r--r-- 3 root root 0 Dec 2 21:48 b
-rw-r--r-- 3 root root 0 Dec 2 21:48 c
For a directory, the hard link count is related to the number of subdirectories. See Why does a new directory have a hard link count of 2 before anything is added to it? for more information.
The number you are talking about doesn't refer to the permissions.
mkdir demo
cd demo
ls -ld
drwxr-xr-x 2 root root 4096 Dec 2 10:21 .
So, the number 2 here refers to,
However, if you want to see 4, you could see it when,
mkdir sub_demo{1,2}
ls -ld
drwxr-xr-x 4 root root 4096 Dec 2 10:23 .
As you could see, we are seeing the number 4 because we have 2 subdirectories that got created. So now 4 represents,
You could find a detailed explanation from my other answer here.