关于sed -i 修改selinux 的软链接文件的问题
关于sed -i 修改selinux 的软链接文件的问题
http://blog.csdn.net/kumu_linux/article/details/8598005
因为sed -i /etc/sysconfig/selinux(selinux文件是/etc/selinux/config的软链接)配置文件重启SELINUX没有关闭,才发现原来sed -i是不能直接修改软链接文件的,如下我修改之后的后果:
- [root@node1 ~]# ll /etc/sysconfig/selinux
- lrwxrwxrwx. 1 root root 19 2月 20 20:34 /etc/sysconfig/selinux -> /etc/selinux/config
- [root@node1 ~]# sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux
- [root@node1 ~]# ll /etc/sysconfig/selinux
- -rw-r--r-- 1 root root 457 2月 20 22:50 /etc/sysconfig/selinux
- [root@node1 ~]#
我们发现链接文件不再是链接文件了,后来查看sed man选项时发现如下选项说明
--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.
以上说明就不作过多解释了,说的很明显,看下面实例
- [root@node1 ~]# echo "test" >>test
- [root@node1 ~]# ln -s ~/test ~/test_soft
- [root@node1 ~]# ln ~/test ~/test_hard
- [root@node1 ~]# ll -i test*
- 271653 -rw-r--r-- 2 root root 5 2月 20 23:04 test
- 271653 -rw-r--r-- 2 root root 5 2月 20 23:04 test_hard
- 271655 lrwxrwxrwx 1 root root 10 2月 20 23:04 test_soft -> /root/test
- [root@node1 ~]# sed -i "s/test/hard/g" test_hard
- [root@node1 ~]# sed -i "s/test/soft/g" test_soft
- [root@node1 ~]# ll -i test*
- 271653 -rw-r--r-- 1 root root 5 2月 20 23:04 test
- 271656 -rw-r--r-- 1 root root 5 2月 20 23:05 test_hard
- 271657 -rw-r--r-- 1 root root 5 2月 20 23:06 test_soft
- [root@node1 ~]#
很明显如man中所说-i选项对软链接和硬链接都会使受到破坏
- [root@node1 ~]# rm -rf test*
- [root@node1 ~]# echo "test" >>test
- [root@node1 ~]# ln -s ~/test ~/test_soft
- [root@node1 ~]# ln ~/test ~/test_hard
- [root@node1 ~]# ll -i test*
- 271653 -rw-r--r-- 2 root root 5 2月 20 23:08 test
- 271653 -rw-r--r-- 2 root root 5 2月 20 23:08 test_hard
- 271655 lrwxrwxrwx 1 root root 10 2月 20 23:08 test_soft -> /root/test
- [root@node1 ~]# sed -i -c "s/test/soft/g" test_soft
- [root@node1 ~]# sed -i -c "s/test/soft/g" test_hard
- [root@node1 ~]# ll -i test*
- 271653 -rw-r--r-- 2 root root 5 2月 20 23:11 test
- 271653 -rw-r--r-- 2 root root 5 2月 20 23:11 test_hard
- 271655 lrwxrwxrwx 1 root root 10 2月 20 23:08 test_soft -> /root/test
--follow-symlinks选项只对软链接有效,硬链接还是会被破坏,建议使用-c选项,这里就不举例了
后来朋友在RHEL5上运行相同的操作居然没有出现类似的现象,运行结果如下:
- $ echo "test" >> test
- $ ln -s ~/test ~/test1
- $ ll ~/test1
- lrwxrwxrwx 1 sxkj sxkj 15 02-21 13:26 /home/sxkj/test1 -> /home/sxkj/test
- $ sed -i "s/test/test1/g" ~/test1
- $ ll ~/test1
- lrwxrwxrwx 1 sxkj sxkj 15 02-21 13:26 /home/sxkj/test1 -> /home/sxkj/test
经查是sed的版本不同造成的影响,RHEL5系列的还是使用老版本的sed,没有--follow-symlinks类似的选项,笔者之前实验的版本是RHEL6.3,所以出现之前的一系列问题了
关于sed -i 修改selinux 的软链接文件的问题的更多相关文章
- Linux之SElinux安全上下文件(1)
SELinux:Secure Enhanced Linux,是美国国家安全局(NSA=The National Security Agency)和SCC(Secure Computing Courpo ...
- sed 's/AA/BB/' file # 将文件中的AA替换成BB,只替换一行中第一次出现的AA,替换后的结果输出到屏幕 sed 's/AA/BB/g' file # 将文件中的所有AA都替换成BB,替换后的结果输出到屏幕
生信人的自我修养:Linux命令速查手册 简佐义 四川大学 生物信息学硕士 科学求真 赢 10 万奖金 · 院士面对面 209 人赞同了该文章 许多人做生物信息学,要么不重视Linux,要么不知道 ...
- Tomcat编码问题及访问软链接文件设置
Tomcat编码问题及访问软链接文件设置 一.编码问题:让其支持UTF-8格式 修改tomcat中server.xml Connector port=" protocol="org ...
- centos7 修改selinux 开机导致 faild to load SELinux policy freezing 错误
centos7 修改selinux 开机导致 faild to load SELinux policy freezing 错误 之前把selinux关闭了,这次想打开selinux,于是修改了 /e ...
- 特殊权限set_uid /特殊权限set_gid/特殊权限stick_bit/软链接文件/硬连接文件
2.18 特殊权限set_uid 2.19 特殊权限set_gid 2.20 特殊权限stick_bit 2.21 软链接文件 2.22 硬连接文件 特殊权限set_uid(s权限用户user权限) ...
- Linux:自动获取静态IP地址,清空iptable,修改selinux脚本
自动获取静态IP地址,清空iptable,修改selinux脚本 环境:VMware 平台:centos6.8全新 功能: 1)应用ifconfig -a,route -n,cat /etc/reso ...
- Linux CentOS7 VMware 特殊权限set_uid、特殊权限set_gid、特殊权限stick_bit、软链接文件、硬连接文件
一.特殊权限set_uid root用户本身拥有对/etc/passwd的写权限,无可厚非:那普通用户呢,这里就用到了setuid,setuid的作用是“让执行该命令的用户以该命令拥有者的权限去执行” ...
- RHEL7 修改SSH默认端口及修改SELinux运行状态
RHEL7安装后,默认开启SSH服务以便远程配置,但默认端口22并不安全,一般不建议使用默认端口,那就修改SSH默认端口.在sshd_config里面的修改RHEL7.0上修改和7.0以下类似,但要注 ...
- 修改目的端trail文件的最大大小--转载
本文为原创,转载请注明出处: http://blog.csdn.net/msdnchina/article/details/38346435 修改目的端trail文件的最大大小. 本文产生的背景: 在 ...
随机推荐
- hadoop中文官网
http://hadoop.apache.org/docs/r1.0.4/cn/hdfs_shell.html
- Jmeter零起点学习
什么是JMeter Apache JMeter是一个开源的Java桌面软件.设计的目的就是进行C/S架构软件的负载测试.随着发展,有很多人也用来进行一些静态资源或者动态资源的性能测试.可以支持的测 ...
- 【python】多进程多线程
import threading import multiprocessing class MultiThread(threading.Thread): def __init__(self,func, ...
- 在php代码中调用帝国cms头部变量temp.header的方法
在php代码中调用帝国cms头部变量temp.header的方法 代码如下: <?php require("../e/class/connect.php"); if(!def ...
- 2014年王道论坛研究生机试练习赛(一) set 1 GrassLand密码
题目 根据手机按键上的对应关系将字母转成数字, 简单模拟题 总结 1. scanf("%s", input); 不需要加上 & 2. 字符串的终结符是 '\0' 3. sc ...
- Qt选择文件对话框-中文路径-转std::string
#include <QFileDialog>#pragma execution_character_set("utf-8") QString path = QFileD ...
- Google Inc.:Google APIs:23' 解决方案
在导入一个项目是,出现 Unable to resolve target 'Google Inc.:Google APIs:6'第一种解决方法: compileSdkVersion 23 改成 com ...
- (三)微信小程序之发送服务通知(模板消息)
1.后端获取AccessToken返回给微信端 微信小程序端请求后端得到AccessToken 2.后端获取openid返回给微信端 微信小程序端登录请求后端得到openid 3.发送消息 ...
- @ResponseBody将集合数据转换为json格式并返回给客户端
spring-mvc.xml: <beans xmlns:mvc="http://www.springframework.org/schema/mvc" > <m ...
- PHP遍历文件夹及子文件夹所有文件(此外还有飞递归的方法)
<html> <body> <?php function traverse($path = '.') { $current_dir = opendir($path); / ...