If I'm scanning a large tree and want to pass results to another command before scanning the whole thing, will the ; option do this? From my reading, it seems to, but I want to be certain there's no background caching. If there is background caching, I want to know so I can use for loops instead.

When running find on a few files, there is no delay or strain on the disc. For a script that runs often, and on a long list of files, it can take minutes before find passes the full list to the next command. I want find to only run on one file at a time, and also refrain from searching the target until the previous -exec is completed.

  • 4
    Please expand on what you want to do and what you mean by background caching (of what?) and in what context? The scan lare tree and pass results to a command followed by before scanning doesn't make sense to me either. – Stéphane Chazelas Oct 25 '17 at 15:53
  • Don't expand on your question in comments; edit the question to incorporate the new information. – DopeGhoti Oct 25 '17 at 16:14
  • Ok I put the comment in my question. – Lumify Oct 25 '17 at 16:26
  • I think so, if that reduces wear on the file device. – Lumify Oct 25 '17 at 16:46
  • 2
    @Lumify "reduces wear"? It feels like there's quite a lot of information missing from the question, especially what your concerns are and what the issue is. – Kusalananda Oct 25 '17 at 17:00

You seem to be asking whether

find -exec some_command '{}' \;

will execute some_command once for each file, sequentially, without doing anything else in the background while some_command is executing.

Indeed this is true.

However, you also seem to think that this would decrease wear on the hard drive. This is probably not the case -- starting and stopping I/O lots of times requires more mechanical movements than reading lots of data at once, and so probably results in (very slightly) more wear on a traditional spinning hard drive.

  • I appreciate the illustration of the utilization of -exec – Yu Shen Dec 23 '17 at 21:51

You could try a bit different approach and use named pipes: How to launch a pipe as a persistent process


  1. Create a named pipe
  2. Launch your process which you wanted to use in find's -exec argument and have it read from pipe.
  3. Launch the find process and have it write the results to the pipe
  4. From your process then you could control and stop find if you reach a result that means you don't need to list the rest of the files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.