我正在阅读有关“差异”的源代码的信息。最近,我在讨论diff -S [FILE]或--starting-file = FILE选项。我做了一些测试来验证它,但我无法得到我想要的东西。关于我的测试:
ls -l /tmp/Nibnat/diffutils-2.7/
-rw-rw-r--. 1 Nibnat Nibnat 9 5月 9 13:46 diff.c
-rw-rw-r--. 1 Nibnat Nibnat 9 5月 9 13:57 file_a
-rw-rw-r--. 1 Nibnat Nibnat 9 5月 9 13:57 file_b
-rw-rw-r--. 1 Nibnat Nibnat 9 5月 9 13:57 file_c
-rw-rw-r--. 1 Nibnat Nibnat 20 5月 9 11:46 heh.c
ls -l /tmp/Nibnat/test_dir/
-rw-rw-r--. 1 Nibnat Nibnat 5 5月 9 11:45 diff.c
-rw-rw-r--. 1 Nibnat Nibnat 5 5月 9 13:56 testfile_a
-rw-rw-r--. 1 Nibnat Nibnat 5 5月 9 13:56 testfile_b
-rw-rw-r--. 1 Nibnat Nibnat 5 5月 9 13:56 testfile_c
-rw-rw-r--. 1 Nibnat Nibnat 5 5月 9 13:56 testfile_d
/tmp/Nibnat/diffutils-2.7/diff.c与/tmp/Nibnat/test_dir/diff.c不同,当我想比较这两个目录时,我想从/tmp/Nibnat/diffutils-2.7进行比较/ file_a(跳过diff.c),所以我使用命令
'diff -S /tmp/Nibnat/diffutils-2.7/file_a /tmp/Nibnat/diffutils-2.7/ /tmp/Nibnat/test_dir/'
我明白了:
diff -S /tmp/Nibnat/diffutils-2.7/file_a /tmp/Nibnat/diffutils-2.7/diff.c /tmp/Nibnat/test_dir/diff.c
1c1
< hahahehe
---
> haha
Only in /tmp/Nibnat/diffutils-2.7/: file_a
Only in /tmp/Nibnat/diffutils-2.7/: file_b
Only in /tmp/Nibnat/diffutils-2.7/: file_c
Only in /tmp/Nibnat/diffutils-2.7/: heh.c
Only in /tmp/Nibnat/diffutils-2.7/: test_a.c
Only in /tmp/Nibnat/diffutils-2.7/: test_b.c
Only in /tmp/Nibnat/diffutils-2.7/: test_c.c
Only in /tmp/Nibnat/test_dir/: testfile_a
Only in /tmp/Nibnat/test_dir/: testfile_b
Only in /tmp/Nibnat/test_dir/: testfile_c
Only in /tmp/Nibnat/test_dir/: testfile_d
它仍然没有跳过diff.c. 任何帮助都是值得的。
答案 0 :(得分:0)
只需使用-S diff.c
,即只使用文件名,而不是完整的路径名:
$ ls -l /tmp/TST/a
total 12
-rw-r--r-- 1 orpe orpe 3 Apr 25 16:16 diff.c
-rw-r--r-- 1 orpe orpe 2 Apr 25 16:17 file_a
-rw-r--r-- 1 orpe orpe 2 Apr 25 16:17 file_b
$ ls -l /tmp/TST/b
total 12
-rw-r--r-- 1 orpe orpe 3 Apr 25 16:16 diff.c
-rw-r--r-- 1 orpe orpe 2 Apr 25 16:17 testfile_a
-rw-r--r-- 1 orpe orpe 2 Apr 25 16:17 testfile_b
$ diff /tmp/TST/a /tmp/TST/b
diff /tmp/TST/a/diff.c /tmp/TST/b/diff.c
1c1
< aa
---
> bb
Only in /tmp/TST/a: file_a
Only in /tmp/TST/a: file_b
Only in /tmp/TST/b: testfile_a
Only in /tmp/TST/b: testfile_b
$ diff -S file_a /tmp/TST/a /tmp/TST/b
Only in /tmp/TST/a: file_a
Only in /tmp/TST/a: file_b
Only in /tmp/TST/b: testfile_a
Only in /tmp/TST/b: testfile_b
$ diff -S file_b /tmp/TST/a /tmp/TST/b
Only in /tmp/TST/a: file_b
Only in /tmp/TST/b: testfile_a
Only in /tmp/TST/b: testfile_b
$