How to tar certain file types in all subdirectories?

后端 未结 7 1444
闹比i
闹比i 2020-12-22 22:30

I want to tar and all .php and .html files in a directory and its subdirectories. If I use

tar -cf my_archive *

it tars all the files, which I

7条回答
  •  庸人自扰
    2020-12-22 23:12

    If you're using bash version > 4.0, you can exploit shopt -s globstar to make short work of this:

    shopt -s globstar; tar -czvf deploy.tar.gz **/Alice*.yml **/Bob*.json
    

    this will add all .yml files that starts with Alice from any sub-directory and add all .json files that starts with Bob from any sub-directory.

提交回复
热议问题