# How to change the stat command time format because of nanoseconds?



## Vanessa.k (Feb 24, 2021)

Hi,

here is an example on FreeBSD 12.2 and stat command

stat -f "Access (atime): %Sa%nModify (mtime): %Sm%nChange (ctime): %Sc%nBirth  (btime): %SB" /test.txt

Access (atime): Nov 19 17:26:43 2020
Modify (mtime): Nov 19 17:26:43 2020
Change (ctime): Nov 19 17:26:43 2020
Birth  (btime): Nov 19 17:26:43 2020


But I want to change the time format to for stat command and want to display the nanoseconds in case a filesystem is used that stores it.

I am looking for this result:
Access (atime): Nov 19 17:26:43.123456789 2020
Modify (mtime): Nov 19 17:26:43.123456789 2020 
Change (ctime): Nov 19 17:26:43.123456789 2020
Birth  (btime): Nov 19 17:26:43.123456789 2020

How can I change the time format for nanoseconds in stat command?
If it is not supported would it be possible to support it FreeBSD developers?


----------



## ralphbsz (Feb 25, 2021)

I don't see any way to do it with the command-line stat(1) version. Read the man page about the -f and -t flags, and there is nothing for nanoseconds.

It's easy to implement in C, python, perl, or any other language. Here is a python example:

```
import os
statresult = os.stat('test.file')
print(statresult.st_mtime)
```
The result for one file I just checked was "1614111187.210859". If you want more precision, the number is actually a floating point number. But beware, floats only have ~55 bits of mantissa, so you will not get the full nanosecond resolution this way (to fully represent that would require over 60 bits). But then, you probably don't really care about nanoseconds. Unless you want bit-wise accuracy, which happens if you want too change one of the times to exactly match, in which case you might want to use C instead of python.


----------

