Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Device number in stat command output

Tags:

linux

  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 ?

like image 464
Ankur Agarwal Avatar asked Nov 30 '10 01:11

Ankur Agarwal


People also ask

What does the stat command do?

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.

How use stat in terminal?

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.

Can you use stat on a directory?

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.

Is stat a system call?

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.


2 Answers

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
like image 124
paxdiablo Avatar answered Sep 20 '22 09:09

paxdiablo


# 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.

like image 25
Huang F. Lei Avatar answered Sep 18 '22 09:09

Huang F. Lei