Ubuntu

Ubuntu – clear all log files

If you want to clear all your log files, not just those in the first-level log folder, you could use:

shopt -s globstar                  # if needed
truncate -s 0 /var/log/*.log       # first-level logs
truncate -s 0 /var/log/**/*.log    # nested folders, like /var/log/nginx/access.log

Noting that if you already have logrotate running, you’ll need to clear out the rotated .gz logs as well:

find /var/log -type f -name '*.[0-99].gz' -exec rm {} +

A valid use for this could be building a VM appliance container for distribution, for example.

You should not need to do this as part of routine maintenance: as D-E-M quite correctly suggested, use logrotate for that.

13 thoughts on “Ubuntu – clear all log files
  1. It’s impressive that you are getting thoughts from this post as well as
    from our argument made at this place.

  2. What’s up to every one, it’s genuinely a good for me to pay a visit this
    site, it contains precious Information.

  3. Thanks for ones marvelous posting! I quite enjoyed reading it, you’re a great author.
    I will remember to bookmark your blog and will eventually come back in the
    future. I want to encourage you to definitely continue your great
    writing, have a nice weekend!

  4. It’s actually a great and helpful piece of info.
    I’m happy that you just shared this useful information with us.
    Please stay us informed like this. Thanks
    for sharing.

  5. Hey! I realize this is kind of off-topic however I had
    to ask. Does building a well-established website like yours require a large amount of work?
    I am brand new to running a blog but I do write in my
    journal daily. I’d like to start a blog so I can easily share my own experience
    and views online. Please let me know if you have any recommendations or tips for brand
    new aspiring blog owners. Thankyou!

  6. Undeniably consider that that you said. Your favorite justification appeared to be on the
    web the easiest factor to be aware of. I say to you, I
    definitely get annoyed while other folks think about worries that they just don’t
    know about. You managed to hit the nail upon the highest as
    well as defined out the entire thing without having side-effects , other folks could take
    a signal. Will probably be back to get more. Thanks

Leave a Reply

Your email address will not be published.