Tell me more ×
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 know if a file has been patched already, before apply the patch?

I need to do this in a script, any thoughts?

share|improve this question
1  
What program are you using to patch them? What sort of patches? – Omnifarious Nov 15 '12 at 4:05

1 Answer

Here is a guess, assuming that you are using the patch utility and each file to be patched has its own patch:

if nohup patch <options> -N --dry-run --silent <patchfile 2>/dev/null; then
    echo The file has not had the patch applied,
    echo and the patch will apply cleanly.
else
    echo The file may not have had the patch applied.
    echo Or maybe the patch doesn't apply to the file.
fi
share|improve this answer
Or, if you patched the files before and want to know, whether it touched some specific file, you can run the first patch round with the -B option, which would cause backup to be made. Then you check for existence of the backup. – peterph Nov 15 '12 at 10:12
1  
Could you expand a bit on why you chose to use nohup in that if case? – Zrajm C Akfohg Apr 17 at 12:48

Your Answer

 
discard

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.