Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

How to diff two remote files over ssh?

Answer:

Assume you have two files on two different machine, how do you do a diff of them?

Simply use the command below:

# diff <(ssh server_1 'cat foo1') <(ssh server_2 'cat foo2')

How to ignore blank lines when creating the diff of two files

Answer:

By default, the diff command will also compare the blank line of two files.

To ignore them, use:

# diff -B a.txt b.txt

How to apply a patch?

Answer:

In the last post, you know how to create a patch for two folders.

But, how to use the patch?

See below.

# cp -r foo dummy
# cd dummy
# patch -p1 -i ../bar.patch

Now the folder dummy is the same as bar.

How to create a patch

Answer:

Let say you have two folders, foo and bar.

The folder bar is originally copied from the folder foo, but later you have chanegd some files inside bar.

Now you want to create a patch (We will see later, when this patch applied to foo, it will produce the same contents as in bar).

# diff -crB foo bar > bar.patch

How to find the differences between two files over SSH

Answer:

If the files you want to compare are on different machines, you can combine ssh and diff for the comparsion.

E.g.

ssh john@192.168.11.5 "cat /tmp/foo.txt" | diff - /tmp/bar.txt