1

I was trying to figure this out but found myself clueless: How can I figure out the name of the device (e.g. /dev/sdb2) for a given file/inode? e.g.

[root@serv07 /]# ls -i /etc/passwd
38357228 /etc/passwd

Now, I know that inode 38357228 (or passwd) resides on /dev/sda2 but how can I figure that out for any given/random file(s)? Any help would be useful. Cheers!!

3 Answers 3

4

You can use df

df -P filename

will give you something like:

Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/root      280496152 31269088 235090852  12% /

-P is --portability to get POSIX output

Just to be convenient:

df -P filename | awk 'NR==2{print $1}'

Will give you just the device

0
2

You can get the mount point for a given file with stat:

$ stat -c '%m' /etc/fstab
/

You can use this to look up what is mounted there using /proc/mounts

awk '$2 == "/"'  /proc/mounts
1
  • I don't see any %m format option in my version of stat; tried on RHEL/CentOS and Ubuntu - none of them has that. What distro are you on? Cheers!
    – MacUsers
    Mar 14, 2012 at 19:04
2

You can use the stat command. See this question on Stack Exchange for the gory details:

https://stackoverflow.com/questions/4309882/device-number-in-stat-command-output

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .