Sed connection file repair, pitfall, sed

Source: Internet
Author: User

Sed connection file repair, pitfall, sed

-bash-4.1# ll /etc/rc.local lrwxrwxrwx. 1 root root 13 Aug 15  2014 /etc/rc.local -> rc.d/rc.local
-bash-4.1# cat /etc/rc.local #!/bin/shtouch /var/lock/subsys/localroute add default gw 192.169.1.1service iptables stopecho "hosfore test line"
</pre><pre code_snippet_id="684937" snippet_file_name="blog_20150605_4_1032646" name="code" class="cpp" style="color: rgb(68, 68, 68);">-bash-4.1# sed -i "/hosfore/s//jane/" /etc/rc.local -bash-4.1# cat /etc/rc.local #!/bin/shtouch /var/lock/subsys/localroute add default gw 192.169.1.1service iptables stopecho "jane test line"
</pre><pre code_snippet_id="684937" snippet_file_name="blog_20150605_6_4535175" name="code" class="cpp"><span style="color:#ff0000;">-bash-4.1# ll /etc/rc.local -rwxr-xr-x 1 root root 300 Jun  5 09:47 /etc/rc.local-bash-4.1# cat /etc/rc.d/rc.local #!/bin/shtouch /var/lock/subsys/localroute add default gw 192.169.1.1service iptables stopecho "hosfore test line"</span>
</pre><pre code_snippet_id="684937" snippet_file_name="blog_20150605_8_4167031" name="code" class="cpp">-bash-4.1# rm /etc/rc.local -bash-4.1# ln -s /etc/rc.d/rc.local /etc/rc.local-bash-4.1# ll /etc/rc.local lrwxrwxrwx 1 root root 18 Jun  5 09:51 /etc/rc.local -> /etc/rc.d/rc.local-bash-4.1# cat /etc/rc.local #!/bin/shtouch /var/lock/subsys/localroute add default gw 192.169.1.1service iptables stopecho "hosfore test line" 
-bash-4.1# sed -i <strong>--follow-symlinks</strong> "/hosfore/s//jane/" /etc/rc.local-bash-4.1# ll /etc/rc.local lrwxrwxrwx 1 root root 18 Jun  5 09:51 /etc/rc.local -> /etc/rc.d/rc.local-bash-4.1# cat /etc/rc.d/rc.local #!/bin/shtouch /var/lock/subsys/localroute add default gw 192.169.1.1service iptables stopecho "jane test line"

As shown above, use "sed-I"/hosfore/s // jane/"/etc/rc. after the local command modifies the file, it is found that the file has become a common file. After querying the sed user manual, we can see that if you need to keep the soft and hard Link Attributes, you need to add the corresponding parameters when modifying the file:

man sedDESCRIPTION       Sed  is  a  stream editor.  A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline).  While in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over the input(s), and is consequently more efficient.  But it is sed's ability to filter text in a pipeline which particularly distinguishes it from other types of editors.       --follow-symlinks            follow symlinks when processing in place; hard links will still be broken.       -i [SUFFIX], --in-place[=SUFFIX]            edit  files in place (makes backup if extension supplied).  The default operation mode is to break symbolic and hard links.  This can be changed with --follow-symlinks and --copy.       -c, --copy            use copy instead of rename when shuffling files in -i mode.  While this will avoid breaking links (symbolic or hard), the resulting editing operation is not atomic.  This is rarely the desired mode; --follow-symlinks is usually enough, and it is both faster and more secure.

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.