Question: I have a bash script that zips up filenames based on user input. It is working fine albeit slowly since I have, at times, to parse up to 50K files.

```
find "$DIR" -name "$USERINPUT" -print | /usr/bin/zip -1 SearchResult -@

```

The @ sign here means that zip will be accepting file names from STDIN. Is there a way to make it go faster?

I am thinking of creating a cron job to update the locate database every night but I am not root so I don't even if it is worth it.

Any suggestions welcome.

Answer: 
As Mattias Ahnberg pointed out, this use of `find` will generate the entire list of matching files before `zip` gets invoked. If you're doing this over 50,000 files, that will take some time. Perhaps a more suitable approach would be to use `find`'s `-exec <cmd> {} \;` feature:

```
find "$DIR" -name "$USERINPUT" -exec /usr/bin/zip -1 {} \;

```

This way, find invokes zip itself on each matching file. You should achieve the same end result as your original version, but if the sheer number of files is your bottleneck (which, if the files are all small, is most likely), this will kick off running zip as soon as it starts finding matches, rather than when all matches have been found.

NB: I recommend reading the man page for find for details of this option. Note that the semi-colon must be escaped to prevent your shell interpreting it rather than passing it to find.
Sounds like you're trawling through the filesystem running a find for each of the 50,000 files.

Why not do **one** run of find, to log names of all files in the filesystem, and then pluck the locations of them straight from this log file ? 

Alternatively, break the work down into seperate jobs, particularly if you have multiple filesystems and multiple CPUs. No need to be single-threaded in your approach.