关于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文件的最大大小. 本文产生的背景: 在 ...
随机推荐
- 【Matlab】运动目标检测之“光流法”
光流(optical flow) 1950年,Gibson首先提出了光流的概念,所谓光流就是指图像表现运动的速度.物体在运动的时候之所以能被人眼发现,就是因为当物体运动时,会在人的视网膜上形成一系列的 ...
- mysqlbinlog基于某个偏移量进行数据的恢复(重做),--start-position,--stop-position的使用方法
需求描述: 今天在看mysqlbinlog的内容,看到了--start-position和--stop-position这些选项, 就测试下这个参数具体该怎么进行使用呢,在此记录下. 操作过程: 1. ...
- 【ExtJs】 ExtJs4.2 基本表单组件的使用
包含ExtJs 基本的组件radioGroup,ComboBox,File,NumberField... <%-- Created by IntelliJ IDEA. User: Adminis ...
- 超全面的JavaWeb笔记day22<文件上传>
文件上传概述 1 文件上传的作用 例如网络硬盘!就是用来上传下载文件的. 在智联招聘上填写一个完整的简历还需要上传照片呢. 2 文件上传对页面的要求 上传文件的要求比较多,需要记一下: 1. 必须使用 ...
- IIS禁止xml文件访问
今天在出现数据库账号信息泄露的时候,突然想到xml文件里面放着很多信息,而且网页能够直接访问到,这就很有问题了 开始的时候,也在IIS网站那里看到请求筛选这个设置,开始还以为不能加呢,还是同事说的.
- JavaIO再回顾
File类 JavaIO访问文件名和文件检测相关操作 分隔符最好是使用File类提供的File.separator,使程序更加的健壮. File类提供的方法基本上是见名知意,例如getName()就是 ...
- 配置maven使用nexus
本文简单介绍使用配置maven使用nexus仓库,在团队中使用nexus,避免每个人都从中央仓库去下载依赖,节省带宽,提高下载速度,同时也减少了中央仓库的压力 配置在maven中使用nexus很简单( ...
- Unity3D笔记三 物理引擎
一.物理引擎 1.物理引擎就是模拟真实世界中物体碰撞.跌落等反应,通过Ballance.愤怒的小鸟来理解什么是物理引擎.Unity的物理引擎使用的是NviDIA的PhysX.2.选中一个游戏对象,主菜 ...
- eclipse导入maven-jeecg项目
参考内容:http://blog.csdn.net/zhangdaiscott/article/details/50915206 [技术文档]jeecg3.7.1-maven搭建环境入门 由于ma ...
- log buffer space事件(转)
看了这篇文章: Oracle常见的等待事件说明http://database.ctocio.com.cn/tips/38/6669538.shtml 对于Log Buffer Space-日志缓冲空间 ...