zoukankan      html  css  js  c++  java
  • 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/sh
    touch /var/lock/subsys/local
    route add default gw 192.169.1.1
    service iptables stop
    echo "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/sh
    touch /var/lock/subsys/local
    route add default gw 192.169.1.1
    service iptables stop
    echo "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/sh
    touch /var/lock/subsys/local
    route add default gw 192.169.1.1
    service iptables stop
    echo "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/sh
    touch /var/lock/subsys/local
    route add default gw 192.169.1.1
    service iptables stop
    echo "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/sh
    touch /var/lock/subsys/local
    route add default gw 192.169.1.1
    service iptables stop
    echo "jane test line"
    

    如上所看到的,使用“sed -i "/hosfore/s//jane/" /etc/rc.local ”命令改动文件之后,发现这个文件变成普通文件了 ,查询sed的使用手冊,可知,假设须要保持软硬链接属性,改动的时候须要加上相应參数:

    man sed
    
    DESCRIPTION
           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.

  • 相关阅读:
    android中实现监听的四种方法
    Jpgraph小应用
    正则表达式的初运用-认证界面
    Oracle案例04——TNS-12547: TNS:lost contact
    通过触发器记录数据库连接信息
    MySQL案例02:ERROR 1221 (HY000): Incorrect usage of DB GRANT and GLOBAL PRIVILEGES
    Oracle案例04——ORA-39700: database must be opened with UPGRADE option
    Oracle案例03——RMAN-06091: no channel allocated for maintenance (of an appropriate type)
    Xwiki安装部署详解
    MySQL案例01:Last_SQL_Errno: 1755 Cannot execute the current event group in the parallel mode
  • 原文地址:https://www.cnblogs.com/yangykaifa/p/6851630.html
Copyright © 2011-2022 走看看