The xargs tag has no wiki summary.
3
votes
3answers
116 views
Concatenating thousands of files: > vs >>
I found two seemingly contradictory answers on StackOverflow to the following questions:
Concatenating Thousands of Text Files Across Hundreds of Directories (while keeping some structure)
How do I ...
6
votes
1answer
55 views
How to do `head` and `tail` on null-delimited input in bash?
find command can output names of files as a null-delimited strings (if -print0 is provided), and xargs can consume them with -0 option turned on. But in between, it's hard to manipulate that ...
1
vote
3answers
72 views
find . .[^.]* -type f -print0 | xargs -0 sudo chmod 664; does not work
I am using this command to set permissions for files recursively
clime@vm6879 /srv/www-php/steeltrading $ find . .[^.]* -type f -print0 | xargs -0 sudo chmod 664
But after executing that command ...
1
vote
1answer
67 views
Wrong behavior of xargs
I was trying to solve this issue using find + xargs but I stuck with another issue
I am try to increasing a count using ((a++)) but not working . I have tried couple of combination of counting a ...
0
votes
1answer
144 views
Can someone provide an xargs example piping mysql query data into another command?
Can someone provide an example for the command xargs? I want to do a mysql query to return the ID field of a column then feed that result into xargs into another command say mysql query delete. How ...
2
votes
3answers
105 views
`solaris + xargs command for solaris
the command
find /tmp -name 'core*' -type f -print0 | xargs -0
works fine on Linux,
but xargs -0 option is not legal on Solaris
what is the equivalent option ( xargs? ) for Solaris 10
second ...
2
votes
3answers
79 views
How to copy a list of files and adjust destination filenames on the fly?
When I don't need to adjust destination filenames I can do something like this:
$ find -type f -name '*.pat' -print0 | xargs -O cp -t /path/to/dest
It is safe because the filenames may even ...
4
votes
2answers
142 views
Why doesn't this xargs command work?
I wanted to delete all .sh extensions so did this:
ls *.sh | xargs -I {} mv {} `basename {} .sh`
However it doesn't work, it behaves like basename returns unchanged file name.
Why is it behaving ...
3
votes
2answers
189 views
Get the complement of the result of an ls command
Let's say I have a directory with multiple files, all of which are either binary files (files with no declared extensions) and source files (.c extension). I do this:
$ ls
and get:
README.md ...
2
votes
3answers
133 views
Howto recursively create PDF thumnbails on linux command line
I am able to use ImageMagick to create a thumbnail of the first page of a PDF using:
convert -thumbnail x80 95.pdf[0] thumb_95.png
This works fine and generates a thumb_95.png file.
I have tried ...
1
vote
1answer
73 views
Speeding a find rm command with test through parallelization
I want to recursively delete all files in directories and subdirectories with number of lines less than 10, and am currently using the following command
find . -type f -name "*.txt" | while read; do ...
8
votes
2answers
104 views
Piping nothing to xargs
I have a script that may in some circumstances have nothing on stdout. At the end of the script, I pass the lines I have to another command using xargs. My problem is, when there is nothing on stdout, ...
3
votes
2answers
262 views
How to delete commands in history matching a given string?
I need to delete all commands in my history matching a string. I've tried:
$ history | grep searchstring | cut -d" " -f2 | history -d
-bash: history: -d: option requires an argument
$ history | grep ...
2
votes
1answer
174 views
xargs : using same argument in multiple commands
Am trying to write a one-liner that can probe the output of df -h and alert when one of the partitions is out [or almost] of space. It's the part using xargs that kicking me in the ass now...
echo 95 ...
6
votes
4answers
299 views
Find images by size: find / file / awk
I've been trying to find png image files a certain height (over 500px). I know that file will return image dimensions. Example:
$ file TestImg1a.png
TestImg1a.png: PNG image data, 764 x 200, ...
1
vote
3answers
801 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
275 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
111 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 ...
6
votes
4answers
377 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 ...
4
votes
2answers
373 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
183 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
553 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
965 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
327 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
279 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
196 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.
5
votes
3answers
1k 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 ...
6
votes
3answers
1k 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
442 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
902 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 ...
3
votes
4answers
835 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 ...
2
votes
2answers
936 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
196 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
1k 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
2k 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'
...
3
votes
4answers
2k 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
236 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, ...
2
votes
2answers
5k 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
237 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
175 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
196 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
738 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 ...
38
votes
6answers
3k 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 ...
2
votes
2answers
840 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
388 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
628 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
470 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
...
10
votes
6answers
3k 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 ...
4
votes
4answers
2k 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? Thanks.
3
votes
4answers
984 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 | ...

