Find all files with a file name starting with the specified line?

I have a directory with approximately 100,000 files in it, and I want to perform some function for all files starting with the specified line, which can correspond to tens of thousands of files.

I tried

ls mystring* 

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

 find ./mystring* -type f 

but it has the same problem.

The code should look something like this:

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

Thanks in advance, Rik

+126
bash find
Oct. 27 '10 at 15:26
source share
3 answers

use

 find . -name 'mystring*' 
+229
Oct 27 2018-10-27
source share
 ls | grep "^a" 

will provide you with all the files starting with the letter a and just work with the current directory, while the default search will expand into subdirectories.

I'm not talking about it better - just from a different angle.

+22
Jul 13 '12 at 12:15
source share

If you want to limit your search to only files, you should use -type f in your search

try also using -iname to search without -iname case

Example:

 find /path -iname 'yourstring*' -type f 



You can also perform some operations with results without a channel sign or xargs.

Example:

Search for files and show their size in megabytes

 find /path -iname 'yourstring*' -type f -exec du -sm {} \; 
+3
Aug 08 '18 at 9:30
source share



All Articles