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
19
votes
1 answer

Find command with regex for multiple file extension

I was wondering if this is possible in find command. I am trying to find all the specific files with the following extensions then it will be SED after. Here's my current command script: find . -regex '.*\.(sh|ini|conf|vhost|xml|php)$' | xargs sed…
user3282191
  • 203
  • 1
  • 2
  • 7
18
votes
4 answers

xargs to execute a string - what am I doing wrong?

I'm trying to rename all files in current directory such that upper case name is converted to lower. I'm trying to do it like this: ls -1|gawk '{print "`mv "$0" "tolower($0)"`"}'|xargs -i -t eval {} I have two files in the directory, Y and YY -t…
Joe Watkins
  • 1,593
  • 4
  • 15
  • 25
18
votes
4 answers

Unix - "xargs" - output "in the middle" (not at the end!)

example use of xargs application in Unix can be something like this: ls | xargs echo which is the same as (let's say I have someFile and someDir/ in the working directory): echo someFile someDir so xargs take its input and place it at the end of…
Petike
17
votes
3 answers

xargs - if condition and echo {}

I have some files that contain a particular strings. What I want to do is, search a location for the file; if the file exists grep for the pattern; if true, do something. find -iname file.xxx| xargs -I {} if grep -Fq "string" {} ; then echo {} ;…
Population Xplosive
  • 581
  • 2
  • 8
  • 18
16
votes
5 answers

xargs with multiple commands

In the current directory, I'd like to print the filename and contents in it. I can print filenames or contents separately by find . | grep "file_for_print" | xargs echo find . | grep "file_for_print" | xargs cat but what I want is printing them…
user987654
  • 5,461
  • 5
  • 23
  • 26
15
votes
1 answer

what is the difference between -L and -n in xargs

Per xargs --help: -L, --max-lines=MAX-LINES use at most MAX-LINES non-blank input lines per command line -n, --max-args=MAX-ARGS use at most MAX-ARGS arguments per command line It is very confusing. Is there any difference between -L…
camino
  • 10,085
  • 20
  • 64
  • 115
15
votes
5 answers

Sending the command(s) spawned by xargs to background

I want to know how I can send the command(s) spawned by xargs to background. For example, consider find . -type f -mtime +7 | tee compressedP.list | xargs compress I tried find . -type f -mtime +7 | tee compressedP.list | xargs -i{} compress {}…
PoorLuzer
  • 24,466
  • 7
  • 31
  • 35
15
votes
4 answers

Ignore empty results for xargs in Mac OS X

The code for my website uses this piece of code for automatic deployment on the server (Ubuntu). cmd = 'cd ' + checkout_dir + ' && ' + svn_command + " st | awk '{print $2}' | grep -v ^deploy | tac | xargs -r" + svn_command + " revert -R && " +…
Anubhav Agarwal
  • 1,982
  • 5
  • 28
  • 40
15
votes
3 answers

bash: xargs passing variable

How can a global script variable be passed to the command of xargs? I tried it this way: TEST=hallo2 echo "hallo" | xargs sh -c 'echo passed=$1 test=$TEST' sh Output: passed=hallo test= I know I could use the {} token but I need to do it this…
arminb
  • 2,036
  • 3
  • 24
  • 43
15
votes
6 answers

'find' with 'xargs' and 'tar'

I have the following I want to do: find . -maxdepth 6 \( -name \*.tar.gz -o -name bediskmodel -o -name src -o -name ciao -o -name heasoft -o -name firefly -o -name starlink -o -name Chandra \) -prune -o -print | tar cvf somefile.tar…
zinkeldonk
  • 151
  • 1
  • 1
  • 5
14
votes
6 answers

xargs with export is not working

I have a file which looks as below. HOST=localhost PORT=8080 I want to export the above into environment. I am executing the following command to export the variables in file to environment. cat | xargs export I am getting the following…
kishore
  • 1,658
  • 7
  • 24
  • 33
14
votes
4 answers

Change sed line separator to NUL to act as "xargs -0" prefilter?

I'm running a command line like this: filename_listing_command | xargs -0 action_command Where filename_listing_command uses null bytes to separate the files -- this is what xargs -0 wants to consume. Problem is that I want to filter out some of…
bstpierre
  • 30,042
  • 15
  • 70
  • 103
14
votes
3 answers

How can I move many files without having Argument list too long?

I am trying to move about 700,000 .jpg files from one directory to another in my Ubuntu server. I tried the following: xargs mv * -t /var/www/html/ and echo (*.jpg|*.png|*.bmp) | xargs mv -t /var/www/html/ and echo (*.jpg) | xargs mv -t…
Awah Hammad
  • 165
  • 1
  • 1
  • 9
14
votes
4 answers

pipe each line of a file to a command

I have a text file which each line is a one word coded base64 separely. Now I want to decode it. I'm trying to use base64 command line, but I'm getting all the words in only one line, I want one per line. For example, my file…
tpcordeiro
  • 441
  • 1
  • 6
  • 13
13
votes
1 answer

linux command xargs: maximum size of the arguments passed by it?

It seems that xargs doesn't pass all the arguments at once, in says in the manual that xargs executes the command (default is /bin/echo) one or more times, I heard that the reason for this is that xargs chops the passed in arguments into groups and…
user685275
  • 2,097
  • 8
  • 26
  • 32