如何找到任何目录的inode?

Str*_*be_ 16 ls inode

谷歌上几乎没有任何东西可以帮助我回答这个问题。我认为它正在将其他一些参数传递给ls -i?

sto*_*eff 29

是的,参数 -i 将打印 ls 命令列出的每个文件或目录的 inode 编号。由于您想打印目录的 inode 编号,我建议使用参数 -d 仅列出目录。要在目录 /path/to/dir 中打印 inode 编号,请使用以下命令行:

ls -id /path/to/dir
Run Code Online (Sandbox Code Playgroud)

来自man ls

   -d, --directory
          list  directory entries instead of contents, and do not derefer?
          ence symbolic links
   -i, --inode
          print the index number of each file
Run Code Online (Sandbox Code Playgroud)


小智 19

这也适用于 stat:

DIR=/
stat -c '%i' $DIR
Run Code Online (Sandbox Code Playgroud)

来自man stat

   -c  --format=FORMAT
          use the specified FORMAT instead of the default; output  a  new?
          line after each use of FORMAT
[...]

   The valid format sequences for files:    
       %i     inode number
Run Code Online (Sandbox Code Playgroud)

  • 我想添加来自 [FreeBSD](http://www.freebsd.org/cgi/man.cgi?query=stat&sektion=1), [NetBSD](http:// netbsd.gw.com/cgi-bin/man-cgi?stat+1), [OpenBSD](http://www.openbsd.org/cgi-bin/man.cgi?query=stat&sektion=1) 和 [OS X](https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/stat.1.html) 的工作方式有点不同,`stat -f '%i' $DIR` 有要使用的。 (2认同)