xargs

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 return the process-ids of all the matches to 'xargs ps' -> which just appends ps to the...

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 {} & .. and as unexpected, it seems to send xargs to the background instead? How do I m...

moving files recurisively on linux

find ./dir -type f -iname "*.t[argz]*[bz2]" -print | xargs mv --target-directory=dir seems to fail on file that has spaces in the name. how to improve it? or alternative? thanks for answer below: my mv doesn't support --null or -0, I'm using cygwin: $ mv --help Usage: mv [OPTION]... [-T] SOURCE DEST or: mv [OPTION]... SOURCE... DIR...

Wget with input-file and output-document

I have a list of URLs which I would like to feed into wget using --input-file. However I can't work out how to control the --output-document value at the same time, which is simple if you issue the commands one by one. I would like to save each document as the MD5 of its URL. cat url-list.txt | xargs -P 4 wget And xargs is there bec...

What is the powershell equivalent to this bash command?

I'm trying to create a cli command to have TFS check out all files that have a particular string in them. I primarily use cygwin but the tf command has trouble resolving the path when run within the cygwin environment. I figure powershell should be able to do the same thing, but I'm not sure what the equivalent commands to grep and xar...

Best output format for Xargs

I'm writing a simple program to run through a bunch of files in various directories on my system. It basically involves opening them up and checking for valid XML. One of the options of this program is to list bad xml files. This leads me to my question. What the best output to format this for use with XARGS. I thought putting each ...

xargs I already have full command set

I have a file like this. rm a.txt mkdir foo cp a.doc docs I am used to xargs but following command is not doing anything. cat commands.txt | xargs -l1 ...

xargs not working

I want all the lines with assert_equal and without amazon. I tried following but it is not working. ack assert_equal | xargs ack -v amazon ...

Display contents of a file in the parent directory

I have a command which lists Weblogic instances directories on a server.I want to display contents of a file in the parent directory of each directory listed. An additional feature would be to display the name of the file in addition to displaying the contents /usr/ucb/ps auwwx | grep weblogic | tr ' ' '\n' | grep security.policy | gr...

When should xargs be preferred over while-read loops?

xargs is widely used in shell scripting; it is usually easy to recast these uses in bash using while read -r; do ... done or while read -ar; do ... done loops. When should xargs be preferred, and when should while-read loops be preferred? ...

Redirect sed output to tr

How do I redirect the output of a sed command as input to a tr command? ...

git undo alias with xargs

I have a git alias (git undo) that undoes everything in the working directory, including new files, changed files, and deleted files: !git reset --hard && git ls-files -d | xargs -0 git rm --ignore-unmatch && git clean -fq On OS X, this works great. On Linux, however, I run into the following issue: if no files have been deleted from...

bash find xargs grep only single occurence

hi. 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 grep "something" i have a great number of files, on multiple depths. first occurence of "something" is enough for me, but find continue...

Bash: "xargs cat", adding newlines after each file

I'm using a few commands to cat a few files, like this: cat somefile | grep example | awk -F '"' '{ print $2 }' | xargs cat It nearly works, but my issue is that I'd like to add a newline after each file. Can this be done in a one liner? (surely I can create a new script or a function that does cat and then echo -n but I was wonder...

Example of xargs' -x option in action

GNU xargs has option '-x'. The man page says: -x Exit if the size (see the -s option) is exceeded. But xargs seems to not care if -x is set or not. I have been unable to make an example in which the -x has any effect at all. Please provide two examples in which the only difference is an added -x and that produce different outp...

Tarballing without git metadata

My source tree contains several directories which are using git source control and I need to tarball the whole tree excluding any references to the git metadata or custom log files. I thought I'd have a go using a combo of find/egrep/xargs/tar but somehow the tar file contains the .git directories and the *.log files. This is what I ha...

Shell Scripting: Using xargs to execute parallel instances of a shell function

I'm trying to use xargs in a shell script to run parallel instances of a function I've defined in the same script. The function times the fetching of a page, and so it's important that the pages are actually fetched concurrently in parallel processes, and not in background processes (if my understanding of this is wrong and there's negli...

Using xargs to assign stdin to a variable

All that I really want to do is make sure everything in a pipeline succeeded and assign the last stdin to a variable. Consider the following dumbed down scenario: x=`exit 1|cat` When I run declare -a, I see this: declare -a PIPESTATUS='([0]="0")' I need some way to notice the exit 1, so I converted it to this: exit 1|cat|xargs -I {...

Argument list too long. Building Hubbub HTML Parsing Library. execv

When I attempt to build this library on my system (Fedora) Linux localhost.localdomain 2.6.33.8-149.fc13.i686 #1 SMP Tue Aug 17 22:45:56 UTC 2010 i686 i686 i386 GNU/Linux I get a long list of errors of which this is the last few lines: build/makefiles/Makefile.top:542: warning: overriding commands for target `build-Linux-Linux-releas...

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 the files. Something like this: filename_listing_command | sed -e '/\.py/!d' | xargs ac ...