Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question