I am using the following script to create a tarball of a directory with php
exec("tar -zcvf archive_name.tar.gz *");
and this is working as expected, but I would like to extend this code so that it will only add files to the tarball that have a certain extension (*.log in this case) then delete the originals after the tarball has been created. Any advise or examples would be great.
TIA,
Kevin
You can change you command to:
Changes made:
Instead of passing all file (
*) asargument to
tarwe now pass*.logAdded
&& rm -f *.log. The commandrm -f *.logforcefully deletes all.logfiles from the present workingdirectory. We’ve used an
&&as theglue between the two commands because
we want the files to be deleted only
after the tarball is created.