Clean up individual files, so you can: Echo > MyLog.log
But what if I want to clean up a bunch of files, such as all the contents of a file that ends with. Log in the/logs directory, without deleting the file?
The first statement I had was this:
Find/logs-name "*.log"-exec echo > {} \;
However, the result of the run is a new file named "{}" and no action to clean up the contents of the file.
After I inquired about the great God, my statement was this:
For I in ' find. -name "*.log"; Do cat/dev/null > $i; Done
The above statement is to be executed in the current directory, that is, to jump to/logs to execute this statement.
This statement can also be: for I in ' find. -name "*.log"; do echo > $i; Done
However, the clean file executed with echo > is not completely empty, but has a size of 4 K, and the file content with Cat/dev/null > cleanup is exactly 0.
Linux bulk cleans up multiple file contents without deleting files