← 返回命令列表

Linux command

parallel 命令

网络

复制后可按需替换文件名、目录或参数。

常用示例

Run command on multiple inputs

parallel [gzip] ::: [*.txt]

Pipe input to parallel jobs

cat [urls.txt] | parallel [curl -O]

Run with specific number of jobs

parallel -j [4] [command] ::: [args]

Use input as argument placeholder

parallel [wget {}] ::: [url1] [url2]

Multiple input sources

parallel [convert {1} {2}] ::: [*.jpg] ::: [--resize 50%]

Run on remote hosts

parallel -S [host1,host2] [command] ::: [args]

Show progress bar

parallel --bar [command] ::: [args]

Dry run

parallel --dry-run [command] ::: [args]

说明

GNU Parallel runs jobs in parallel, utilizing multiple CPU cores. It's a more powerful replacement for xargs -P, designed for parallel processing of command-line tasks. Arguments can come from the command line (:::), files (::::), or stdin. The {} placeholder is replaced with each argument. Variants like {.} (no extension), {/} (basename), and {//} (dirname) enable flexible filename manipulation. Job control includes limiting parallelism (-j), distributing across SSH hosts (-S), and handling failures (--halt). Output can be kept in order (--keep-order) or saved to separate files (--results). For distributed computing, parallel copies necessary files to remote hosts, runs jobs, and retrieves output. This enables clusters without complex job schedulers. Progress tracking with --bar or --eta helps monitor long-running batch jobs. Logging options record what ran and what failed for later analysis.

参数

-j, --jobs _N_
Number of parallel jobs (N, N%, +N, -N).
-S, --sshlogin _HOSTS_
Remote hosts for distributed execution.
-a, --arg-file _FILE_
Read arguments from file.
:::, :::::
Argument separators (inline or from file).
{}
Replacement string for argument.
{#}
Job number.
{%}
Job slot number.
{.}
Argument without extension.
{/}
Basename of argument.
{//}
Directory of argument.
--bar
Show progress bar.
--eta
Show estimated time of arrival.
--dry-run
Show commands without executing.
--keep-order, -k
Preserve output order.
--halt _MODE_
When to halt: never, soon, now.
--results _DIR_
Save output to files in directory.
--delay _TIME_
Delay between job starts.
--retries _N_
Retry failed jobs.
--timeout _TIME_
Maximum runtime per job.

FAQ

What is the parallel command used for?

GNU Parallel runs jobs in parallel, utilizing multiple CPU cores. It's a more powerful replacement for xargs -P, designed for parallel processing of command-line tasks. Arguments can come from the command line (:::), files (::::), or stdin. The {} placeholder is replaced with each argument. Variants like {.} (no extension), {/} (basename), and {//} (dirname) enable flexible filename manipulation. Job control includes limiting parallelism (-j), distributing across SSH hosts (-S), and handling failures (--halt). Output can be kept in order (--keep-order) or saved to separate files (--results). For distributed computing, parallel copies necessary files to remote hosts, runs jobs, and retrieves output. This enables clusters without complex job schedulers. Progress tracking with --bar or --eta helps monitor long-running batch jobs. Logging options record what ran and what failed for later analysis.

How do I run a basic parallel example?

Run `parallel [gzip] ::: [*.txt]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -j, --jobs _N_ do in parallel?

Number of parallel jobs (N, N%, +N, -N).