How can I use the parallel command to exploit multi-core parallelism on my MacBook?

后端 未结 4 1338
孤城傲影
孤城傲影 2021-01-27 04:13

I often use the find command on Linux and macOS. I just discovered the command parallel, and I would like to combine it with find command

4条回答
  •  旧巷少年郎
    2021-01-27 04:48

    Just use background running at each first level paths separately

    In example below will create 12 subdirectories analysis

     $ for i in [A-Z]*/ ; do find "$i" -name "*.ogg" & >> logfile ; done 
    [1] 16945
    [2] 16946
    [3] 16947
    # many lines
    [1]   Done                    find "$i" -name "*.ogg"
    [2]   Done                    find "$i" -name "*.ogg"
    #many lines
    [11]   Done                    find "$i" -name "*.ogg"
    [12]   Done                    find "$i" -name "*.ogg"
     $
    

    Doing so creates many find process the system will dispatch on different cores as any other.

    Note 1: it looks a little pig way to do so but it just works..

    Note 2: the find command itself is not taking hard on cpus/cores this is 99% of use-case just useless because the find process will spend is time to wait for I/O from disks. Then using parallel or similar commands won't work*

提交回复
热议问题