I have script for finding files of certain type and compress them to a single tar archive and put in to other place. But now, there is a change in requirement, that I need to find files of certain type, list it and compress each of them to a tar archive and put it to other place. Currently I'm using the script
cd /to/top/of/dir/structure
tar -cf /path/to/tarfile.tar --files-from /dev/null # trick to create empty tar file
find . -type f ! -name '*.log' -print0 | xargs -0 tar -uvf /path/to/tarfile.tar
which I have taken from this post : https://superuser.com/questions/436441/copy-every-file-with-a-certain-extension-recursive
So, the above script find certain file type and then archive it as single tar file and then place it to another location. But my question is, I need to find files of certain type, list them, tar each of the listed files and put them into other location.
I'm going with...
...but I haven't tested it.
And I'm really dubious it will be what you really need...
Edit
I can get it as far as...
...to output the commands you would want to run.
I'm still working on executing those commands, short of
-fprint
ing to a temp file,chmod +x
and executing that.Not to mention dealing with any issues escaping awkward characters in filenames.
Edit #2
OK, I can't get it down to one line (which was my challenge, not yours), but I can get it into a fairly simple script:
Without a pipe (or xargs), creating several tar files instead of just one, and deleting the non-compressed files, here is how you can do it:
Find the files and build a list, tell tar to make an archive from the list....
Side note: your example doesn't compress the file, it just archives it.
find . -type f ( -name ".php" -o -name ".js" -o -name ".css" -o -name ".crt" -o -name ".htm*" -o -name ".txt" -o -name ".$" -o -name ".xml" -o -name ".ht" ) -print0 | tar -czpf $FILE --null -T -