Questions tagged [xargs]

xargs is a command on Unix and most Unix-like operating systems used to build and execute command lines from standard input.

xargs is a command on Unix and most Unix-like operating systems used to build and execute command lines from standard input. Under the Linux kernel before version 2.6.23, arbitrarily long lists of parameters could not be passed to a command, so xargs breaks the list of arguments into sublists small enough to be acceptable.

xargs often covers the same functionality as the backquote(`) feature of many shells, but is more flexible and often also safer, especially if there are blanks or special characters in the input. It is a good companion for commands that output long lists of files like find, locate and grep, but only if you use -0, since xargs without -0 deals badly with file names containing ', " and space.

1303 questions
10
votes
1 answer

Split line into 3 separate arguments using xargs

If I have the following: $ printf '%s\n' "${fa[@]}" 1 2 3 4 5 6 7 8 9 where each line is a new array element. I want to be able to split the element by space delimiter and use the result as 3 separate parameters and pipe into xargs. For example…
brucezepplin
  • 9,202
  • 26
  • 76
  • 129
10
votes
2 answers

Got exit code 123 in find + xargs grep

Here is my script eval "find \\( -type f -a \\( -name '*.h' \\) \\) -print0" | xargs -0 -n100 grep -f <(echo "stdio") echo $? Nothing is found and the exit code is 123. If I modify it a little as follows echo "stdio" >.P eval "find \\( -type f -a…
Pan Ruochen
  • 1,990
  • 6
  • 23
  • 34
10
votes
2 answers

using a user defined bash function in xargs

I have this self-defined function in my .bashrc : function ord() { printf '%d' "'$1" } How do I get this function to be used with xargs ?: cat anyFile.txt | awk '{split($0,a,""); for (i=1; i<=100; i++) print a[i]}' | xargs -i ord {} xargs: ord:…
lonestar21
  • 1,113
  • 2
  • 13
  • 23
10
votes
2 answers

xargs: String concatenation

zgrep -i XXX XXX | grep -o "RID=[0-9|A-Z]*" | uniq | cut -d "=" -f2 | xargs -0 -I string echo "RequestID="string My output is RequestID=121212112 8127127128 8129129812 But my requirement is to have the request ID prefixed before all the…
User
  • 401
  • 2
  • 8
  • 15
9
votes
7 answers

xargs and find, rm complaining about \n (newline) in filename

I am trying to delete the oldest file in a tree with a script in Debian. find /home/backups -type f \( -name \*.tgz -o -name \*.gz \) -print0 | xargs -0 ls -t | tail -1 | xargs -0 rm But I am getting an error: rm: cannot remove…
user1076412
  • 317
  • 2
  • 5
  • 12
9
votes
3 answers

Why does xargs -L yield the right format, while xargs -n doesn't?

Consider the following: $ echo index.html* | xargs -L 1 ls -l -rw-r--r-- 1 zeki zeki 17198 2011-05-03 23:18 index.html -rw-r--r-- 1 zeki zeki 17198 2011-05-03 23:20 index.html.1 -rw-r--r-- 1 zeki zeki 17198 2011-05-03 23:21…
ezequiel-garzon
  • 3,047
  • 6
  • 29
  • 33
9
votes
3 answers

Is it possible to distribute STDIN over parallel processes?

Given the following example input on STDIN: foo bar bar baz === qux bla === def zzz yyy Is it possible to split it on the delimiter (in this case '===') and feed it over stdin to a command running in parallel? So the example input above would…
Erik
  • 4,268
  • 5
  • 33
  • 49
9
votes
2 answers

How can I use adb to uninstall all 3rd party user apps?

I am trying to create a script that will retrieve and uninstall all user apps in one batch operation through adb. Does anyone know how I would be able to do this? I can currently list out all 3rd party apps through adb shell pm list packages…
Troy Greenman
  • 111
  • 1
  • 6
8
votes
4 answers

Which is faster, 'find -exec' or 'find | xargs -0'?

In my web application I render pages using PHP script, and then generate static HTML files from them. The static HTML are served to the users to speed up performance. The HTML files become stale eventually, and need to be deleted. I am debating…
yhager
  • 1,632
  • 15
  • 16
8
votes
3 answers

Alternatives to xargs -l

I want to rename a bunch of dirs from DIR to DIR.OLD. Ideally I would use the following: find . -maxdepth 1 -type d -name \"*.y\" -mtime +`expr 2 \* 365` -print0 | xargs -0 -r -I file mv file file.old But the machine I want to execute this on has…
eatloaf
  • 607
  • 1
  • 9
  • 16
8
votes
1 answer

How do I fuzzy find all files containing specific text using ripgrep and fzf and open it VSCode

I have the following command to fuzzy find files in the command line and to open the selected file in VSCode.: fzf --print0 -e | xargs -0 -r code Now I want to be able to search also file contents for a string. I am able to find the searched string…
BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96
8
votes
2 answers

How can I use -0 option to xargs when specifying the input manually?

I have ~/bashpractice$ ls dir3 dir1 I get ~/bashpractice$ xargs ls -l dir1 dir3 dir1: total 0 -rw-r--r-- 1 abc abc 0 2011-05-23 10:19 file1 -rw-r--r-- 1 abc abc 0 2011-05-23 10:19 file2 dir3: total 0 -rw-r--r-- 1 abc abc 0 2011-05-23 10:20…
Ankur Agarwal
  • 23,692
  • 41
  • 137
  • 208
8
votes
1 answer

JQ - How to define filter to remove brackets, quotes and commas from output array

I need to convert an output array to lines without brackets, quotes and commas, so that it can be used to create git clones. This is my original query curl -s http://bitbucketlocalserver:7990/rest/api/1.0/projects/PROJECT_NAME/repos?per_page=20 ^ -u…
adbdkb
  • 1,897
  • 6
  • 37
  • 66
8
votes
3 answers

Piping echo output into xargs

I'm trying to pipe a list of values through xargs. Here's a simple example: echo "Hello Hola Bonjour" | xargs -I _ echo _ Landon I would expect this to output the following: Hello Landon Hola Landon Bonjour Landon Instead, the command outputs…
LandonSchropp
  • 10,084
  • 22
  • 86
  • 149
8
votes
3 answers

Joining concurrent Python Output

I'm using something like this: find folder/ | xargs -n1 -P10 ./logger.py > collab Inside logger.py I am processing the files out outputting reformatted lines. So collab should look like {'filename' : 'file1', 'size' : 1000} {'filename' : 'file1',…
Josh K
  • 28,364
  • 20
  • 86
  • 132