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 don't want. If I use
tar -cf my_archive *.php *.html
it ignores subdirectories. How can I make it tar recursively but include only two types of files?
To compress a single file by running tar -zcvf file. tar. gz /path/to/filename command on Linux. Tar and compress multiple directories file by running tar -zcvf file.
If your system uses GNU tar , you can use tar in conjunction with the gzip file compression utility to combine multiple files into a compressed archive file. Note: In the above examples, the -z option tells tar to use gzip to compress the archive as it is created. The file extensions .
find ./someDir -name "*.php" -o -name "*.html" | tar -cf my_archive -T -
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With