method 1:
In the non-editing state, use the shortcut key gg to jump to the head of the first line, and then use dG to clear it, or enter "%d" to clear it, and then save it. But when the file content is large, the processing is slower.
Method 2:
cat /dev/null > /var/log/yum.log (replace with the file name that needs to be cleared) or cp /dev/null access.log
Method 3:
> /var/log/yum.log (replaced with the file name that needs to be cleared)
Method 4:
: > access.log 或
true > access.log
Method 5:
Use the echo command to clear, and a blank line "\n" will be written in the file at this time,
echo "" > access.log 或者 echo > access.log 或echo -n "" > access.log
Method 6:
truncate can be used to shrink or expand a file to a given size. You can use it with the -s parameter to specify the size of the file. To clear the contents of the file, set the file size to 0 in the following command:
truncate -s 0 access.log