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: 
I suggest you make use of parallel processing in xargs command to speed up your entire process. Use a command like this:

```
find "$DIR" -name "$USERINPUT" -print0 | xargs -0 -P10 zip -1 SearchResult -@

```

Above command will make xargs run 10 parallel sub-processes.

Please record timing of above command like this:

```
time find "$DIR" -name "$USERINPUT" -print0 | xargs -0 -P10 zip -1 SearchResult -@

```

and see if this makes any performance improvements.
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.