Tip TuesdayLinux is a great operating system for servers. Coincidentally, I run a local linux server and as everyone should know… disk space matters! That’s where today’s quick fix comes in! As a server owner, you will quickly realize how important every little kilobit is when it comes to keeping your server in order.

If you are curious how large your log space is you may run du -hs /var/log

Heres how to compress and backup all your logs to /root/logs-(date).tar.bz2 and wipe all the data out of all the files in /var/log.

  1. Open up a CLI (terminal)
  2. tar -cjf /root/logs-`date +%d%m%y`.tar.bz2 /var/log
  3. find /var/log -type f | xargs sed ‘/^/d’ -i
    • Red: This part of the command will send the path of all the files in /var/log to stdout(the screen)
    • Blue: The xargs command allows us to perform an operation on everything in stdout, as from the previous command displays all the file names, this will let us “merge” a command with the filenames.
    • Green: sed is a streamline editor, basically it will allow us to perform a regular expression. In this case we are deleting all the lines from a file

Related Posts

Got a question? Ask it here

Please link the tutorial in your question. You may go to the questions section of our forums to view any question answered, including yours!