How do I clear a log file that is currently in use?

12,338

Are there many methods how clear/delete log files. Some of log you can delete, some not and some you can truncate.

For linux system log (such as mail.log for example) I use this method. Steps 1 and 2 are optional, but sometines you need check older logs and backup is sometimes useful. ;-)

  1. Optional: Copy log file

    cp file.log file.log.old
    
  2. Optional: Use Gzip on copy of log

    gzip file.log.old
    
  3. Use /dev/null for clean file

    cat /dev/null > file.log
    
Share:
12,338

Related videos on Youtube

Dreamracer
Author by

Dreamracer

Updated on September 18, 2022

Comments

  • Dreamracer
    Dreamracer over 1 year

    I'm trying to clear a log file in use, and all the commands I've tried so far:

    truncate
    less
    tail
    filename
    

    Don't get the job done. Deleting the file and creating a new file with the same name doesn't work either.

    I heard about a config-file for the log but I have no idea where this is kept. Is there ANY way to fix this problem? This log file will get so big it'll crash my system.

    • joeguarino
      joeguarino over 11 years
      Which log file, and what was the error message?