Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

This question already has an answer here:

I generated a patch using the diff command with the number of context lines as 1 (-c option). My patch file contents:

*** /home/sk/abc/def/src/klm/a.py 2015-05-18 16:25:50.348398554 +0530
--- /opt/abc/def/ghi/klm/a.py  2015-05-18 14:27:13.860503469 +0530
***************
*** 72,73 ****
--- 72,74 ----
              output, error, rCommand = "", "", ""
+             import subprocess
              rCommand = self.copyCmd % (self.executor_hostname, self.testId, self.testId)

When I tried to apply the patch using these commands,

cd /
patch -p0 < sg.patch

I got this output,

can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|*** /home/sk/abc/def/src/klm/a.py  2015-05-18 16:25:50.348398554 +0530
|--- /opt/abc/def/ghi/klm/a.py  2015-05-18 17:10:48.368670076 +0530
--------------------------
File to patch:

Why doesn't the patch command take the file name in second line as the file to patch?

share|improve this question

marked as duplicate by garethTheRed, Anthon, Stephen Kitt, dr01, Thomas Dickey Jun 2 at 8:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
hi javabrett, thanks for your info.. i have changed the question and its error message... – Madhavan Kumar May 18 '15 at 12:53
    
Are both of the files present? – javabrett Apr 20 at 5:16

You need to be in the root directory to apply the patch with an absolute path, and apply the -p0 option. See also this post.

share|improve this answer

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