Linux 如何通过 ssh 区分目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20969124/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:47:18  来源:igfitidea点击:

How to diff directories over ssh

linuxshell

提问by Hesham Yassin

I am trying to recursively compare a directory in the local host to a directory in a remote linux machine. However, when i execute the next command:

我试图递归地比较本地主机中的目录与远程 linux 机器中的目录。但是,当我执行下一个命令时:

diff -r 'ssh [email protected]:/home/admin' /home/admin

it doesn't work saying:

它不起作用说:

diff: ssh [email protected]:/home/admin: No such file or directory

diff: ssh [email protected]:/home/admin: 没有那个文件或目录

what is the right way to compare recursively the directories contents?

递归比较目录内容的正确方法是什么?

Thanks in advance

提前致谢

采纳答案by BMW

If you needn't diff the detail in file, just get the difference of dir/file name, then try this:

如果您不需要比较文件中的详细信息,只需获取目录/文件名的差异,然后尝试以下操作:

(Note: need set "SSH login without password" , for detail , review this URL: http://www.linuxproblem.org/art_9.html)

(注意:需要设置“SSH无密码登录”,详情请查看此网址:http: //www.linuxproblem.org/art_9.html

diff <(ssh [email protected] ls -R /home/admin) <(ls -R /home/admin)

回答by Mark Setchell

Try using "rsync" with the "-n" option, which just does a "dry run" and tells you what it would do.

尝试使用带有“-n”选项的“rsync”,它只会进行“试运行”并告诉您它会做什么。

回答by Alfe

You can mount the remote directory via sshfs, then you can use diff -rto compare the two directories as you want to do it.

您可以通过挂载远程目录sshfs,然后您可以根据diff -r需要比较两个目录。

Alternatively you could run similar findcommands on both machines to print the file trees (e. g. file names, sizes, and dates) and then compare the outputs of both using diff. This would not compare file contents, of course:

或者,您可以find在两台机器上运行类似的命令来打印文件树(例如文件名、大小和日期),然后使用diff. 这当然不会比较文件内容:

diff <(ssh host find /home/admin -printf '"%8s %P\n"') \
     <(find /home/admin -printf '%8s %P\n')

Notice the double quoting of the printf-format string in the sshcall. One layer is removed by the sshrelay.

注意ssh调用中printf 格式字符串的双引号。一层被ssh继电器移除。

回答by Hanan Shteingart

I find krusader very useful for such task in case you need a GUI. See https://www.linux.com/news/synchronize-directories-komparator-and-kdiff3for more details http://krusador.org.

如果您需要 GUI,我发现 krusader 对于此类任务非常有用。有关更多详细信息,请参阅https://www.linux.com/news/synchronize-directories-komparator-and-kdiff3 http://krusador.org

example folder compare

示例文件夹比较