
我在谷歌上幾乎找不到任何可以幫助我回答這個問題的東西。我認為它正在將其他一些參數傳遞給ls -i
?
答案1
是的,參數 -i 將列印 ls 指令列出的每個檔案或目錄的索引節點號。當您想要列印目錄的索引節點號時,我建議使用參數 -d 僅列出目錄。若要列印目錄 /path/to/dir 的 inode 編號,請使用下列命令列:
ls -id /path/to/dir
從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
答案2
這也適用於 stat:
DIR=/
stat -c '%i' $DIR
從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
答案3
-i
您可以使用選項找到檔案和目錄的索引節點
ls -id /home/user/dir
您可以獲取系統消耗的inode信息
df -hi
答案4
在 C++ 中:
#include <sys/stat.h>
ulong getInode( const QString &path )
{
struct stat st;
stat( path.toUtf8(), &st );
return st.st_ino;
}
這應該適用於文件和資料夾。