XE(1) | General Commands Manual | XE(1) |
xe
— execute a
command for every argument
xe |
[-0FLRnqv ] [-I
replace-arg] [-N
maxargs] [-j
maxjobs]
command ... |
xe |
[flags ...] -p
pattern command ...
[+ pattern
command ...]... |
xe |
[flags ...] -f
argfile
command ... |
xe |
[flags ...] -s
shellscript |
xe |
[flags ...] -a
command ... --
args ... |
xe |
[flags ...] -A
argsep command ...
argsep args ... |
The xe
utility constructs command lines
from specified arguments, combining some of the best features of
xargs(1) and apply(1).
xe
means “execute for every
...”.
xe
supports different methods to specify
arguments to commands:
In this mode, no shell is involved and replace-arg must appear as a word on its own, i.e. ‘foo {} bar’ will work, but ‘foo{} bar’ will not, where {} is the default value for replace-arg.
If no argument is specified, the default is
‘printf %s\n
’.
-f
argfileThis does not close the standard input for execution, it is passed to the forked process.
-s
shellscriptsh -c
. In the script, the specified
arguments can be accessed using $1, $2, ...
For example:
echo 'a\nb' | xe -N2 -s 'echo $2
$1'
-a
command ... --
args ...--
is passed as
args to command.-A
argsep command ...
argsep args ...-a
, but the custom argument separator
argsep is used to distinguish between
command and its args.The options are as follows:
-0
-F
-L
-vv
,
also prefix each line with the number of the job (see
ENVIRONMENT) in such a manner that
the output can be piped to ‘sort
-snk1
’ to group it.-R
xe
never executes a command when
no arguments are specified.-n
-q
-v
-p
**
’) are
matched against the basenames only.
Multiple runs of patterns and commands are separated by
‘+
’. Only the first matching
percent rule is executed; in case no pattern matches, no command is
run.
-I
replace-arg{}
) in the resulting command with the argument(s).
Pass an empty replace-arg to disable the replace
function. Contrary to xargs(1) this will expand into
multiple arguments when needed.-N
maxargs-N0
will pass as many arguments as
possible.-j
maxjobs-j0
will run as many processes as there are CPU
cores running. If maxjobs ends with an
‘x
’, it is regarded as a multiplier
of the number of running CPU cores (rounded down, but using at least one
core).The percent rules of xe
are similar to the
globs of sh(1) or fnmatch(3):
‘?
’ matches a single character that is
not ‘/
’.
‘/
’ matches one or multiple
‘/
’ in the string.
‘*
’ matches zero or more characters,
but never ‘/
’.
‘**
’ matches zero or more characters,
including ‘/
’. Note that all of these
also match leading dots in file names.
‘{
a,b,c}’
matches either a, b or
c.
‘[
abc]’ matches
one of the characters abc (but never
‘/
’).
‘[
!abc]’ matches
all characters but abc. Alternatively,
‘[
^abc]’ can be
used too.
‘[
a-c]’
matches any character in the range between a and
c inclusive. In character ranges, characters can be
escaped using a backslash.
In the pattern, a single occurrence of
‘%
’ matches one or more characters,
and replaces the first occurrence of
‘%
’ with the matched string in the
remaining arguments, which are then used as the command to be executed.
The environment variable ITER
is passed to
the child process and incremented on each command execution.
xe
follows the convention of GNU and
OpenBSD xargs:
Additionally, 122 is returned when -R
was
passed and the command was never executed.
Compress all .c files in the current directory, using all CPU cores:
xe -a -j0 gzip -- *.c
lr -U -t 'size == 0' | xe -N0
rm
xe -a -j0 -s 'ffmpeg -i
"${1}" "${1%.mp3}.ogg"' -- *.mp3
xe -a -j0 -p %.mp3 ffmpeg -i %.mp3
%.ogg -- *.mp3
xe -ap -j0 -vvq '%.{m4a,ogg,opus}'
ffmpeg -y -i {} out/%.mp3 -- *
Leah Neukirchen <leah@vuxu.org>
xe
is in the public domain.
To the extent possible under law, the creator of this work has waived all copyright and related or neighboring rights to this work.
November 3, 2017 | Debian |