How to display the link count of files using the ls command in Linux?

Published on Aug. 22, 2023, 12:17 p.m.

To display the link count of files using the ls command in Linux, you can use the -l option to show the long listing format, which includes the link count. Here is an example command:

ls -l

This will display a list of files and directories in the current directory, along with their permissions, owner, size, modification time, and link count.

The link count indicates how many hard links reference the same inode. This number includes the original file itself, so a file with a link count of 1 has only one hard link and no additional references to the same inode.

To display only the link count and no other information, you can use the -i option to show the inode number and the -l option to show the long listing format, like this:

ls -li

This will display a list of files and directories in the current directory, along with their inode numbers and link counts.

Note that symbolic links have a link count of 1 and do not affect the link count of the files they point to. To see the link count of the target file, use the stat command instead of ls.

Tags:

ls