i want to truncate the log file which is already in use ( log is getting appended) . After that i want to make sure log is still getting appeneded after performing truncate. I have been using below command for the same but don't see it is happening.

truncate -s 0 rosout.log

i belive it should truncate the log file contents and after that append the new one.
even it will be helpfull if i can specify how many contents i would be able to truncate.

truncate -s 1M rosout.log

Recommended Answers

All 2 Replies

As I have said to others, use logrotate. See the man page for logrotate and logrotate.conf usage. That will let you do exactly what you want.

Also depending on how much you're changing the size, it would be possible to have a smaller file size and still use the same amount on the hard drive, due to the way your OS has structured the file system.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.