关于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文件的最大大小. 本文产生的背景: 在 ...
随机推荐
- 如何使用ChemDraw改变说明文本
作为一款全球领先的化学绘图工具,ChemDraw能够绘制各种复杂的结构方程式.ChemDraw软件还增加了新的绘图工具,能够方便化学领域的图形绘制.本教程将向大家讲解如何在ChemDraw中改变说明文 ...
- mysql数据库中,查看某个数据库下的表的存储类型都有哪些
需求描述: 在备份数据库的时候,使用mysqldump进行数据库的备份,如果库中仅仅有innodb存储引擎, 那么使用--single-transaction就可以,如果还有其他的存储引擎类型就要使用 ...
- NFS挂在文件系统启动参数
1.tiny6410(增强版)bootargs启动参数(周学伟)noinitrd console=ttySAC0,115200 lcd=S70 init=/init root=/dev/nfs rw ...
- mongodb 安装(windows mongodb 安装)
MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的.他支持的数据结构非常松散,是类似json的bjson格式,因此可以存储比较复杂的数据类型.M ...
- Python 入门(十)列表生成式
生成列表 要生成list [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],我们可以用range(1, 11): >>> range(1, 11) [1, 2, 3, ...
- Python 练习题:计算 MAC 地址
#!/usr/bin/env python #-*- coding:utf-8 -*- ''' 给一个MAC地址加1 ''' mac = '52:54:00:e6:b2:0a' prefix_mac ...
- Qt选择文件对话框-中文路径-转std::string
#include <QFileDialog>#pragma execution_character_set("utf-8") QString path = QFileD ...
- MFC-TCP连接代码片段(支援大富的)
BOOL CClientSocketTestDlg::OnInitDialog() { CDialogEx::OnInitDialog(); ........................ // T ...
- 关于MultiByteToWideChar与WideCharToMultiByte代码测试(宽字符与多字节字符的转换)以及字符串的转换代码测试
#pragma once #include <stdio.h> //getchar() #include <tchar.h> #include <stdlib.h> ...
- 测试sql语句性能,提高执行效率
为了让您的程序执行的效率更高,SQL的效率一定不可忽视. 现有以下方法去检测SQL的执行效率. 对于多表查询的效率测试: )直接from ,where方式. SET STATISTICS io ON ...