Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Run tasks in parallel with xargs

Answer:

xargs provided a very simple to parallel tasks, e.g. setting P=3 means run 3 processes in parallel

seq 1 10 | xargs -n 1 -P 3 echo

Result:

1
2
3
4
5
7
6
9
8
10

Try to run the command several times, you might notice that number's order might be changed.

Why? Since they are running in parallel and some numbers finished first and some later!

  1. Executing jobs in parallel using GNU parallel
  2. xargs when the filename contains a newline
  3. How to adjust the argument position in xargs?
  4. Validate the syntax of PHP files in a directory
  5. Parallel command line downloader in Linux: Axel

One Response to “Run tasks in parallel with xargs”

  1. If you use GNU Parallel http://www.gnu.org/software/parallel/ you can run the jobs in parallel but make sure the output is kept the same way as input:

    seq 1 10 | parallel -k echo

    Watch the intro video to GNU Parallel: http://www.youtube.com/watch?v=OpaiGYxkSuQ

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>