I need to apply a patch to a file in a complicated directory and symlink scenario. No matter what I try, I can't figure out how to massage the patch arguments so that it would find the desired file. Is there a way to completely circumvent the problem and just EXPLICITLY TELL patch to which file it should apply the patch, ignoring the path/filename in the .patch file?

  • I'm not sure if there's a way to do with with patch options, but can you just edit the patch file instead?
    – Sparhawk
    Commented Feb 1, 2019 at 8:46
  • Last resort. This is an automated build scenario where the patch is downloaded from the web, so I would have to either script the editing (cp, sed, patch, rm), or... patch the patch, which is silly. Commented Feb 1, 2019 at 9:04

2 Answers 2


If the patch only contains changes to a single file, you should be able to tell patch to apply those changes to a file of your choice by specifying it before the patch name:

patch myfile withthis.patch

will apply withthis.patch to myfile, ignoring the file name in the patch.

Quoting the man page:

The names of the files to be patched are usually taken from the patch file, but if there's just one file to be patched it can be specified on the command line as originalfile.


If the patch applies to only one file you could simply, put a symlink in that location pointing at the file you want it to be applied to. (assuming that the reason you need it applied else-ware is because that file does not exist) Then just apply the patch.

Even if it pointed at multiple files, it could be done this way, with more time.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .