Linux temporary file creation conditions

I am trying to do what, in my opinion, is simple on Linux. I have a bash script that runs various test programs, and I want to determine which files in the current directory were created by the test programs. So I am doing something like this:

touch timestamp-file
run the test
find -newer timestamp-file -type f> list-of-files
rm -f timestamp-file

It turns out that the granularity of find -newer is unsatisfactory, so it usually happens that some files that were generated by the test program are displayed as OLDER than the timestamp file. So, I tried this:

ls -tr1 | sed '1, / timestamp-file / d'

to create the same list. This usually works, but not always. I still ended up in a situation where the files that were generated by the test look older than the timestamp file.

Thanks!

PS I can do it differently by taking two snapshots of the directory, one before running the test program, and then one after it and comparing them. Any files in the second list that are not included in the first place should be created by the test program (I am not interested in background jobs or other users writing to the directory). But this method is not what I want, because if the output file was not deleted before the test was run (they should be, but in some cases they may not be), this method will say that it was not created because it was located in the directory before running the test program.

+3
4

, :

find -printf '%p %T@\n' | sort > file1

, stat :

find -print0 | xargs -0 stat -c "%n %Y" | sort > file1

>

file2.

comm -1 -3 file1 file2

, file2, , . , , %T@ thingy ( 1970 ):

[js@HOST2 cpp]$ find -printf '%p %T@\n' | sort > file1
[js@HOST2 cpp]$ echo foo>bar
[js@HOST2 cpp]$ echo foo>baz
[js@HOST2 cpp]$ find -printf '%p %T@\n' | sort > file2
[js@HOST2 cpp]$ comm -1 -3 file1 file2
. 1230947309.0000000000
./bar 1230947308.0000000000
./baz 1230947309.0000000000
./file2 1230947315.0000000000
[js@HOST2 cpp]$ find -printf '%p %T@\n' | sort > file1
[js@HOST2 cpp]$ echo lol>bar
[js@HOST2 cpp]$ find -printf '%p %T@\n' | sort > file2
[js@HOST2 cpp]$ comm -1 -3 file1 file2
./bar 1230947359.0000000000
./file2 1230947362.0000000000
[js@HOST2 cpp]$`
+1

touch , :

touch -t 200801010000.00 *

, "find -newer", . , , 5 , .

, script :

touch -t (current time - 10 minutes) *
touch -t (current time -  5 minutes) timestamp-file
run the test
find -newer timestamp-file -type f > list-of-files
rm -f timestamp-file

, Perl, , 5 ( -600 10 ) "date -t":

use Date::Manip;
print UnixDate(DateCalc(ParseDateString("now"),"-300"),"%Y%m%d%H%M.%S") . "\n";

- , :

sleep 300
touch timestamp-file
sleep 300
run the test
find -newer timestamp-file -type f > list-of-files
rm -f timestamp-file

, , , ( , ).

+3

, find(1), , , . :

  $ touch timestamp ; touch newer ; find . -newer timestamp 
  $ rm timestamp newer
  $ touch timestamp ; sleep 1 ; touch newer ; find . -newer timestamp
  .
  ./newer
  $

find(1) mtime/ctime/atime stat(2). struct stat <sys/stat.h> (Linux):

  time_t    st_atime;   /* time of last access */
  time_t    st_mtime;   /* time of last modification */
  time_t    st_ctime;   /* time of last status change */

Linux (, , ) time_t , " 1970 ". , -newer , .

+2

? , , , .

0

All Articles