Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Suppose I have two same folders in machine A (Linux) and in machine B (Linux) . Now I am compare these two files using "diff" command .
I mean running diff command in following way :
Diff compares the contents of two files. It does not (directly) compare directories.
Diff compares files only - not URLs. When you say remote, what do you mean? If the remote files are mounted on the local system using NFS or SMB or something else which allows you to see them in the local filesystem this is fine, but if you access the files using HTTP or FTP, this is a little more complicated.
Acyually I have a file called "file1" in Linux A .
In Linux B i have same file caled 'file2'
Now i need to run diff command in a shell script .
But I cannot go to the file2 in LinixB easily . So that I need ur help how can I comapre this two files where files are in different machines ......
where <remote-host> is the address of the remote machine. This will execute "cat /path/to/remotefile" on the remote host and will compare it with /path/to/localfile. The command
Code:
diff - /path/to/localfile
means compare standard input with the content of /path/to/localfile. The standard input is passed through the pipe.
Maybe you have to elaborate to suite to your needs. For example, you may want to generate private/public ssh keys to avoid prompting for password. Also if you want to compare files with blank space in their name you have to escape it, e.g.
ssh is not directly connected to the remote server without password , is it ?
It shows follwoign error :
[root@server ~]# ssh 192.168.101.129 "cat /tmp/file2" | diff - /root/file1
diff: cannot compare `-' to a directory
connect to address 192.168.101.129: Connection refused
Trying krb4 ssh...
connect to address 192.168.101.129: Connection refused
trying normal ssh (/usr/bin/ssh)
sshd: 0826-826 The host name for your address is not known.
ssh is not directly connected to the remote server without password , is it ?
No, of course. You have to setup public key authentication for passwordless connection. See man ssh and man ssh-keygen for details.
Quote:
[root@server ~]# ssh 192.168.101.129 "cat /tmp/file2" | diff - /root/file1
diff: cannot compare `-' to a directory
connect to address 192.168.101.129: Connection refused
Trying krb4 ssh...
connect to address 192.168.101.129: Connection refused
trying normal ssh (/usr/bin/ssh)
sshd: 0826-826 The host name for your address is not known.
This means two things: first, /root/file1 on the local machine is a directory, not a file, isn't it? So it would be more tricky to compare directories by this method. Second, it looks like the remote machine does not resolve the host name of your local machine and refuse connection. Try to investigate this problem before proceeding.
Here's how to configure ssh to work using public key authentication (which you can use to do remote commands without being prompted for a password each time):
No, of course. You have to setup public key authentication for passwordless connection. See man ssh and man ssh-keygen for details.
This means two things: first, /root/file1 on the local machine is a directory, not a file, isn't it? So it would be more tricky to compare directories by this method. Second, it looks like the remote machine does not resolve the host name of your local machine and refuse connection. Try to investigate this problem before proceeding.
Hi all, I know this thread is quite old, but I am facing a similar issue now...what I need to know is "it is possible to combine cat , diff and ssh to compare the content of two directories ( and so recursively of all the files into them ) located on two different machines?
I only can imagine the following:
ssh your@connection find ./folder -type f -exec cat \;>> ./freespace; find ./folder -type f -exec cat \; >> ./evenmorespace; diff ./freespace ./evenmorespace
Last edited by White Tea Citrus; 01-24-2010 at 04:59 PM.
Or use sshfs to mount the remote directory through ssh (it requires FUSE) and then just diff recursively. Here is a quick and dirty example (suppose you have to compare /path/to/local/dir and /path/to/remote/dir)
The only glitch is that on many systems the fusermount command has the setuid attribute set and you can run it only by gaining root privileges. A common workaround is to add yourself (or ask the system administrator to add you) to the fuse group.
Or use sshfs to mount the remote directory through ssh (it requires FUSE) and then just diff recursively. Here is a quick and dirty example (suppose you have to compare /path/to/local/dir and /path/to/remote/dir)
The only glitch is that on many systems the fusermount command has the setuid attribute set and you can run it only by gaining root privileges. A common workaround is to add yourself (or ask the system administrator to add you) to the fuse group.
Thanks a lot, I liked this solution and it worked!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.