如何ls命令找到硬盘连接数? [英] How does the ls command find the hard link count?

查看:188
本文介绍了如何ls命令找到硬盘连接数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何命令的ls -l <​​/ code>算一个inode的硬链接的数量?
它使用Linux API或者是code,需要Linux内核源代码code的更深的认识?

How does the command ls -l count the number of hard links of an inode? Does it use the Linux API or is it code that requires deeper knowledge of the Linux kernel source code?

我不是,但是,能够理解 LS源$ C ​​$ C ,因为我刚开始学习C

I am not, yet, able to understand the source code of ls, because I just started learning C.

推荐答案

下面是说明用户一个真正简单的程序 STAT()找到硬链接数:

Here is a real simple program illustrating the user of stat() to find hard-link counts:

#include <stdio.h>
#include <sys/stat.h>

int main ( int argc, char ** argv ) {
    int     i;
    struct stat st;     /* stat puts info here */

    for (i = 1; i < argc; ++i) {
        if (stat(argv[i], &st) == -1) perror(argv[i]);
        else printf("%s has %d hard links\n", argv[i], st.st_nlink);
    }
    return 0;
}

(它传递命令行上的一个或多个文件名称)

这篇关于如何ls命令找到硬盘连接数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