Sunday, February 04, 2007

Linux: Truncate A File

There is a simple command that will truncate the file to zero length without affecting any permissions. Here it is:
shell>:>filename
If the file already exists, it will be truncated to zero bytes, else this command will create an empty file. This is handy for truncating big log files.

Or you can use:

shell>cat /dev/null > some_log_file.log



No comments: