Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you diff a directory for only files of a specific type?

Tags:

linux

bash

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?

I tried using the exclude option but can only use one pattern only:

$ diff /destination/dir/1 /destination/dir/2 -r -x *.xml 

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.

like image 239
de_3 Avatar asked Sep 23 '10 04:09

de_3


People also ask

How can I find the difference between two folders?

If you double-click on a folder, it will expand to reveal its contents. If you double-click on a file it will open a side by side comparison and will highlight the differences, if any, between the two files. Double-clicking a file will open both copies in a side by side view and will highlight any differences.

How do I list only files and not a folder?

Open the command-line shell and write the 'ls” command to list only directories. The output will show only the directories but not the files. To show the list of all files and folders in a Linux system, try the “ls” command along with the flag '-a” as shown below.


1 Answers

You can specify -x more than once.

diff -x '*.foo' -x '*.bar' -x '*.baz' /destination/dir/1 /destination/dir/2 

From the Comparing Directories section of info diff (on my system, I have to do info -f /usr/share/info/diff.info.gz):

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'.

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'.

like image 188
Dennis Williamson Avatar answered Sep 28 '22 03:09

Dennis Williamson