1

When attempting to run

find . -iname "*.gz" -mtime +7 -exec tar czvf all_gizip_$(date +%Y-%m-%d).tar.gz {} \;

I get the list of files

./corosync.log-20140620.gz
./corosync.log-20140618.gz
./rgmanager.log-20140620.gz
./fenced.log-20140620.gz
./rgmanager.log-20140618.gz
./qdiskd.log-20140618.gz

But the archive only gets the last item

 tar -tvf all_gizip_$(date +%Y-%m-%d).tar.gz
-rw-r--r-- root/root       506 2014-06-18 03:21 ./qdiskd.log-20140618.gz

What am I doing wrong?

2
  • It looks like the find is limiting to the last 7 days, do the files meet that criteria?
    – Tyson
    Commented Aug 15, 2014 at 15:34
  • Yes Tyson. Log rotate creates the .gz to start with. I need to run the second in cron to take all gz's and put them into a single gz and then move them off to archive. jjlin gave me the correction to my original. Commented Aug 15, 2014 at 19:56

1 Answer 1

0

Your command is running tar once for each file, and each call to tar creates an output of the same name, thus overwriting the previous output. So you end up with only the last file. You need something like

find . -iname "*.gz" -mtime +7 | xargs tar czvf all_gizip_$(date +%Y-%m-%d).tar.gz

This should work fine as long as your list of files isn't huge. If it is, then you'll probably want to switch to using tar rvf and doing a separate gzip step at the end.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .