Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a directory with .patch files, generated using diff.

I would like to apply all those patches using patch -p1 to another directory.

But patch takes only one file, unless I cat.

What would the command be to apply multiple files using xargs or a similar tool.

share|improve this question
I like both solutions below, thanks guys! – styts Jan 13 '10 at 16:33
Then why not upvote them? – womble Jan 13 '10 at 20:59
A reputation of 15 is required to upvote. – styts Jan 16 '10 at 9:55
ah, finally enough points.. both solutions upvoted! – styts Jul 1 '10 at 12:28
up vote 2 down vote accepted

If cat works, why not use it?

To use find and xargs:

find dirname -name namespec -print0 | xargs -0 patch patchargs
share|improve this answer
It should be -print0 instead of -print 0, anyway it does not work whereas @James solution does – tanguy_k Oct 7 '15 at 0:01

Assuming you're using bash/sh/zsh etc...

cd /path/to/source
for i in /path/to/patches/*.patch; do patch -p1 < $i; done
share|improve this answer

This actually works (in Bash):

shopt -s globstar
for file in /path/to/patches/**/*.patch
    patch -p1 < "$file"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.