xargs is a command that executes another command and generates its arguments from stdin

learn more… | top users | synonyms

1
vote
3answers
2k views

Linux: Does find | xargs grep have limitations?

I've historically performed something like: find . 2>/dev/null | xargs grep -i something_to_find 2>/dev/null If my pwd is barfoo (/foo/bar/baz/foofoo/foobar/foobaz/barfoo) it finds matches. ...
1
vote
4answers
500 views

No such file or directory error when using xargs

I have some files with .mkv extension and I want to calculate their total size using du -h. Some of the files are preceded by whitespace characters. ranveer@ranveer:~$ ls *.mkv ...
1
vote
2answers
336 views

Import sql files using xargs

I have a number of sql files to import. For a single file I use the following command: mysql -u root -p dbname < db.sql Is it possible to use xargs to bulk import all files? something like: ls ...
11
votes
8answers
716 views

Spreading stdin to parallel processes

I have a task that processes a list of files on stdin. The start-up time of the program is substantial, and the amount of time each file takes varies widely. I want to spawn a substantial number of ...
5
votes
2answers
820 views

Reformatting a large number of XML files

I'm manipulating a large number of XML files scattered throughout a nested directory structure. I tried the following (which almost works): $ find . -name "*.xml" -type f | xargs -- xmllint --format ...
4
votes
3answers
267 views

Use command grep and locate

