6
6
6elkka2017-02-16 20:09:21
bash
6elkka, 2017-02-16 20:09:21

How to limit gnu find output to a specific number?

Let's say bash wants to use only the first result of a find search.
In this case, you do not need to search for everything, because this can be resource-intensive.
In man find, I did not find any keys to limit the number of results (only limits on the depth of the search).
One option is to use the bash pipeline so that find exits with the pipeline, which in turn exits with head. However, this solution is not ideal, because in the pipeline find still works [a little] more than it should and finds more files. Which solution is better than this (where find actually looks for only one file)?
first_result="$(find -name '*foo*' | head -n 1)"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2017-02-16
@6elkka

For one, everything is just
unix.stackexchange.com/questions/62880/how-to-stop...
The NetBSD find equivalent:
for several, you already need to write code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question