When working with large log files, it can be difficult to open or analyze them. In such cases, you may need to clear the content of existing log files to make space for fresh log data.
There are several safe and effective ways to truncate or empty log files in Linux.
Methods to Clear Log Files
- : > application.log – Redirects nothing into the file, effectively clearing it.
- cat /dev/null > application.log – Writes an empty stream into the file.
- truncate -s 0 application.log – Sets the file size to zero without deleting it.
Clear Multiple Log Files
To empty all log files ending with .log inside a directory, you can use:
sudo truncate -s 0 /<directory-path>/**/*.log
Tip: Always back up important logs before clearing them, as this process permanently removes the file content.
Search
Categories
Recent Posts
Top 10 Free Audio Generation AI Tools in 2025
Top 10 Free Video Generation AI Tools in 2025
Top 10 Free Image Generation AI Tools in 2025
Top 10 Free Text-Based AI Tools in 2025
Top Git interview Questions for Experienced Developer
Recent Tags