Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Is it possible to tell patch not to generate .orig and .rej files? I find it extremely annoying that patch creates these.

share|improve this question

3 Answers 3

To tell patch not to produce backups just omit the -b and any --backup-... options.

To instruct it not to create .rej files add -r - option to the command.

share|improve this answer
This doesn't work for me – it just puts the rejects in a file called "-", which is a very very annoying filename to have around. I'm using version 2.5.8 on a Mac. –  rjmunro Jan 28 at 11:29

If you're not giving any option to patch other than -pN, it only creates those files when a patch fails to apply cleanly.

So, one option is to stop creating (or accepting) bad patches. :)

Back in the real world, this is a feature. When patch(1) fails to apply a patch segment to the original file, it saves the temporary original file copy out durably as *.orig, dumps the rejected segment to *.rej, and continues trying to apply patch segments. The idea is that you can open the *.rej file and complete the patch process manually by copying bits and pieces over to the patched file. The *.orig file can also be useful when the patch process accidentally wrecks something, and you need to refer to the original version to fix it.

I don't always fix a bad patch with text from the *.rej and *.orig files, but it's nice to have them in case I need them.

Once I've fixed up a bad patch, I give this command at the project root to quickly clean things up:

$ find . \( -name \*.orig -o -name \*.rej \) -delete

I use it often enough that it stays in my Bash history. I find that Ctrl-R o r i is enough to find the command in my history.

share|improve this answer

patch -p1 -B /dev/null -r - < file.patch

share|improve this answer
-1: This is very bad advice. First, the -B flag doesn't send the *.orig output to /dev/null, as it appears to from your command. It just happens that normal users can't write to files called things like /dev/nullfoo.cpp. If you do this as root, you'll get junk in your /dev tree instead. Second, -r - doesn't suppress the *.rej file. It just appears to do that because the error due to the bogus -B flag stops it from showing you what it really would do without the -B, which is create a file called - in the current directory. –  Warren Young Mar 19 at 8:18
@WarrenYoung according to man patch: "-r Put rejects into rejectfile instead of the default .rej file. When rejectfile is -, discard rejects." –  Limbo Peng May 12 at 9:02

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.