I'm running a long string of -exec commands, and I want to pull a timestamp from the beginning of the run to use as a value for subsequent commands. Is this possible? Something like:
find . -exec NOW=$(date +%s) {} \; -exec echo $NOW."$0" {} \;
find . -exec set NOW=$(date +%s) {} \; -exec echo $NOW."$0" {} \;
find . -exec export NOW=$(date +%s) {} \; -exec echo $NOW."$0" {} \;
Those don't seem to work, but if I just use $(date +%s) instead of setting the value, I get inconsistent timestamps because each subsequent -exec is happening later in time.
What I want is a different timestamp to use for each file. For example, modifying someones suggestion, this may show my intent better:
find . -exec sh -c '
NOW=$(date +%s); for f in "$@"; do echo "$NOW $f First Output"; sleep 3; echo "$NOW $f Second Output"; done
' find-sh {} +
That command doesn't do what I want, but shows that the delay when acting on the first file should not change the timestamp, should output the timestamp and file name, sleep 3, and output the SAME timestamp for that file. Then I want it to create a new timestamp to use with the next file.
-exec
commands, but you can write the data to a file.-exec
commands will take longer than a second? If the commands run faster you will get the same timestamp for several files.