Andrew Que Sites list Photos
Projects Contact
Main

October 22, 2021

Getting file creation time in Linux

I’ve known for awhile that getting the creation time of a file in Linux isn’t an easy task. There are three timestamps on every file: modified time, access time, and change time. Change time acts like modified time except it also changes if the file’s attributes change. Access time is the last time the file was opened. POSIX has no timestamp for when the file was created. However, most modern file systems do (ext4, btrfs, zfs and others).

Despite file system for support for creation time, actually getting the value isn’t trivial. The function stat can print the birth field, but it is often blank. This is because the POSIX C function stat doesn’t include creation time. In Linux there is a new function called statx (get file status extended) which includes the creation time. It requires a kernel of at least 4.11, and glibc 2.28.

However, just because those requirements are met doesn’t mean the stat command line utility will use statx. For that one needs GNU coreutil of at least version 8.31. Currently the version of coreutil on Mint is 8.30. So close.

I decided today I could no longer live without having creation time. To get this functionality one just needs to download and compile the latest coreutil and I found a website that described the process. The setup took much longer than the compile itself. Running parallel on 16 threads makes quick work out of many builds. I installed it and just like that I had the file creation time showing up in the stat command output.

Before:

File: temp
Size: 5         	Blocks: 8          IO Block: 4096   regular file
Device: 3bh/59d	Inode: 86528       Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/     que)   Gid: ( 1000/     que)
Access: 2021-10-21 10:36:08.885699682 -0500
Modify: 2021-10-21 10:35:53.401775358 -0500
Change: 2021-10-21 10:35:53.401775358 -0500
 Birth: -

After:

File: temp
Size: 5         	Blocks: 8          IO Block: 4096   regular file
Device: 9,0	Inode: 30225103    Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/     que)   Gid: ( 1000/     que)
Access: 2021-10-21 10:36:08.885699682 -0500
Modify: 2021-10-21 10:35:53.401775358 -0500
Change: 2021-10-21 10:35:53.401775358 -0500
 Birth: 2021-10-21 10:33:05.154597661 -0500
Departing sun

Departing sun

   Over the past couple days I have been working on a basic status monitor script.  I have a half-dozen backups that take place periodically.  The critical backups send an e-mail when they fail, but several others do not.  The e-mails are nice if the script actually runs, but what happens if the script never launches?  I decided rather than modify all the scripts to send an e-mail, I would have them all create a log file.  Then I would make a status monitor that would check the status of each of these log files.  If the script encountered errors, that could be displayed.  And if the script had not run in a designated amount of time, an error would also be displayed.
   The script is really basic.  Every backup creates two log files: one for what it did, and one for errors.  This is done simply by piping stdout and stderr to files.  Any size above 0 on the error file means there was a failure.  And if the modified date of the log file is greater than the backup period, the backup didn't run.  The script currently displays the name of the process, if it functional, the last time the process ran, and how long ago it ran.  My 6-monitor setup has a monitor that displays the status of various running processes, so this script fits nicely into that setup.
   Pictured is sunset half way through my Martinsville-Waunakee loop today.  The clouds made for a very pretty sunset.
James and Arrakis Eggs

James and Arrakis Eggs

   James in front of his new creation: eggs pickled in ghost pepper brine.  James received a bunch of super hot peppers which were an assortment of ghost, scorpion, and Carolina reapers.  A couple weeks ago he juiced a bunch of them to start a fermentation process with the goal of making some kind of supper hot sauce that could be added to things.  As we talked James wondered out loud what he might make with some leftovers.  I suggested pickled eggs and we both agreed that would be amazing.  The other day I picked up a bunch of eggs and today James hard boiled them and made a pickle brine with the hot sauce.  I have suggested we call them Arrakis Eggs as even if the spice doesn't flow, your nose will.
   Just the act of heating the mixture a little bit made it very difficult to breath without coughing—these peppers are no joke. 
   The number of comments on my polynomial regression online calculator has reached a point where the comments were more of the page than the other content.  I had written a new comment system for my CRC site but had not yet moved the polynomial site to use it.  This afternoon I made that change.  There was a fair bit of work to convert the old comments, which had the character translations built into the stored comments.  The new system does the conversion at display time rather than post, so those changes needed to be reversed.  The comments are much more compressed.
   Since I was doing updates, I decided to also make a couple small changes.  I allowed the precision of calculations to be specified.  This allows users needing higher precision the ability to set it.  The server for DrQue.net has plenty of processing power which is hardly used by the existing site.  So allowing the higher precision should not be an issue.
   Our comment section on both the polynomial regression page as well as my main site have both had SPAM from educational institutions in south Asia, mainly India.  The comments say something extremely generic like "What a great article" and then link to the site.  I have been deleting these comments because they are simply SPAM.  My guess is they are just looking to get ranked higher by search engines by having their sites linked from other sites, and the useless comments are an easy way to make this happen.  I plan to remove the comments as well as forbid robots from loading the comments.  This should prevent search engines from including the comments and thus not allowing spammers to promote themselves.
   Pictured is Maya in front of a whole-made thongophone in a cement silo.  This is played with old flip-flop shoes and the tall cement silo makes a good resonance chamber.  It was a lot of fun.
   Visited a corn maze in Lodi with Maya, Mira, Pokie, Collin, Noah and Mary this afternoon.  We did the maze last year and found 9 of the 10 secret locations.  This year we were determined to be better.  Noah and I used a fairly efficient strategy of plotting out trek through the maze in a manner such that we were likely to pass by potential secret locations while being able to quickly deploy someone down a side channels.  Without a huge effort or much backtracking we discovered all 10 secret locations.  The maze didn't take much longer than simply getting through it normally.
   While the kids enjoyed finding sections of the map to complete the maze, they were far more interested in the hayloft and playground.  We spent nearly 5 hours at the location.