I’m trying to do what I think is a simple thing under Linux. I have a bash script which 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
Turns out the granularity of find -newer is poor, so what typically happens is that some files which were generated by the test program show up as OLDER than the timestamp file. So then I tried this:
ls -tr1 | sed '1,/timestamp-file/d'
to generate the same list. This usually works, but not always. I still end up with the situation where files which were generated by the test show up as older than the timestamp file.
Thanks!
P.S. I can accomplish this another way by taking two snapshots of the directory, one before the test program runs, and then one after, and comparing them. Any files in the second list which are not in the first must have been created by the test program (I’m not concerned with background jobs or other users writing to the dir). But this method is not what I want because if an output file wasn’t removed prior to running the test (they’re supposed to be, but in some cases they may not be), this method will say it was not created by the test program because it was in the dir before the test program was run.
Take the filenames of all the files before the run, but include their timestamps:
If you haven’t got that find option available, you can use stat for that job too:
And after the run to
file2. Then useAnd it will show you the lines unique to
file2, which must be new files if i’m not mistaken. If they existed before, their modification time will have changed, which is taken care by the%T@thingy (printing out the number of seconds since 1970):