LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

xe

Simple xargs and apply replacement

TLDR

Run command for each line of stdin
$ cat [list.txt] | xe [command]
copy
Use {} as placeholder for the argument
$ cat [list.txt] | xe [command] {}
copy
Parallel execution with N jobs
$ cat [urls.txt] | xe -j [4] curl {}
copy
Pass arguments directly after --
$ xe -a -- mv {} {}.bak -- [file1] [file2]
copy
Null-separated input (for filenames with spaces)
$ find . -print0 | xe -0 echo {}
copy
Pass up to N arguments per command
$ xe -N [10] rm -- [*.txt]
copy
Dry-run: print commands without executing
$ cat list.txt | xe -n [command] {}
copy

SYNOPSIS

xe [-0FLnqvR] [-I replace-arg] [-N maxargs] [-j maxjobs] [-f argfile] [-s shellscript] [-a] [command [_args...]]

DESCRIPTION

xe is a tool for constructing command lines from file listings or arguments, combining the best features of xargs(1) and apply(1). By default it runs the given command once per input line, substituting {} with the argument, making common use cases simpler than xargs.Unlike xargs, xe has sane defaults: it is equivalent to `xargs -d'\n' -I{} -n1 -r`. Arguments can be read from stdin (default), from a file with -f, or directly from the command line after -a.xe supports parallel execution with -j, make-style percent rule matching with -p, and can invoke a shell script per argument with -s.

PARAMETERS

-0

Input arguments are separated by NUL bytes instead of newlines. Useful with `find -print0`.
-a
Take arguments from the command line (after the command, separated by --) instead of stdin.
-A argsep
Use a custom argument separator instead of -- (implies -a).
-f argfile
Read arguments from argfile instead of stdin.
-F
Fatal: stop and exit when a command execution fails.
-I replace-arg
Set the replacement string (default: {}).
-j maxjobs
Run up to maxjobs processes concurrently.
-L
Line-buffered output so lines from concurrent jobs do not interleave.
-N maxargs
Pass up to maxargs arguments to each command invocation (default: 1).
-n
Dry-run: print the commands that would be executed without running them.
-p
Make-style percent rule matching for pattern-dispatched commands.
-q
Quiet: redirect stdout/stderr of commands to /dev/null.
-R
Return exit status 122 when no arguments are supplied (instead of 0).
-s shellscript
Execute shellscript via the shell; arguments are available as $1, $2, etc.
-v
Verbose: print commands to stderr before running them.

INSTALL

sudo apt install xe
copy
brew install xe
copy
nix profile install nixpkgs#xe
copy

CAVEATS

xe is distinct from the XenServer xe CLI and from xargs despite similar goals. If xargs compatibility is required, flags and behavior may differ (for example xe uses {} as placeholder by default and always runs one command per argument unless -N is given).

HISTORY

xe was written by Leah Neukirchen as a modernized replacement for xargs(1) and apply(1) with saner defaults and a cleaner interface. It is distributed as a small, portable C program.

SEE ALSO

xargs(1), parallel(1), find(1)

Copied to clipboard
Kai