What is truncate command Linux? The truncate command is used to shrink or extend the size of a file to the given size. The truncate command cannot remove the file whereas removes the contents of the file and set size of file is zero byte. The meaning of truncate is reducing.
How do you truncate text in Linux?
- The : colon means true and produces no output.
- The redirection operator > redirect the output of the preceding command to the given file.
- filename , the file you want to truncate.
How do I truncate a log file in Linux? You can simply truncate a log file using > filename syntax. For example if log file name is /var/log/foo, try > /var/log/foo as root user.
How do I truncate a file to zero in Linux? The extra information has been deleted by the truncate command. You can also use other units, such as K for kilobytes, M for megabytes, G for gigabytes, etc. To empty the file completely, use -s 0 in your command.