Empty File in CentOS: 3 Quick Methods
To clear the content of a file, you can use the following methods:
- Use the “>” symbol to redirect empty content into a file.
> 文件名
This will clear the contents of the file and create a new file if it doesn’t exist.
- Use the “truncate” command to empty the content of a file.
truncate -s 0 文件名
This will truncate the file and set its size to 0, thus clearing the file content.
- Write empty content to a file using the “echo” command.
echo -n > 文件名
This will write an empty content to the file and clear its contents.
Please be aware that clearing the file content will delete all data in the file, so please proceed with caution.