I need in a bash script to get details about a file when I know the inode.The system is Linux.
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.
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.
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.