How I can make the grep command locate certain words in the files specified by the routes found by the locate command? locate my.cnf | grep user (I want that grep command search the word "user" ...
1
vote
3answers
1k views

how to sum output of awk or other expression with xargs

Suppose i have the following bash shell script: #!/bin/bash export count=0; for i in `ls ./mydoc` ;do pdfinfo ./mydoc/$i | egrep Pages |awk {'print $2'} |xargs -+ $count ; ...
4
votes
1answer
2k views

“Argument list too long”: How do I deal with it, without changing my command?

When I run a command like ls */*/*/*/*.jpg, I get the error -bash: /bin/ls: Argument list too long I know why this happens: it is because there is a kernel limit on the amount of space for ...
4
votes
4answers
814 views

xargs and vi - “Input is not from a terminal”

I have about 10 php.ini files on my system, located all over the place, and I wanted to quickly browse through them. I tried this command: locate php.ini | xargs vi But vi warns me Input is not ...
2
votes
2answers
519 views

Inner function call with xargs parameters

I am trying to create a file occurent within my /tmp directory of each file containing a speicific string. The problem is that the call to basename {} does not seem to work. Neither this, neither ...
4
votes
2answers
330 views

Decrypt files encrypted with gpg using xargs

I have a lot of files encrypted with gpg. All files have the same password. Is it possible to use xargs to decrypt files? ls | xargs -n 1 gpg asks for the password for every file.
7
votes
4answers
2k views

How to make `xargs` ignore child's exit and keep processing further

I sometimes run long xargs jobs overnight and it is really annoying to discover in the morning that xargs died somewhere in the middle, for example because of a segmentation fault in one single ...
10
votes
3answers
4k views

Find -exec + vs find | xargs. Which one to choose?

I understand that the -exec can take a + option to mimic the behaviour of xargs. Is there any situation where you'd prefer one form over the other? I personally tend to prefer the first form, if ...
5
votes
2answers
566 views

Batch copy to multiple directories

I have about 9000 files in a directory and I want to mv them into 90 files in 100 directories by filename order, ignoring any remainder. In Copy multiple files from filename X to filename Y?, Caleb ...
4
votes
4answers
3k views

copying multiple files to multiple directories

I've a problem copying many files in different directories. Let me explain better: Let's say I have the following in a dir: $ ls file1 file2 file3 file4 file5 dir1 dir2 dir3 and I want to copy ...
4
votes
4answers
2k views

Remove numbers from filenames

I've a problem modifying the files' names in my Music/ directory. I have a list of names like these: $ ls 01 American Idiot.mp3 01 Articolo 31 - Domani Smetto.mp3 01 Bohemian rapsody.mp3 01 Eye of ...
3
votes
2answers
2k views

Why does xargs strip quotes from input?

Why does xargs strip quotes from input text? Here is a simplified example: echo "/Place/='http://www.google.com'" | xargs echo outputs /Place/=http://www.google.com Is there any way to ...
4
votes
2answers
383 views

Append line to many files

I want to add some text to over 200,000 files I am trying this find . -name *.txt -print | xargs -I % echo "hello world" >> % But nothing is happening. When i run find . -name *.txt it work ...
2
votes
3answers
3k views

How to delete files filtered out by awk

I have the following files in a directory: -rw-r--r-- 1 smsc sys 46 Apr 22 12:09 bills.50.1.3G.MO.X.20120422120453.Z -rw-r--r-- 1 smsc sys 28 Apr 22 12:15 bills.50.1.3G.MO.X.20120422120953.Z ...
3
votes
3answers
4k views

How can I pass strings with single quotes to grep?

My desired outcome is the following: to recursively search a directory looking for a given string in all found files. The following command is my usual port of call: find ./ | xargs grep -ns 'foobar' ...
10
votes
4answers
7k views

Sorting the output of “find”?

I need to be able to alphabetically sort the output of find before piping it to a command. Entering | sort | between didn't work, so what could I do? find folder1 folder2 -name "*.txt" -print0 | ...
7
votes
3answers
294 views

What's wrong with this xargs command?

Consider the output: % { echo one; echo two; echo three; } | xargs -I{} -L1 echo test-{} test-{} one test-{} two test-{} three Why doesn't {} get substituted as per the manual page (and my memory, ...
3
votes
2answers
9k views

using xargs to grep multiple patterns

I have a file that has terms I want to grep for, with each term being one line in the file. I was thinking I could do this with xargs. What I'm able to glean from examples from the man page like this ...
2
votes
2answers
371 views

xargs grep suggestion

grep -v "\<Swap" instruments.log | awk '{ idx=index($0, "MasterId="); masterId=substr($0, idx+length("MasterId=")+1); masterId=substr(masterId,1,index(masterId,"L")-3); print masterId; }' | xargs ...
1
vote
3answers
259 views

man xargs says standard input is delimited by blanks; but is it?

I'm puzzled by what actually defines an arg in xargs. The man page seems to suggest that args are delimited by blanks (I assume that means whitespace). However the following script doesn't behave as ...
4
votes
1answer
213 views

Why did using xargs fail in this case?

I tried to understand the usage of xargs and did the following experiment. ls | xargs | touch I want to refresh the files dates and directoris in the curent directory. Though it is a bit silly,for ...
3
votes
6answers
1k views

Grep a directory and return list with line numbers

I'm currently trying to learn more about bash scripting and all of that fun stuff, and I pieced together this little command: find $path | xargs grep -n $pattern | awk '{print $1}' While this DOES ...
45
votes
6answers
4k views

When is xargs needed?

The xargs command always confuses me. Is there a general rule that can help me figure out when I need it? Consider the two examples below: $ \ls | grep Cases | less prints the files that match ...
5
votes
2answers
2k views

Provide parameters to scp with xargs

When I run svn st | awk '{print $2}', I get: a.py b.py c.py Then I want to scp these files to a remote server. I have tried: svn st | awk '{print $2}' | xargs scp my_name@my_server:~/ But it ...
5
votes
2answers
517 views

Is using xargs faster than not using it?

Is this faster: find /tmp -name core -type f | xargs /bin/rm -f than doing this: find /tmp -name core -type f -exec /bin/rm -f {} \; So would using xargs increase overall speed? (I got the ...
2
votes
3answers
1k views

create md5 hash from a recursive file listing when some paths have spaces

I need to create an md5 hash of every directory and file inside of one main directory. The only thing that is keeping me from success is figuring out a way around files with a space in the path. I am ...
0
votes
2answers
725 views

Combination of ls, xargs and zcat leads to duplicate file name suffixes?

Disclaimer: Yes, finding files in a script with ls is bad, but find can't sort by modification date. Using ls and xargs with echo everything is fine: $ ls -t1 ssl-access*.gz | xargs -n 1 echo ...
11
votes
6answers
5k views

xargs with stdin/stdout redirection

I would like to run: ./a.out < x.dat > x.ans for each *.dat file in the directory A. Sure, it could be done by bash/python/whatsoever script, but I like to write sexy one-liner. All I could ...
6
votes
6answers
8k views

How to search for a word in entire content of a directory in linux

need to search for something in entire content I am trying: find . | xargs grep word I get error: xargs: unterminated quote How to achieve this?
3
votes
4answers
1k views

rename character “â” of directory name?

I'm trying to rename rename character â of directory name to be blank. For example, directory with name how-â8093-to. This is the command I use, including some other modification find . -type d | ...
7
votes
2answers
1k views

How to stop xargs from badly merging output from multiple processes?

I'm using xargs with the option --max-args=0 (alternatively -P 0). However, the output of the processes is merged into the stdout stream without regard for proper line separation. So I'll often end ...
3
votes
4answers
3k views

Passing pipeline value as parameter to xargs for use by eval echo

I have a text file that I'm using as a template, it looks like this: Hostname : $HOSTNAME Host Address : $HOSTADDRESS My bash script sets two variables, HOSTNAME and HOSTADDRESS, reads the ...
2
votes
1answer
417 views

why isn't xargs parsing my input correctly?

Ive been trying to write a shell script that will interface with cmus and then notify me of the track info using notify-send. Right now it is not working mainly because xargs does not seem to pass 2 ...
3
votes
3answers
176 views

Use find to execute series of commands

I want to examine a directory and execute a command for each matching folder. The following find correctly returns the list I'm looking for. find . -maxdepth 1 -name "*.bitbucket" For each item ...
14
votes
2answers
745 views

gnu find and masking the {} for some shells - which?

The man page for gnu find states: -exec command ; [...] The string `{}' is replaced by the current file name being processed everywhere it occurs in the arguments to the command, ...
2
votes
3answers
975 views

untar a directory of *.tgz files using a wildcard

I've got a directory that looks like $ ls Broad_hapmap3_r2_Affy6_cels_excluded.tgz DINGO.tgz GIGAS.tgz index.html IONIC.tgz passing_cels_sample_map.txt ...
4
votes
3answers
4k views

Pass xargs argument as a string to another command with '>'?

Suppose I have a bunch of files in /tmp/. I do find . -type f | xargs -iFILES And I want to do a md5sum in each file, outputting to a file with the same name, but with .md5 extension. find . ...
3
votes
1answer
2k views

Remove files, which provided by pipe

I have this command chain: find . -print | grep php | xargs grep 'eval' -sl | xargs wc -l | grep ' [1-2][0-9] ' This provide me this output: 14 ./includes/js/calendar/lang/vgju.php 18 ...
4
votes
4answers
1k views

Xargs and rm with a *

I am trying to execute the following command ls -d a* | xargs -i sudo rm -rf {}/* The problem is that when I add the /* part the command does not work. I want to remove the directory contents (not ...
6
votes
3answers
2k views

How to open multiple files from `find` output?

I know I can open multiple files found in a dir like so: find -name *.foo -xargs <command> {} \; This works, but when trying to open a bunch of textfiles in gedit at the same time, it opens ...
10
votes
6answers
1k views

Why does xargs cause apt-get to abort?

I'm trying to remove a list of packages from a file. I'm using the following command: cat packages | xargs sudo apt-get remove packages is my file containing a list of packages I want to remove. ...
14
votes
7answers
9k views

Using xargs with input from a file

Say I have a file with the following bob john sue Now these directly corrospond to (in this case) URL pattern such as http://example.com/persons/bob.tar, john.tar, sue.tar. I would like to take ...
5
votes
4answers
916 views

recursively chmod

I was trying to chmod folders and files with: find . -type d -exec chmod 755 {} \; find . -type f -exec chmod 644 {} \; But I was wondering: How to do it in one line using find and excluding the ...
10
votes
3answers
2k views

bash find xargs grep only single occurence

Maybe it's a bit strange - and maybe there are other tools to do this but, well.. I am using the following classic bash command to find all files which contain some string: find . -type f | xargs ...