Questions tagged [xargs]

Execute a command, passing constructed argument list(s). The arguments are typically a long list of filenames (generated by ls or find) that are passed to xargs via a pipe.

Execute a command, passing constructed argument list(s). The arguments are typically a long list of filenames (generated by ls or find) that are passed to xargs via a pipe.

manpage

45 questions
66
votes
6 answers

Newline-separated xargs

Is it possible to make xargs use only newline as separator? (in bash on Linux and OS X if that matters) I know -0 can be used, but it's PITA as not every command supports NUL-delimited output.
Kornel
  • 1,075
  • 1
  • 11
  • 16
39
votes
6 answers

prevent xargs from quitting on error

According to the man page, xargs will quit if one of the execution lines exits with an error of 255: If any invocation of the command exits with a status of 255, xargs will stop immediately without reading any further input. An error message is…
JDS
  • 2,508
  • 4
  • 29
  • 48
32
votes
3 answers

How can I handle spaces in file names when using xargs on find results?

One of my common practices is to perform greps on all files of a certain type, e.g., find all the HTML files that have the word "rumpus" in them. To do it, I use find /path/to -name "*.html" | xargs grep -l "rumpus" Occasionally, find will return a…
abeger
  • 461
  • 1
  • 4
  • 6
16
votes
2 answers

Redirect to stdin instead of argument when using xargs

for exmaple, using the command cat foo.txt | xargs -I{} -n 1 -P 1 sh -c "echo {} | echo" The foo.txt contains two lines foo bar The above command print nothing.
Ryan
  • 5,341
  • 21
  • 71
  • 87
14
votes
3 answers

Tracking progress with xargs

I'm using xargs to execute a command on a set of input parameters something like this: cat | xargs -n 1 -P 5 The input file is really long and take a long time to run. So I'm just waiting for the command prompt to show up. Is…
Utkarsh Sinha
  • 241
  • 2
  • 5
11
votes
5 answers

Apply multiple .patch files

I have a directory with .patch files, generated using diff. I would like to apply all those patches using patch -p1 to another directory. But patch takes only one file, unless I cat. What would the command be to apply multiple files using xargs or a…
styts
  • 235
  • 1
  • 2
  • 6
7
votes
3 answers

How can I download multiple files stored in a text file with curl and xargs?

How can I download multiple files stored in a text file with curl and xargs? This is my last trial: cat listfile.txt | xargs curl -O first file works well, but other files are just output to stdout.
Eonil
  • 9,689
  • 15
  • 34
  • 53
5
votes
1 answer

Finding all Public IPv4 and IPv6 addresses in a UNIX shell script

For monitoring purposes, I'd like to find out all public IPv4 and IPv6 addresses of a mobile-warrior UNIX box. Note that this is different from Finding the Public IP address in a shell script because of the following extra requirements: the mobile…
cnst
  • 12,948
  • 7
  • 51
  • 75
4
votes
2 answers

Feeding Multiline STDIN Input to Command

I have a script that outputs git repository SSH URLs, like this: git@example.com:namespace/project.git git@example.com:another_namespace/some_other_project.git I want to run the command git clone (or other commands) for each line. I tried piping…
Robert Dundon
  • 223
  • 2
  • 6
4
votes
2 answers

xargs "too long argument list"

I want to do something like this: cat 5.txt | xargs -0 openssl prime but xargs is saying that argument list is too long Edit: cat 3.txt | xargs -n 1 openssl prime | wc -l works, thanks
asfsafsfsaf
  • 41
  • 1
  • 3
4
votes
3 answers

xargs --max-proc split output per proc?

I recently discovered the xargs --max-procs feature. How can split the output of the command by proc? Should I just create a mycommand --logfile $LOGFILE, or can I do it from xargs itself? An example (for womble): Suppose I have script…
Gregg Lind
  • 159
  • 6
3
votes
2 answers

What does rm {} + do?

As in find -L /etc/ssl/certs/ -type l -exec rm {} + So it finds all broken symlinks and deletes them. But how exactly do I interpret the {} + part?
yanchenko
  • 259
  • 1
  • 6
  • 13
2
votes
1 answer

Dropping the -print0 and -0 flags from find and xargs

Almost 10 years ago, I asked this question use SED recursively in linux? and got this useful command find . -type f -print0 | xargs -0 sed -i 's/regex_search_term/replace_term/g' I decided to learn more about the find, xargs and sed statement. On…
John
  • 7,153
  • 22
  • 61
  • 86
2
votes
3 answers

How to process a space delimited environment variable with xargs

I am trying to execute a long running process multiple times in parallel. The parameter for each execution of the process is stored in a space separated environment variable. Here is a contrived example of what I am trying to execute: $ echo -e 1…
gordo911
  • 23
  • 1
  • 3
2
votes
1 answer

Xargs and bash script

The script works fine when executed manually but I recived the folloing error while it's run as a cron job: xargs: postsuper: No such file or directory #!/bin/bash mailgueue=$(mailq | awk '/MAILER-DAEMON/ { print $1 }' | wc -l) if [ $mailgueue -ge…
HTF
  • 3,050
  • 14
  • 49
  • 78
1
2 3