• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >Android > sed 替换、修改链接文件注意问题

sed 替换、修改链接文件注意问题

作者:网友 字体:[增加 减小] 来源:互联网 时间:2017-05-26

网友通过本文主要向大家介绍了sed替换文件内容,sed 替换,linux sed替换,sed 替换字符串,shell sed替换等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

sed 替换、修改链接文件注意问题



  1. sed 替换、修改链接文件注意问题

  2. #系统与版本
  3. [root@localhost ~]# cat /etc/redhat-release
  4. CentOS release 6.8 (Final)
  5. [root@localhost ~]# sed --version
  6. GNU sed version 4.2.1
  7. Copyright (C) 2009 Free Software Foundation, Inc.
  8. This is free software; see the source for copying conditions. There is NO
  9. warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
  10. to the extent permitted by law.

  11. 因为sed -i /etc/sysconfig/selinux(selinux文件是/etc/selinux/config的软链接)配置文件重启SELINUX没有关闭,才发现原来sed -i是不能直接修改软链接文件的,如下我修改之后的后果:
  12. [root@localhost ~]# ll /etc/sysconfig/selinux
  13. lrwxrwxrwx. 1 root root 17 Dec 20 11:31 /etc/sysconfig/selinux -> ../selinux/config
  14. [root@localhost ~]# ll /etc/selinux/config
  15. -rw-r--r--. 1 root root 458 Dec 20 11:31 /etc/selinux/config


  16. [root@localhost ~]# sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux
  17. [root@localhost ~]# ll /etc/sysconfig/selinux
  18. -rw-r--r--. 1 root root 457 Dec 22 19:18 /etc/sysconfig/selinux

  19. 我们发现链接文件不再是链接文件了,后来查看sed --help选项时发现如下选项说明

  20. --follow-symlinks
  21. follow symlinks when processing in place; hard links will still be broken.

  22. -i[SUFFIX], --in-place[=SUFFIX]
  23. edit files in place (makes backup if extension supplied). The default operation mode is to
  24. break symbolic and hard links. This can be changed with --follow-symlinks and --copy.

  25. -c, --copy
  26. use copy instead of rename when shuffling files in -i mode. While this will avoid breaking
  27. links (symbolic or hard), the resulting editing operation is not atomic. This is rarely the
  28. desired mode; --follow-symlinks is usually enough, and it is both faster and more secure.



  29. #测试
  30. [root@localhost ~]# echo "test" >>test
  31. [root@localhost ~]# ln -s test test-zsq
  32. [root@localhost ~]# ll -i test-zsq #链接文件
  33. 260727 lrwxrwxrwx. 1 root root 4 Dec 22 19:21 test-zsq -> test
  34. [root@localhost ~]# cat test-zsq
  35. test

  36. #如果直接-i删除,链接文件将失效
  37. [root@localhost ~]# sed -i "s/test//g" test-zsq
  38. [root@localhost ~]# ll -i test-zsq
  39. 260726 -rw-r--r--. 1 root root 1 Dec 22 19:29 test-zsq

  40. #重新添加再测试,加上-c选项
  41. [root@localhost ~]# rm -rf test-zsq
  42. [root@localhost ~]# ln -s test test-zsq
  43. [root@localhost ~]# ll -i test-zsq
  44. 260726 lrwxrwxrwx. 1 root root 4 Dec 22 19:33 test-zsq -> test
  45. [root@localhost ~]# echo "test" >>test
  46. [root@localhost ~]# sed -i -c '/test/d' test-zsq
  47. [root@localhost ~]# ll -i test-zsq
  48. 260726 lrwxrwxrwx. 1 root root 4 Dec 22 19:33 test-zsq -> test

  49. #--follow-symlinks选项
  50. [root@localhost ~]# rm -rf test-zsq
  51. [root@localhost ~]# ln -s test test-zsq
  52. [root@localhost ~]# echo "test" >> test
  53. [root@localhost ~]# cat test
  54. test
  55. [root@localhost ~]# sed -i --follow-symlinks '/test/d' test
  56. [root@localhost ~]# ls -l test-zsq
  57. lrwxrwxrwx. 1 root root 4 Dec 22 19:50 test-zsq -> test
  58. [root@localhost ~]# cat test


  59. --follow-symlinks比-c选项更快更安全
  60. -c, --copy
  61. use copy instead of rename when shuffling files in -i mode.
  62. While this will avoid breaking links (symbolic or hard), the
  63. resulting editing operation is not atomic. This is rarely
  64. the desired mode; --follow-symlinks is usually enough, and
  65. it is both faster and more secure.


  66. 链接文件/etc/rc.local也是/etc/rc.d/rc.local的软连接,用sed添加删除启动服务要特别注意
  67. 有可能配置的链接文件失效而导致服务起不来


  68. 在centos 5.x系列中运行相同的操作没有出现类似的现象
  69. 经查是sed的版本不同造成的影响,centos 5系列的还是使用老版本的sed,没有--follow-symlinks类似的选项

  70. [root@DNS ~]# sed --version
  71. GNU sed version 4.1.5
  72. Copyright (C) 2003 Free Software Foundation, Inc.
  73. This is free software; see the source for copying conditions. There is NO
  74. warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
  75. to the extent permitted by law.
  76. [root@DNS ~]# sed --help
  77. Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...

  78. -n, --quiet, --silent
  79. suppress automatic printing of pattern space
  80. -e script, --expression=script
  81. add the script to the commands to be executed
  82. -f script-file, --file=script-file
  83. add the contents of script-file to the commands to be executed
  84. -i[SUFFIX], --in-place[=SUFFIX]
  85. edit files in place (makes backup if extension supplied)
  86. -c, --copy
  87. use copy instead of rename when shuffling files in -i mode
  88. (avoids change of input file ownership)
  89. -l N, --line-length=N
  90. specify the desired line-wrap length for the `l' command
  91. --posix
  92. disable all GNU extensions.
  93. -r, --regexp-extended
  94. use extended regular expressions in the script.
  95. -s, --separate
  96. consider files as separate rather than as a single continuous
  97. long stream.
  98. -u, --unbuffered
  99. load minimal amounts of data from the input files and flush
  100. the output buffers more often
  101. --help display this help and exit
  102. --version output version information and exit

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • sed 替换、修改链接文件注意问题

相关文章

  • 2017-05-26国外干货!6个方法助你设计出优秀的APP,干货app
  • 2017-05-26Android 拨号器的简单实现,android拨号器实现
  • 2017-05-26充值,充值平台
  • 2017-05-26[Android学习]ListView显示多种item的处理办法
  • 2017-05-26android studio 使用checkstyle全攻略
  • 2017-05-222.3.2 EditText(输入框)详解
  • 2017-05-26Android 判断当前语言环境是否是中文环境,android中文
  • 2017-05-26[android] 手机卫士读取联系人,android卫士
  • 2017-05-26DroidPlugin插件化开发,droidplugin插件
  • 2017-05-26安卓高级组件-----网格视图,安卓-----网格

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • Android—ZXing二维码扫描遇到的问题,androidzxing
    • 我的android学习经历16,android学习经历16
    • 活动的生命周期系列(一)返回栈,生命周期系列
    • Android安全专项-AndBug动态调试工具环境搭建
    • Android中Intent在Activity之间传递对象[Serializable或Parcelable]
    • android单选按钮RadioGroup的详细使用
    • Android 动画资源 详解
    • android:configChanges属性总结,
    • android 之 启动画面的两种方法,android两种方法
    • Android与HTML+JS交互入门

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有