GNU find .extension files and -exec, while new .extension files are being made

0

Here is a problem, can someone please explain or provide some references. I've been trying to read since an hour but can not find the answer.

Suppose, I have process1 going on a pool of directories. process1 picks a directory and creates, say, .csv files inside it. The .csv files are being appended to, and are, therefore, incomplete while process1 is continuing on this, say, directory1. process1 then moves on to directory2 and so on.

Now, I want to do something with csvs in directories that process1 has finished with. Ideally, I should check which directories have been finished with and run process2 on those. But in my infinite wisdom, I do this:

find directories* -type f -name '*.csv' -exec process2

My assumption was that find will first find all csvs existing till the point of invocation of find and then -exec process2 on those only, ignoring any csvs that will have been made after the invocation of find.

It seems I was wrong (still not sure). Can someone explain, please?

Thanks.

ASB

Posted 2013-01-02T17:35:50.933

Reputation: 3

Couldn't you have process1 execute process2 after it finishes with the file? – Rob – 2013-01-02T17:58:56.097

Well yes. You are right. It is not a problem as in there isn't a solution. This is a problem as in I did something this stupid and am now just trying to understand the repercussions of it. Thanks anyway. – ASB – 2013-01-02T18:31:08.897

Answers

2

The way find works with -exec is that the exec process is called as each file is found. If you want to work from a snapshot, you're probably better off doing something like this:

find directories* -type f -name '*.csv' > /tmp/filelist
cat /tmp/filelist | while read file; do 
  process2 $file # I'm assuming you want to pass the filename somehow...
done;

Again, you still have no idea which ones are actually being written to, so you have to solve that separately.

BowlesCR

Posted 2013-01-02T17:35:50.933

Reputation: 2 607