在Linux下比較兩個目錄需要忽略某些文件時怎麼做
在Linux下如果要比較兩個目錄,可以使用diff命令,並且需要加上選項-r(遞歸)。
-r When comparing directories, recursively compare any subdirectories found.
另外還有兩個常用的選項,-b (忽略空白)和 -B (忽略空行)
-b Ignore changes in amount of white space.
-B Ignore changes that just insert or delete blank lines.
www.2cto.com
如下例所示:
[root@s170 cjtj]# diff -r -b -B sch_admin 4sch_admin
Only in 4sch_admin: 1.txt
diff -r -b -B sch_admin/build/CVS/Root 4sch_admin/build/CVS/Root
1c1
< :pserver:coding@cvsbank:/CVSAPPS
---
> :pserver:
[email protected]:12401/home/cvsroot
diff -r -b -B sch_admin/conf/CVS/Entries 4sch_admin/conf/CVS/Entries
1c1
< /struts-sch.xml/1.3/Fri May 18 07:31:05 2012//
---
> /struts-sch.xml/1.3/Fri May 18 14:39:35 2012//
。。。 www.2cto.com
。。。
因為我的目錄中帶有版本信息,CVS目錄存在很大的區別,但是對實際的文件內容是沒有意義的,因此我想在比較時忽略掉CVS目錄。
--exclude=pattern
When comparing directories, ignore files and subdirectories whose basenames match pattern.
下面是加了 --exclude選項時的比較結果,看上去很清爽。
[root@s170 cjtj]# diff -r -b -B --exclude=CVS sch_admin 4sch_admin
Only in 4sch_admin: 1.txt
Binary files sch_admin/dist/sch-admin.jar and 4sch_admin/dist/sch-admin.jar differ
Only in 4sch_admin/dist: .#sch-admin.jar.1.10
Only in 4sch_admin/dist: .#sch-admin.jar.1.11
Only in 4sch_admin/dist: .#sch-admin.jar.1.12
Only in 4sch_admin/extra/zhaosheng: baoming.html.1
[root@s170 cjtj]#