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

learn more… | top users | synonyms

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
3k 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
671 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
5k 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
6k 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' ...
14
votes
4answers
14k 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
351 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, ...
4
votes
2answers
13k 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
534 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 ...
2
votes
3answers
325 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
235 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 ...
4
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 ...
51
votes
6answers
6k 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
3k 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
626 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 ...
3
votes
3answers
3k 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
914 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
7k 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
18k 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
2k 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
2k 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
5k 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
487 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
211 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
1k 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, ...
3
votes
3answers
1k 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
5k 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
3k 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
2k 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 ...
7
votes
3answers
3k 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 ...
11
votes
6answers
2k 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. ...
16
votes
7answers
13k 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
1k 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 ...
11
votes
3answers
3k 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 ...