The tar command is the de facto tool for compressing files to be later sent through e-mail or over the network in one file. As a matter of fact, tar does not technically compress files; it only groups them in one .tar file. If you want to further compress this file, you can use the famous gzip tool. For example,
Tar generally works as follows:
tar -cvf myfile.tar file1 file2 file3 fileX
But that's when you have only a bunch of files that are of known names to you. What if you want to tar dozens or even hundreds of files based on a certain criteria?
You can combine tar with the find command to selectively tar files. The find command (in its simplest form) works as follows:
find /path/to/directory -type f -name *name*
So, let's say that you want to find all the files that end in .log in /var/www/log. You are not interested in .log.1 or .log.old for example, only .log. A find command like the following may do the job:
find /var/www/log -type f -name '*.log'
That will list all the files that end in .log. Now, if you want to tar those files, you can add the tar command as follows:
tar -cvf logs.tar $(find /var/www/log -type f -name '*.log')
Notice the use of $(), which will execute any commands inside it and return the result. The result is further processed by tar to create logs.tar file.
Finally, you can compress this file using gzip as follows: