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

前端 未结 9 1447
囚心锁ツ
囚心锁ツ 2021-01-31 13:15

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

9条回答
  •  北恋
    北恋 (楼主)
    2021-01-31 13:38

    Taken from ( a version of) the man page:

    -x PAT  --exclude=PAT
      Exclude files that match PAT.
    
    -X FILE    --exclude-from=FILE
      Exclude files that match any pattern in FILE.
    

    So it looks like -x only accepts one pattern as you report but if you put all the patterns you want to exclude in a file (presumably one per line) you could use the second flag like so:

    $ diff /destination/dir/1 /destination/dir/2 -r -X exclude.pats
    

    where exclude.pats is:

    *.jpg
    *.JPG
    *.xml
    *.XML
    *.png
    *.gif
    

提交回复
热议问题