Emptying a log file in Linux
How to clean a log file in Linux? – Over time it gets necessary to truncate log files. Expanding log files may not be easy to read. In Linux emptying a log file is easily achieved by issuing some basics commands. To remove or truncate a file, we can use /dev/null, which is utilized to discard text.
Be sure NOT to clean ANY file. Some files may be needed and should not be truncated.
To truncate or clean up a log file, do following:
[su_note]linux# cat /dev/null > [logfle] [/su_note]You can use alternative methods to achieve same result:
[su_note]linux# : > [logfile] (: is semicolon)[/su_note] [su_note]linux# true > [logfile][/su_note] [su_note]linux# cp /dev/null [logfile][/su_note] [su_note]linux# dd if=/dev/null of=[logfile][/su_note] [su_note]linux# echo “” > [logfile][/su_note]
Add Comment