How to Compress Old Log Files into Single Zip on Linux

findgzipshelltar

I have a folder /home/testuser/log which contain log files of one day old *.log. I wish to compress all the log files older than one day to a single zip(gzip or tar.gz) and delete the older files.

I tried to pipeline find and tar commands but didn't work

Best Answer

Create tar.gz files older than one day logs

find /home/testuser/log/ -mtime +1 | xargs  tar -czvPf  /opt/older_log_$(date +%F).tar.gz

Delete older files [ Note:- if below find output is Correct then remove echo , after that it will delete those files]

find /home/testuser/ -mtime +1 | xargs  -n1 echo rm
Related Question