0

I want to know what is %T specifier in stat printf option and how it gets the file descriptor value ie., fd,1 is printed by using the below command.

command is

$> echo `stat -L /dev/mapper/VolGroup-LogVol00 --printf="%T\n"`

ouput: 1 --> which relates to "dm-1"

Thanks in advance for any reply.

cxw
  • 1,689
  • 1
  • 16
  • 27

1 Answers1

1

This format isn't defined by bash, but by stat(1). Per the linked man page, %T gives the minor device type in hex. I don't have your specific configuration, but, for example:

$ ls -l /dev/sda2
brw-rw-rw-  1 <user> <group>   8,   2 Oct  9 10:29 sda2
                               ^    ^
                               |    +-- minor device number
                               +------- major device number
$ stat /dev/sda2 --printf='%T\n'
2      <--- This matches the minor  ^ device number
$

If you ls -lH /dev/mapper/VolGroup-LogVol00, you should see <something>, 1 in the output - 1 is the minor device number.

Edit to answer your additional questions:

"how %T specifier able to get that output": by calling the stat(2) system call. The st_rdev member of the resulting structure has the minor device number, which can be extracted with minor(3). For use in your own scripts, just use stat(1) like you've been doing.

"what is the functionality of %T specifier in bash printf command": it is totally unrelated to devices. Per the bash hackers' wiki, it is the current time, formatted as for strftime(3). The wiki gives an example:

$ printf 'This is week %(%U/%Y)T.\n'
This is week 52/2010.
cxw
  • 1,689
  • 1
  • 16
  • 27