How to archive log files in Linux?

Published on Aug. 22, 2023, 12:17 p.m.

To archive log files in Linux, you can use the tar command. Here’s an example of how to create a compressed archive of log files in a directory:

tar -czvf logs.tar.gz /path/to/logs

In this example:

  • -c specifies that we want to create a new archive
  • -z specifies that we want to compress the archive using gzip
  • -v specifies that we want to see the names of the files as they’re added to the archive
  • -f specifies the filename of the archive
  • logs.tar.gz is the name of the archive file we’re creating
  • /path/to/logs is the directory containing the log files we want to archive

Once you’ve created the archive, you can move it to another directory or to an external storage device to free up space on your system. Keep in mind that you’ll need to periodically delete old archives that are no longer needed to free up storage space.

Tags:

log