Command referencexargs
xargs command (Linux / bash / sh / zsh)
What it does
Build and run command invocations from standard input. When people search for the xargs command linux examples, they usually want xargs's everyday flags, safe examples, and how it differs from related tools. Below you'll find syntax, options, and copyable examples for Bash/sh/zsh.
Build and run command invocations from standard input.
Syntax
xargs [OPTION]... [COMMAND [ARG...]]
Common options
| Flag / option | Meaning |
|---|---|
| -0 | Read NUL-delimited items. |
| -n N | Use at most N input items per invocation. |
| -P N | Run up to N processes in parallel. |
| -I TOKEN | Replace a token with each input item. |
Practical examples
Safe file removal
find . -name '*.tmp' -print0 | xargs -0 rm
Handles filenames containing whitespace.
Batch arguments
printf '%s ' a b c | xargs -n 2 echo
Runs echo with batches of two items.
Parallel checks
printf '%s ' host1 host2 | xargs -n 1 -P 2 ping -c 1
Checks two hosts concurrently.
Common mistakes
- Using newline-delimited input for arbitrary filenames instead of `-print0` and `-0`.
- Running a destructive command without first printing and reviewing generated invocations.
Related commands
- findWalk directory trees and select entries using tests and actions.
- teeCopy standard input to standard output and one or more files.
- grepSearch text for lines matching a pattern.
- Where-ObjectFilter pipeline objects by property values or a script block predicate.
- catConcatenate files and write their contents to standard output.
- Get-ContentRead file content or provider data as a stream of objects.
- echoWrite arguments and shell-expanded values to standard output.
- echoDisplay text or control command echoing in a batch script.
FAQ
What does xargs do in Linux?
Build and run command invocations from standard input.
How do I use xargs from the terminal?
Start with `xargs [OPTION]... [COMMAND [ARG...]]`, then choose only the options needed for the task.
What is a practical xargs example?
Try `find . -name '*.tmp' -print0 | xargs -0 rm` — Handles filenames containing whitespace.
Can I use xargs in a shell script?
Yes. xargs works in Bash, sh, and Zsh, but scripts should handle quoting, errors, and command output explicitly.
Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.