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

前端 未结 9 1450
囚心锁ツ
囚心锁ツ 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:53

    The lack of a complementary --include makes it necessary to use such convoluted heuristic patterns as

    *.[A-Zb-ik-uw-z]*
    

    to find (mostly) java files!

    0 讨论(0)
  • 2021-01-31 13:56

    You can also use find with -exec to call diff:

    cd /destination/dir/1
    find . -name *.xml -exec diff {} /destination/dir/2/{} \;
    
    0 讨论(0)
  • 2021-01-31 13:56

    The lack of a complementary --include ... .

    We can do one workaround, a exclude file with all files but what we want include. So we create file1 with a find all files which don't have extensions that we want include, sed catch the filename and is just :

    diff --exclude-from=file1  PATH1/ PATH2/
    

    For example:

    find  PATH1/ -type f | grep --text -vP "php$|html$" | sed 's/.*\///' | sort -u > file1 
    diff PATH1/ PATH2/ -rq -X file1 
    
    0 讨论(0)
提交回复
热议问题