I am trying to apply patches for multiple files. These files are present in different directories at different levels in a top-level directory. The directory structure is same for the patch files also.

Is there any way in which I can apply all patches at once?

I'm applying them individually using patch -p1 command.

  • What's the exact command you're using? – muru Jan 4 '16 at 6:01
  • right now i'm iterating to each folder in which the patch file is present and applying it using " patch -p1 <file.patch " – Atchyut Sreekar Jan 4 '16 at 6:02

You could do something like:

find . -iname '*.patch' -execdir sh -c 'patch -p1 < $0' {} \;

This find command:

  • looks for files in the current directory (.) recursively
  • that are have filenames ending in .patch (adjust according to whatever naming pattern your patch files follow)
  • and in the directory where a matching file was found, runs sh -c 'patch -p1 < $0' matched-file:
    • $0 is the first argument, which is the matched file, so the command is essentially patch -p1 < matched-file
    • sh -c is needed since we're using redirection.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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