Get file details by inode

前端 未结 3 847
攒了一身酷
攒了一身酷 2021-01-14 01:07

I need in a bash script to get details about a file when I know the inode.The system is Linux.

相关标签:
3条回答
  • 2021-01-14 01:19

    You can use find with a combination of -inum and -xdev. This gives you the file's names (it can have more than one name), and from them you can find whatever information you want.

    0 讨论(0)
  • 2021-01-14 01:21

    If you're dealing exclusively with an ext2/3 filesystem, you can use debugfs to do your inode to file look-up, which can be considerably faster than using find for large filesystems with many files.

    debugfs -R "ncheck $inode" /dev/device 2> /dev/null | tail -1 | awk '{print $2}'
    

    Find is still really your best bet though, there is nothing else I know of that is filesystem agnostic.

    0 讨论(0)
  • 2021-01-14 01:25

    Something like so:

    find $SEARCHPATH -maxdepth $N -inum $INUM -exec ls -l {} \;
    

    Since the filename links to the inode, ans not vice-versa, you need to do this in a brute force manner. The -maxdepth is to narrow it down if you have some idea of where it should be. You can also ad -xdev if your searching a tree containing multiple filesystems.

    0 讨论(0)
提交回复
热议问题