如何只为特定类型的文件区分目录? [英] How do you diff a directory for only files of a specific type?
问题描述
我对diff命令有疑问 如果我要递归目录diff但仅针对特定文件类型,该怎么做?
I have a question about the diff command if I want a recursive directory diff but only for a specific file type, how to do that?
我尝试使用exclude选项,但只能使用一种模式:
I tried using the exclude option but can only use one pattern only:
$ diff /destination/dir/1 /destination/dir/2 -r -x *.xml
使用命令我只能排除xml文件类型,即使文件夹图像类型中有文件(png
,gif
,jpg
),txt
,php
等
with the command I can only exclude xml file type, even though there are files in the folder image type (png
, gif
, jpg
), txt
, php
, etc
如何仅区分某些文件类型.
how to diff only certain file types.
推荐答案
您可以多次指定-x
.
diff -x '*.foo' -x '*.bar' -x '*.baz' /destination/dir/1 /destination/dir/2
在info diff
的比较目录"部分中(在我的系统上,我必须执行info -f /usr/share/info/diff.info.gz
):
From the Comparing Directories section of info diff
(on my system, I have to do info -f /usr/share/info/diff.info.gz
):
要在比较目录时忽略某些文件,请使用'-x PATTERN"或"--exclude = PATTERN"选项.此选项将忽略任何文件 或基本名称与外壳模式PATTERN匹配的子目录. 与外壳程序不同,在文件名的开头以句点开头 在模式开头匹配通配符.你应该附上 用引号将PATTERN括起来,以使外壳程序不会对其进行扩展.例如, 选项 -x'*.[ao]'会忽略名称以'.a'结尾的任何文件,或者 ".o".
To ignore some files while comparing directories, use the '-x PATTERN' or '--exclude=PATTERN' option. This option ignores any files or subdirectories whose base names match the shell pattern PATTERN. Unlike in the shell, a period at the start of the base of a file name matches a wildcard at the start of a pattern. You should enclose PATTERN in quotes so that the shell does not expand it. For example, the option -x '*.[ao]' ignores any file whose name ends with '.a' or '.o'.
如果多次指定此选项,则会累积该选项.为了 例如,使用选项 -x'RCS'-x'*,v'忽略任何文件或 子目录,其基本名称为'RCS'或以',v'结尾.
This option accumulates if you specify it more than once. For example, using the options -x 'RCS' -x '*,v' ignores any file or subdirectory whose base name is 'RCS' or ends with ',v'.
这篇关于如何只为特定类型的文件区分目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!