stat test.log
File: `test.log'
Size: 573 Blocks: 8 IO Block: 4096 regular file
Device: 804h/2052d Inode: 7091301 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1001/ abc) Gid: ( 1001/ abc)
Access: 2010-11-29 17:56:22.000000000 -0800
Modify: 2010-11-29 17:56:22.000000000 -0800
Change: 2010-11-29 17:56:22.000000000 -0800
In the stat o/p above what does the Device entry signify ?
The stat is a command which gives information about the file and filesystem. Stat command gives information such as the size of the file, access permissions and the user ID and group ID, birth time access time of the file. Stat command has another feature, by which it can also provide the file system information.
Using stat to Report on Filesystems The -f (filesystem) option tells stat to report on the filesystem that the file resides on. Note we can also pass a directory such as “/” to stat instead of a filename. The information stat gives us is: File: The name of the file.
Notice this shows us the last access time while adding "c" shows us the change time (in this example, the time when we renamed the file). The stat command can also work against directories.
Stat system call is a system call in Linux to check the status of a file such as to check when the file was accessed. The stat() system call actually returns file attributes. The file attributes of an inode are basically returned by Stat() function. An inode contains the metadata of the file.
It's the major and minor device number combined into one value (in hex and decimal) of the device on which the file resides.
For your example, 804h
is major device 8, minor device 4. if you run df .
while you're in the directory where that file is, you'll get the device name such as /dev/sda1
. If you were to then do ls -al /dev/sda1
, it would show you the device numbers. Here's an example:
pax$ stat newfile # note device 801h, hex 801 = 2049 decimal
File: 'newfile'
Size: 2097152 Blocks: 4096 IO Block: 4096 regular file
Device: 801h/2049d Inode: 2888080 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ pax) Gid: ( 1000/ pax)
Access: 2010-11-29 07:32:22.011271661 +0800
Modify: 2010-08-30 15:43:14.286796827 +0800
Change: 2010-08-30 15:43:14.286796827 +0800
pax$ df . # to get current device mount
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 470301088 182471788 263939332 41% /
pax$ ls -al /dev/sda1 # to get major/minor = 8/1
brw-rw---- 1 root disk 8, 1 2010-11-30 07:02 /dev/sda1
# stat tool
File: `tool'
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 801h/2049d Inode: 671689 Links: 3
# ls -l /dev/sda*
brw-rw---- 1 root disk 8, 0 2010-08-16 14:43 /dev/sda
brw-rw---- 1 root disk 8, 1 2010-08-16 14:43 /dev/sda1
brw-rw---- 1 root disk 8, 2 2010-08-16 14:43 /dev/sda2
brw-rw---- 1 root disk 8, 5 2010-08-16 14:43 /dev/sda5
In the example, 'tool' (801h) is in /dev/sda1
(major device number is 8, minor device number is 1). That's the first partition in /dev/sda
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With