How to empty files in Linux

Source: Internet
Author: User

Often encounter the view log file, if the log file is too large, with the Less,more,vi,tail command to view it will be more troublesome, but also very difficult to locate specific errors, and regular backup, regular emptying should be a good idea, of course, must be backed up before emptying. If the log file itself does not exist, with mkdir can build an empty file, but the system program is already in the call, then how to empty the file, in fact, quite simple:

Method One:

# Cat/dev/null > Error.log
Method Two:

# echo "" | Tee Error.log

Method Three:

# truncate-s Error.log


Note:

# echo/dev/dull > Error.logbash:error:cannot Overwrite existing file
If you encounter this error when writing a file, that's because the noclobber switch is turned on. If you want to eliminate the above error, there are two ways:

Method One:

# set +o noclobber;                -Off noclobber items # Set-o | grep nocl               //--> view Noclobber     off
Method Two:
# echo "ORA1001: ..." >| Error.log  //--> This is the notation in bash, and if it's csh, use >! filename# cat error.logora1001: ...


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.