tar and the compression utilities:
find . -type f -name bigfile | tar cfz bigfile.tgz -T -
find . -type f -name bigfile | tar cfJ bigfile.txz -T -
find searches recursively for all files named
bigfile under the current/working directory and the resulting pathnames are supplied to
tar that creates a tarball and compresses it.
These commands are suited for the example supplied in the question. Different patterns supplied to
zip -R will require corresponding arguments supplied to
Also keep in mind that this won't work for all possible filenames; you should consider the --null option and feed tar from find -print0.
tar's "-T" option is not available on every systems (for instance in HP-UX).
Unlike zip, rar or 7-zip, for example, gzip and xz are not capable of compressing multiple files into one.
Quoting the gzip manpage:
If you wish to create a single archive file with multiple members so that members can later be extracted independently, use an archiver such as tar or zip. GNU tar supports the -z option to invoke gzip transparently. gzip is designed as a complement to tar, not as a replacement.
See How to gzip multiple files into one gz file? and How do I compress multiple files into a .xz archive?.
If the goal of the OP is to make a gzip file for each file it finds that satisfies the search criteria the following command should be issued:
find . -type f -name bigfile | gzip > bigfile.gz
For a xz file:
find . -type f -name bigfile | xz > bigfile.xz
It will create a compressed file in the same directory for each file that satisfies the search criteria leaving the original file "untouched".
As suggested by @Kusalananda, if in
bash you first do:
shopt -s globstar
and then issue the command:
tar -c -zf bigfile.tgz ./**/bigfile
a single archive file will be created with the multiple files found in subdirectories that satisfies the search criteria.
If the goal is to create one compressed file for each file found in subdirectories that satisfies the search criteria, after issuing the
shopt command, you can just issue: