I have a patch file that I want to install in linux. I know there is a patch command, And I tried to use it like this:
patch -i file --verbose
where file is the patch file. But it asks me for the file to be patched(to be changed):
Hmm... Looks like a unified diff to me...
can't find file to patch at input line 17
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|From 13fac179aa50556ba3c60790a9beb6ca9d0b1b8b Mon Sep 17 00:00:00 2001
|From: Andrey Vagin <avagin#openvz.org>
|Date: Fri, 28 Jan 2011 23:31:20 +0300
|Subject: [PATCH rh5] vdso: export vdso_sysctl_vsyscall
|
|Signed-off-by: Andrey Vagin <avagin#openvz.org>
|---
| arch/x86_64/vdso/vclock_gettime.c | 4 ++--
| arch/x86_64/vdso/vextern.h | 1 +
| include/asm-x86_64/vsyscall.h | 1 +
| 3 files changed, 4 insertions(+), 2 deletions(-)
|
|diff --git a/arch/x86_64/vdso/vclock_gettime.c b/arch/x86_64/vdso/vclock_gettime.c
|index 5e15d01..3e586bf 100644
|--- a/arch/x86_64/vdso/vclock_gettime.c
|+++ b/arch/x86_64/vdso/vclock_gettime.c
--------------------------
File to patch:
I don't know what file should be changed so I tried to get that from the patch file itself. But of course there is no directory arch/x86_64/vdso/
This is the full patch file. Any help on how to install it?
A patch file like this contains the differences between two versions of text files.
This one contains changes to these source files:
arch/x86_64/vdso/vclock_gettime.c | 4 ++--
arch/x86_64/vdso/vextern.h | 1 +
include/asm-x86_64/vsyscall.h | 1 +
You can't install it. You can use it to patch the source code (if you have it), compile it and install the results. But I don't think that is what you want.
If you want to install bugfixes use your package manager (I guess it's 'yum' for RedHat).
I'm not good with patch files, but it seems to be a patch file in the 'git format'.
The easiest way to apply such files would be to
1) git clone <path_to_kernel_sources>
2) git checkout 13fac179aa50556ba3c60790a9beb6ca9d0b1b8b
3) git apply <patch_file>
That should take care of automatically applying it for you.
I'm not entirely sure if the commit ID 13fac179aa50556ba3c60790a9beb6ca9d0b1b8b is the correct one. I just picked that up from the e-mail part of your post.
You probably need some more arguments to patch(1). In particular, try
patch -p1 --verbose -i file
Related
I want to build linux-rt kernel and after downloading kernel and patch from kernel.org website i run this command as with documentation:
gzip -cd ../patch-5.11.4-rt11.patch.gz | patch -p1 --verbose {}
now i see this line in first time
patching file {}
Using Plan A...
Hunk #1 FAILED at 35.
1 out of 1 hunk FAILED -- saving rejects to file {}.rej
Hmm... The next patch looks like a unified diff to me...
The text leading up to this was:
--------------------------
|diff --git a/include/linux/rbtree.h b/include/linux/rbtree.h
|index d7db179963221..c33b0e16d04b4 100644
|--- a/include/linux/rbtree.h
|+++ b/include/linux/rbtree.h
--------------------------
patching file {}
Using Plan A...
Hunk #1 FAILED at 19.
Hunk #2 FAILED at 112.
2 out of 2 hunks FAILED -- saving rejects to file {}.rej
Hmm...The next patch would create the file {},
which already exists! Assume -R? [n]
which key should be pressed to apply this patches ?
For example I have two directories say old and new. The directory old has a sub-directory abc and the directory new has a sub-directory cde.
I tried creating patch by using
diff -ru old/ new/ > file.patch
I got following output in file.patch:
Only in old/: abc
Only in new/: cde
and when I tried to patch the file I got following error:
patch: **** Only garbage was found in the patch input.
When I try to create patch by using:
diff -ruN old/ new/ > file.patch
I get empty file.patch.
Is there any way to create a patch that when patched to old would delete abc and create cde in old?
The makepatch script is useful for this. I use this for almost all source-patches, along with diffstat. There is also applypatch (completing the task), though I do not use it myself.
The GNU diff new-file "-N" option does (used to not...) work with the recursion option "-r". So you could use
diff -r -N old new
I just verified that it works for diff 3.0 (which by now is rather old).
I have been using ns2 and nam for a long time on my ubuntu. Now I have to apply a patch (OSPF) to it. I have been searching for how to apply a patch in linux (as I'm kind of new in it) and all I got was:
1) $ tar xvf ns-allinone-2.35.tar.gz
2) $ cd ns-allinone-2.35/
3) $ ln -s ns-2.35/ ns-2.34
... Then the patch will work, except for one line. (commom/packet.h).
4) $ patch -p0 < 10-ospf4ns2.34-base.patch
http://sourceforge.net/projects/ospf4ns/
5) Replace commom/packet.h with the attached "packet.h" : Edited by hand.
6) export CC=gcc44 CXX=g++44 && ./install
I untared the tar file, copied the .patch file in the ns-allinone-2.35 folder called 10-ospf4ns2.34-base.patch, gone to the directory in a terminal, used ln -s ns-2.35/ ns-2.34 and then patched using line 4. After that I have these messages:
The next patch would create the file ns-2.34/classifier/classifier-mtopology.cc,
which already exists! Assume -R? [n] y
patching file ns-2.34/classifier/classifier-mtopology.cc
The next patch would create the file ns-2.34/classifier/classifier-mtopology.h,
which already exists! Assume -R? [n] y
patching file ns-2.34/classifier/classifier-mtopology.h
can't find file to patch at input line 92
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|--- ns-2.34.old/common/agent.cc 2009-06-14 18:35:45.000000000 +0100
|+++ ns-2.34/common/agent.cc 2010-02-26 23:34:33.161063590 +0000
--------------------------
File to patch:
After this I don't know what to do. What file should I patch? There is no classifier-mtopology.h in ns-2.34.
And after that, which packet.h should I replace with the specified new packet.h? Because there are several common folders. Any help would be much appreciated cause I'm a novice in linux.
It looks like you already applied the patch before (at least partially) and that you are not in the correct directory.
Start again, also you can avoid the symlink with the following instructions:
Extract ns-allinone-2.35.tar.gz in a fresh directory.
cd ns-allinone-2.35/ns-2.35
Apply the patch with:
patch -p1 < 10-ospf4ns2.34-base.patch
I have a folder which contains subfolders. In these subfolders are both .jpg and .mov files.
What I want to do is duplicate the tree into another root folder, but include only the .mov files.
Is there a terminal command I can issue that will do this like magic? I'm hoping there might be a linux guru out there with ninja-like skills who can save me a lot of time.
Example:
Current:
Pictures
-- 2014
----- January
--------- file1.jpg
--------- file1.mov
----- February
--------- file1.jpg
--------- file1.mov
----- March
--------- file1.jpg
--------- file2.jpg
----- April
--------- file1.mov
--------- file2.mov
Desired:
Pictures
-- 2014
----- January
--------- file1.jpg
----- February
--------- file1.jpg
----- March
--------- file1.jpg
--------- file2.jpg
Movies
-- 2014
----- January
--------- file1.mov
----- February
--------- file1.mov
----- April
--------- file1.mov
--------- file2.mov
I would use find with dirname. Should work in the same way both in Linux and in MacOS. This is a shell script that should work in bash.
Note: to make sure you don't run it in the wrong place or with wrong values of $source and $target I prefixed all essential commands with echo so that it will print the command, rather than execute it. Make sure it does what you expect, then remove all echo (e.g. replace echo mkdir ... with just mkdir ...). This is a common precaution when writing complicated shell scripts.
source="/path/to/source"
target="/path/to/target"
cd "$source"
find . -type f -name '*.mov' |
while read fn ; do
path=`dirname $fn`
echo mkdir -p "$target/$path" # -p is essential here
echo cp "$fn" "$target/$path/"
done
Here we iterate over the list of *.mov files in the $source directory, and for each file we extract the directory name using dirname. Then we create the corresponding subdirectory in the $target using mkdir -p (which will create all the required subdirectories and will not fail if the directory already exists) and finally copy the file.
I would suggest using rsync, I hope the syntax is the same on OS X
rsync -vrR --include="*.jpg" --include="*/" --exclude="*" /path/to/source /path/to/target
You will need to run two separate commands for *.mov and *.jpg since the target dirs are different
In case it will help someone, I actually found a simpler solution that doesn't require the command line. I used FreeFileSync to copy the files to the new tree, then went back and used finder to remove the files that were copied over. Still a two-step process, but it was simple since it did not use the command line.
FreeFileSync has filtering, so I was able to isolate only the videos to copy over.
Removing the videos from the pictures folder was as simple as using finder's search capability and filtering on video file types only. Then one delete killed them all at once.
Here's an output of diff -u "temp temp/docs 1.txt" "temp temp/docs 2.txt":
--- temp temp/docs 1.txt Mon Apr 7 16:15:08 2014
+++ temp temp/docs 2.txt Mon Apr 7 16:18:45 2014
## -2,6 +2,6 ##
22
333
4444
-555555
+55555
666666
7777777
However, feeding this diff to patch -u fails with following message:
can't find file to patch at input line 3
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|--- temp temp/docs 1.txt Mon Apr 7 16:15:08 2014
|+++ temp temp/docs 2.txt Mon Apr 7 16:18:45 2014
--------------------------
Apparently, the spaces are the problem; is there a way to make patch to work on files with spaces in names?
No, GNU patch doesn't support this. Here's the official statement: http://www.gnu.org/software/diffutils/manual/html_node/Unusual-File-Names.html#Unusual%20File%20Names
Gnu patch 2.6.1 (linux) seems to obey at least 1 space (not tried with more) if the filename is separated from the date with tab.
YYMV
I encountered the same problem when trying to establish conventions how to do manual version control with diff and patch.
I found out that GNU "diff" creates quoted path names in the patch headers if they contain spaces, while BusyBox "diff" doesn't.
Neither GNU nor BusyBox "patch" accepts quoted path names.
If the problem is just embedded spaces within filenames, it can therefore be avoided by using "busybox patch" rather than GNU "patch".
Another solution is to postprocess the output of GNU "diff" before feeding it into "patch":
sed 's,^\([-+]\{3\} \)"\([^"]*\)",\1\2,' $PATCHFILE | patch -p1
This works whether $PATCHFILE was created with GNU or busybox diff, but will only work with unified diff format.
Unfortunately, it turns out that leading or trailing spaces in filenames cannot be preserved with this method, as "patch" will skip them when parsing the path names from the patch instructions.
The approach will neither work if the filename starts with a literal double quote - but then, who uses such file names?
Most of the time, however, the above approach works just fine.
Finally a note of other approaches I have also tried but which did not work:
First I tried to replace the quotation of the whole path names by individually quoted path name components. This failed because "patch" does not use double quotes as meta-characters at all. It considers them to be normal literal characters.
Then I tried to replace all spaces by "\040" like CVS does - but "patch" does not seem to accept octal-escapes either, and this failed too.