How to turn off the overwrite output redirection (>) feature in a Linux system

Source: Internet
Author: User

First, the problem description

We often use the file operation to overwrite the output redirect (>), append output redirection (>>), it is obvious that the two output redirection symbol difference is not very large, but the meaning of the two is a big difference: The former will overwrite the contents of the file , the latter will not overwrite the contents of the file! When we use append output redirection, we are most likely to use overwrite redirection due to our own carelessness, which results in the loss of file content, but the Linux system can still solve this problem.


Second, the problem demonstration

[Email protected]~]# echo "Cangls" >/root/test.txt [[Email protected]~]# cat/root/test.txt Cangls[[email protected] ~]# echo "Longls" >/root/test.txt [[Email protected]~]# cat/root/test.txt longls[[email protected]~]# echo ' Cangls ' & gt;>/root/test.txt [[Email protected]~]# cat/root/test.txt Longlscangls


It is obvious from the above example that using > Overwrite output redirection will delete the contents of the file Test.txt, while using the >> append output redirect will not lose the contents of the file, the following describes how to use the tips to eliminate the problem as much as possible.


Third, the use of skills

SET-C: Prohibit overwrite redirect to existing file

Set +c: Turn off the above features:

>|: Force overwrite redirection under-C feature

[[Email protected]~]# set-c [[Email protected]~]# echo ' xiaozels ' >/root/test.txt-bash:/root/test.txt:cannot overw Rite existing File[[email protected]~]# echo "Xiaozels" >>/root/test.txt [[Email protected]~]# cat/root/test.txt L Onglscanglsxiaozels[[email protected] ~]# echo "Xiaozels" >|  /root/test.txt [[email protected] ~]# cat/root/test.txt xiaozels[[email protected] ~]# set +c [[email protected] ~]# Echo "Bols" >/root/test.txt [[Email protected]nux ~]# cat/root/test.txt Bols



The above example can be seen using the set-c command to override the output redirection function to close, but sometimes to use this function to do? Obviously you can use the set +c command, but what if we forget to shut it down? Obviously the system still has a corresponding method, that is, in the use of overlay redirection after adding a | symbol can continue to use the Override redirection function. Finally in the future encounter class is can change the contents of the command must be careful! Do not cause unnecessary consequences for your momentary carelessness!





This article is from the "Bread" blog, make sure to keep this source http://cuchadanfan.blog.51cto.com/9940284/1670308

How to turn off the overwrite output redirection (>) feature in a Linux system

Related Article

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.