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
58
votes
4 answers

GNU parallel not working at all

I have been trying to use GNU parallel for some time, but I have never been able to get it to function at all! For example, running (in a non-empty directory!): ls | parallel echo # Outputs single new line ls | parallel echo echo echo #…
WaelJ
  • 2,942
  • 4
  • 22
  • 28
57
votes
6 answers

Is there a grep equivalent for find's -print0 and xargs's -0 switches?

I often want to write commands like this (in zsh, if it's relevant): find | \ grep stringinfilenamesIwant | \ grep -v stringinfilesnamesIdont | \ xargs dosomecommand (or more complex combinations of greps) In recent…
Andrew Ferrier
  • 16,664
  • 13
  • 47
  • 76
51
votes
5 answers

Getting error "xargs unterminated quote" when tried to print the number of lines in terminal

I want to get the number of lines in my application. I am using this code: find . "(" -name "*.m" -or -name "*.h" ")" -print | xargs wc -l It is working fine in other applications but for one of my applications it is giving the error "xargs…
Lena
  • 1,400
  • 3
  • 14
  • 20
50
votes
2 answers

How to stop xargs on first error?

I have an pages.txt file with 100 URLs inside. I want to check them one by one and fail on the first problem. This is what I'm doing: cat pages.txt | xargs -n 1 curl --silent \ --output /dev/null --write-out '%{url_effective}: %{http_code}\n';…
yegor256
  • 102,010
  • 123
  • 446
  • 597
49
votes
4 answers

ls: terminated by signal 13 when using xargs

I'm using the following command to delete four largest size files in a folder: find "/var/www/site1/" -maxdepth 1 -type f | xargs ls -1S | head -n 4 | xargs -d '\n' rm -f It works fine, but from time to time throws broken pipe error: xargs: ls:…
xfloys2112
  • 605
  • 1
  • 5
  • 13
48
votes
10 answers

How can I pass all arguments with xargs in middle of command in linux

I want to pass all the files as a single argument on Linux but I am not able to do that. This is working ls | sort -n | xargs -i pdftk {} cat output combinewd2.pdf This passes a single argument per command, but I want all in one command.
user2027303
  • 609
  • 2
  • 7
  • 8
47
votes
6 answers

When to use xargs when piping?

I am new to bash and I am trying to understand the use of xargs, which is still not clear for me. For example: history | grep ls Here I am searching for the command ls in my history. In this command, I did not use xargs and it worked fine. find…
Sara Hamad
  • 645
  • 1
  • 6
  • 12
46
votes
11 answers

how to output file names surrounded with quotes in SINGLE line?

I would like to output the list of items in a folder in the folowing way: "filename1" "filename2" "file name with spaces" "foldername" "folder name with spaces" In other words, item names must be in a single line, surrounded with quotes (single or…
Ana
  • 463
  • 1
  • 4
  • 4
45
votes
7 answers

Is there a way to uninstall multiple packages with pip?

I am attempting to remove all of the installed "pyobjc-framework"-prefixed packages. I have tried the following: % pip freeze | grep pyobjc-framework | xargs pip uninstall but this barfs because each pip uninstall requires confirmation (perhaps a…
wh1tney
  • 1,157
  • 1
  • 9
  • 16
44
votes
6 answers

Using grep to search for hex strings in a file

Does anyone know how to get grep, or similar tool, to retrieve offsets of hex strings in a file? I have a bunch of hexdumps (from GDB) that I need to check for strings and then run again and check if the value has changed. I have tried hexdump and…
user650649
  • 495
  • 1
  • 5
  • 10
44
votes
4 answers

xargs split at newlines not spaces

here is my problem in short $ echo 'for i in $@; do echo arg: $i; done; echo DONE' > /tmp/test.sh $ echo "ac\nbc\ncc\n" | xargs bash /tmp/test.sh arg: ac arg: bc arg: cc DONE Which is what i expect, but $ echo "ac s\nbc s\ncc s\n" | xargs -d \n…
fakedrake
  • 6,528
  • 8
  • 41
  • 64
42
votes
7 answers

Is it possible to pipe the results of FIND to a COPY command CP?

Is it possible to pipe the results of find to a COPY command cp? Like this: find . -iname "*.SomeExt" | cp Destination Directory Seeking, I always find this kind of formula such as from this post: find . -name "*.pdf" -type f -exec cp {}…
Paul
  • 2,620
  • 2
  • 17
  • 27
41
votes
10 answers

Batch renaming files in command line and Xargs

So, I have the following structure: . .. a.png b.png c.png I ran a command to resize them ls | xargs -I xx convert xx -resize xx.jpg Now my dir looks like this . .. a.png.jpg a.png b.png.jpg b.png c.png.jpg c.png The firs question is, how do i…
Cripto
  • 3,581
  • 7
  • 41
  • 65
40
votes
5 answers

Understanding the UNIX command xargs

I'm pretty much confused on this. Need some clarifications. Example 1 : pgrep string | xargs ps Example 2 : find . | xargs grep whatever From Example 1, I gather it's this way: Search for a "string" which is part of name of running process and…
halluc1nati0n
  • 893
  • 2
  • 13
  • 18
36
votes
9 answers

How can I use aliased commands with xargs?

I have the following alias in my .aliases: alias gi grep -i and I want to look for foo case-insensitively in all the files that have the string bar in their name: find -name \*bar\* | xargs gi foo This is what I get: xargs: gi: No such file or…
Nathan Fellman
  • 122,701
  • 101
  • 260
  • 319
1
2
3
86 87