How to tar certain file types in all subdirectories?

后端 未结 7 1425
闹比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 22:52

    tar -cf my_archive `find ./ | grep '.php\|.html'`
    

    Use "find" and "grep" to get all path of .php and .html files in all directory and its sub-directories. Then pass those path information to tar to compress.

    Please be careful with those symbol ` and '. Note also that this will hit the limit of how many characters your shell will allow on the command line, unlike some of the other answers.

提交回复
热议问题