Compress All Log Files

I decided to start being more active with this blog.  I’ve always wanted a personal indexer for all the things I learn in Linux or software development.  Might as well make this blog that index.

So, you want to gzip all the log files in a particular directory right?  Well, you better be sure that you’re not doing that to live files, so just check them with lsof…

find /var/log/somefolder -type f | while read -r file; do lsof "$file"; if [ $? -eq 1 ]; then gzip "$file"; fi; done

Leave a Reply

Your email address will not be published. Required fields are marked *