Every Linux sysadmin knows the pain: You update a package, and suddenly you have a
|
1 |
.rpmnew |
,
|
1 |
.pacnew |
, or
|
1 |
.conf.default |
file sitting next to your carefully tuned configuration.
Do you keep your old file? Do you overwrite it with the new defaults? Don’t just copy-paste!
Here are the three best ways to interactively merge these files, including a dark-mode friendly “Cheat Sheet” for the most powerful tool of them all.
1. The Power User Way:
1
vimdiff
|
1 |
vimdiff |
If you have Vim installed, this is the gold standard. It opens both files side-by-side, highlights the differences, and folds away the parts that are identical.
The Command
|
1 |
vimdiff current_config.conf new_defaults.conf |
The Vimdiff Cheat Sheet
Navigating Vim can be scary, but you only need these 5 commands to merge files:
| Key | Action | Mnemonic | ||
|---|---|---|---|---|
|
Jump to Next Change | — | ||
|
Jump to Previous Change | — | ||
|
Pull change from other window to yours | Diff Obtain (Get it) | ||
|
Push change from yours to the other | Diff Put (Send it) | ||
|
Save All files and Quit | eXit All |
2. The Simple Interactive Way:
1
sdiff
|
1 |
sdiff |
If you don’t want to memorize keyboard shortcuts,
|
1 |
sdiff |
is a fantastic alternative. It runs in the terminal and asks you line-by-line which version you want to keep.
The Command
|
1 |
sdiff -o final_merged.conf current.conf new.conf |
It will pause at every difference and show a prompt (
|
1 |
% |
). Just type one of these letters and hit Enter:
- l : Choose the Left file’s version.
- r : Choose the Right file’s version.
- eb : Edit Both (opens a mini-editor to combine them).
3. The Graphical Way: Meld
If you are on a desktop environment (Ubuntu, Fedora, Mint), nothing beats Meld. It provides a visual 3-column or 2-column view where you can simply click arrows to move code blocks around.
The Command
|
1 |
meld current.conf new.conf |
Tip: You can hold down CTRL while clicking the arrow to insert the new lines above/below instead of replacing the old ones!