Search code examples
shellfindgnu-parallel

Find files using gnu parallel


I understand that using the following command

find . -name "*.foo" | parallel grep bar

will be executed in 2 steps :

1) do a search for all files matching "*.foo" .

2) Then on this set of files it will do a parallel search to look for index "bar" inside the files .

But is it also possible to parallellize the first step itself ?


Solution

  • If you really think your disks are up to parallel finding and grepping, you could do this:

    printf "%s\0" */ | parallel -0 'find {} -name "*foo" | parallel grep bar'
    

    Running a full grep process for each file is also not very sensible. You should consider using GNU Parallel's -X option to let each grep process search multiple files.