Only find first few matched files using find

find

Say there may be hundreds of *.txt files in a directory. I only want to find the first three *.txt files and then exit the searching process.

How to achieve this using the find utility? I had a quick through on its man page, seemed not such a option for this.

Best Answer

You could pipe the output of find through head:

find . -name '*.txt' | head -n 3
Related Question