Tag Info

Hot answers tagged

17

GNU xargs (default on Linux, install findutils from MacPorts on OS X to get it) supports -d which lets you specify a custom delimiter for input, so you can do ls *foo | xargs -d '\n' -P4 foo


11

From man find: -exec command {} + This variant of the -exec option runs the specified command on the selected files, but the command line is built by appending each selected file name at the end; the total number of invoca- tions of the command will be much less than the number of matched files. The command line is built in ...


11

You do not need to use xargs, because find can execute commands itself. When doing this, you do do not have to worry about the shell interpreting characters in the name. find /path/to -name "*.html" -exec grep -l "rumpus" '{}' + from the find man page -exec command {} + This variant of the -exec action runs the specified command on the selected ...


10

Use find ... -print0 | xargs -0 ... e.g. find /path/to -name "*.html" -print0 | xargs -0 grep -l "rumpus" from the find man page -print0 True; print the full file name on the standard output, followed by a null character (instead of the newline character that ‘-print’ uses). This allows file names that ...


10

Something along the lines of alias myxargs='perl -p -e "s/\n/\0/;" | xargs -0' cat nonzerofile | myxargs command should work.


5

Using GNU Parallel http://www.gnu.org/software/parallel/ you can do: cat listfile.txt | parallel curl -O Not only does GNU Parallel deal nicely with special chars like ' " and space, you will also get the added benefit of downloading in parallel. Watch the intro video to GNU Parallel: http://www.youtube.com/watch?v=OpaiGYxkSuQ


5

How big is the list and how many files are gone? Can you filter the missing files? % cat list.txt foo/bar foo/baz foo/fred foo/wilma betty % for file in `cat list.txt`; do [ -f $file ] && echo $file; done | xargs tar rvf archive.tar foo/bar foo/fred betty % tar tvf archive.tar -rw-r--r-- scott/scott 0 2011-07-05 10:25 foo/bar -rw-r--r-- ...


4

Provide the full path to postsuper in your script. It's probably just not in cron's $PATH.


4

Your problem, as I understand it, is that du is descending into other filesystems (some of which are network or SAN mounts, and take a long time to count up utilization on). I respectfully submit that if you're trying to monitor filesystem utilization du is the wrong tool for the job. You want df (which you apparently know about since you included its ...


4

If you're using a shell that supports backticks- or $()-style command substitution (most shells do), then in your case, you can avoid using xargs entirely, like this: ssh $(host -t PTR $(host -t A DomainIWant.com | awk '{print $4}') | awk '{print $5}') (I added the -t flags to the host commands, to ensure they only emit 1 line of output.)


4

sudo chown -R www:www ./ and if you don't want the directory owned by www, just change it back.


4

The {} bit is the placeholder for the exec command. Whatever files are found by find are inserted in place of the brackets. The + means to build up a long list of the found files and call the exec on all of them at once instead of one at a time, like the more traditional -exec {} \; variant.


4

If cat works, why not use it? To use find and xargs: find dirname -name namespec -print 0 | xargs -0 patch patchargs


4

You didn't use the -print0 option with find.


3

Assuming you're using bash/sh/zsh etc... cd /path/to/source for i in /path/to/patches/*.patch; do patch -p1 < $i; done


3

If you can live with the file being updated in place and a backup created. find -name '*.ext' -exec sed -i'.backup' 's/searchText/replaceText/' {} + Edit: If you absolutely can't have the files that way round - modified file in place and original with an extension - then you could bolt an extra command on the end of the exec to move them around.


3

You could write your xargs invocation to mask the return codes of your command lines. With something like the following,xargs will never see exit codes return by somecommand: xargs sh -c "somecommand || :"


3

Simple answer: install an infrastructure monitoring tool (such as ZenOSS, Zabixx, etc.). If you're looking for something custom, perhaps you need some sort of abstraction layer to handle weird per-machine differences rather than managing that by hand every time?


3

You can use pv : cat <someinput> | pv -p -s sizeof_someimput | xargs -n 1 -P 5 <somecmd> With this you will now where the reading of someimput is so you will know approximately where the treatment of someimput is.


2

The problem you are having is caused because the output of your ls command doesn't contain the path to the file it only contains the filename. When a cron job runs, it runs in the users home directory so when your rm is run, it is looking for files in /home/testuser not /home/testuser/test. You could fix this with a simple cd command cd /home/testuser/test ...


2

cat foo.txt | xargs -J % -n 1 sh -c "echo % | bar.sh" Tricky part is that xargs performs implicit subshell invocation. Here sh invoked explicitly and pipe not becomes the part of parent conveyor


2

Try this: find . -name "*.html" -exec hunspell '{}' \;


2

You can try using xargs's -n: Use at most max-args arguments per command line. Also worth noting xargs can be made to Print the command line on the standard error output before executing it. with -t, which is rather useful for debuging.


2

"xargs svn add" should be enough, why are you using -I {} ? I wouldn't do this at all. You'll probably get a lot of tempfiles in SVN. You may put a CD-image there one day. I wouldn't do this. Your comment will be completely meaningless. What did I change, etc? Why not just commit when you have actually changed something? Mysql is evil sometimes. You need to ...


2

There are some files in the file system that aren't real files, but are instead hooks into the kernel. Some of those can be read from forever. Try grep foo /dev/zero to see this in action. Get ready to stop it with ctrl-C before it takes over the whole system. If I wanted to do what you're doing, I'd enumerate the subdirectories of / that I wanted ...


2

You can try using find + xargs + grep for that, kinda: find /there -type f :MaybeSomeRestrictingFlagsLikeSizeNotBigger500MB_or_FS_type_if_u_know_its_exactly_on_EXT3_AndSoOn: -print0 | xargs -0r grep needle /dev/null (/dev/null makes grep printing file name even if only one file was found)


1

With Bash, I generally prefer to avoid xargs for anything the least bit tricky, in favour of while-read loops. For your question, while read -ar LINE; do ...; done does the job (remember to use array syntax with LINE, e.g., ${LINE[@]} for the whole line). This doesn't need any trickery: by default read uses just \n as the line terminator character. I ...


1

I think you will find that GNU Parallel http://www.gnu.org/software/parallel/ solves both your problems with newline and with running jobs in parallel. Watch the intro video: http://www.youtube.com/watch?v=OpaiGYxkSuQ


1

You could do this by running your xargs command through a shell - this will let you redirect the output - something like this: find blah -type f | xargs -I{} -P 4 -n 1 sh -c 'yourcommand --input {} > {}.output' ...you'll probably have to tweak it a bit - xargs replaces {} with the item/file it's working on


1

GNU Parallel http://www.gnu.org/software/parallel/ seems to be made for you, because it automatically combines the standard output from the processes correctly. find $MY_FILE_TREE --print0 | parallel --null --max-procs 3 --max-args 1 --no-run-if-empty myprocess.sh ">" {}.output or shorter: find $MY_FILE_TREE --print0 | parallel -0 -j3 -r myprocess.sh ...



Only top voted, non community-wiki answers of a minimum length are eligible