Linux bulk cleans up multiple file contents without deleting files

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.