If you want to keep the full content of the existing files you will need to compress them to some temporary space elsewhere and then replace each uncompressed file with its compressed equivalent. Otherwise just delete the older log files or archive them elsewhere.
Here is a proposal to compress the log files without losing their contents. However, you need to be aware that if you keep growing log files it will only defer the problem of your filesystem filling up and not resolve it permanently.
Identify the older files that are to be compressed. (None of these must be in use or open right now for logging.) In my example this is
Identify a chunk of filesystem that can hold the largest of these uncompressed files. In my example I'm going to assume this is
In your real-world scenario you can use a
for loop to iterate across a series of files. Here are the steps for a single file:
logfile='/var/log/big1.log' # The logfile to be compressed
if gzip -c "$logfile" >/home/log.gz
touch --reference "$logfile" /home/log.gz # Capture timestamp of last update
chown --reference "$logfile" /home/log.gz # Capture ownerships
chmod --reference "$logfile" /home/log.gz # Capture permissions
rm -f "$logfile" # Make space
mv -f /home/log.gz "$logfile.gz" # Rename with correct suffix