Find all files with a filename beginning with a specified string?

RikSaunderson picture RikSaunderson · Oct 27, 2010 · Viewed 198.4k times · Source

I have a directory with roughly 100000 files in it, and I want to perform some function on all files beginning with a specified string, which may match tens of thousands of files.

I have tried

ls mystring*

but this returns with the bash error 'Too many arguments'. My next plan was to use

find ./mystring* -type f

but this has the same issue.

The code needs to look something like

for FILE in `find ./mystring* -type f`
do
    #Some function on the file
done

Answer

Sergio Tulentsev picture Sergio Tulentsev · Oct 27, 2010

Use find with a wildcard:

find . -name 'mystring*'