如何通过shell去掉Linux配置文件中的注释行呢?
本文给出两种解决方法,供大家参考。

方法1、使用grep -v "^#" 来去掉注释行,其中:-v 表示取反 ^# 表示注解行
grep -v "^#" /etc/vsftpd/vsftpd.conf (使用“>”来重写配置文件也是可以的)

方法2、连同空行一起去掉,使用管道符。(^$表示空行 )
grep -v "^#" httpd.conf | grep -v "^$" >> vsftpd.conf

以上用了 2次 grep 过滤命令,是把空行和注解行过滤掉,再把剩下的内容追加保存为原来的配置文件 vsftpd.conf,那么此文件中的内容就没有注解行和空行了.
注意:
保留配置文件中的注释,可以方便以后对配置文件的阅读与理解,对配置不是很熟悉的朋友,建议不要去除注释行。

在更改配置文件时,建议先做备份,例如:
cp httpd.conf httpd.conf.bak

 

分享:shell去掉linux配置文件的注释行的更多相关文章

  1. 如何去掉linux配置文件的注释行和空行

    1.使用grep -v "^#"  来去掉注释行,其中:-v  就是取相反的   ^# 表示以#开头的行 eg. grep -v "^#" /etc/vsftp ...

  2. grep命令:查看配置文件未注释行(转)

    FROM: https://linux.cn/article-6958-1.html 可以使用 UNIX/BSD/OS X/Linux 这些操作系统自身提供的 grep,sed,awk,perl或者其 ...

  3. 老李分享:《Linux Shell脚本攻略》 要点(四)

    老李分享:<Linux Shell脚本攻略> 要点(四)   1.IP地址的正则表达式: [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} 2. ...

  4. 老李分享:《Linux Shell脚本攻略》 要点(二)

    老李分享:<Linux Shell脚本攻略> 要点(二)   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课 ...

  5. 老李分享:《Linux Shell脚本攻略》 要点(八)

    老李分享:<Linux Shell脚本攻略> 要点(八)   1.打印进程 [root@localhost program_test]# ps -e | head  PID TTY     ...

  6. 老李分享:《Linux Shell脚本攻略》 要点(七)

    老李分享:<Linux Shell脚本攻略> 要点(七)   1.显示给定文件夹下的文件的磁盘适用情况 [root@localhost program_test]# du -a -h ./ ...

  7. 老李分享:《Linux Shell脚本攻略》 要点(六)

    老李分享:<Linux Shell脚本攻略> 要点(六)   1.打印网络接口列表 [root@localhost touch_more]# ifconfig | cut -c-10 | ...

  8. 老李分享:《Linux Shell脚本攻略》 要点(五)

    老李分享:<Linux Shell脚本攻略> 要点(五)   //1.打包.解包 [root@localhost program_test]# tar -cf output.tar 11. ...

  9. 老李分享:《Linux Shell脚本攻略》 要点(三)

    老李分享:<Linux Shell脚本攻略> 要点(三)   1.生产任意大小的文件 [root@localhost dd_test]#[root@localhost dd_test]# ...

随机推荐

  1. Android 使用PullToRefreshExpandableListView不能setAdapter的问题

    private PullToRefreshExpandableListView lv; lv = (PullToRefreshExpandableListView) findViewById(R.id ...

  2. 指向函数的指针与iOS-Block相关知识

    指向函数的指针与iOS-Block相关知识 一. 函数指针的定义和调用: 关于函数指针的知识详细可参考:http://www.cnblogs.com/mjios/archive/2013/03/19/ ...

  3. 6、JavaScript进阶篇③——浏览器对象、Dom对象

    一.浏览器对象 1. window对象 window对象是BOM的核心,window对象指当前的浏览器窗口. window对象方法: 注意:在JavaScript基础篇中,已讲解了部分属性,windo ...

  4. oracle修改sys用户密码

  5. duplicate命令创建physical standby数据库报RMAN-03015 ORA-17628

    The following error is reported trying to create a Physical Standby database using "duplicate f ...

  6. leetcode-99 Recover_Binary_Search_Tree

    题目要求: Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without ch ...

  7. decimal类型保留两位小数

    oj.PriceTop =Math.Round(Convert.ToDecimal(reader["PriceTop"]),2);

  8. PostgreSQL Replication之第十三章 使用PL/Proxy扩展(2)

    13.2 设置 PL/Proxy 简短的理论介绍之后,我们可以继续前进并运行一些简单的PL/Proxy设置.要做到这一点,我们只需安装PL/Proxy并看看这是如何被使用的. 安装PL/Proxy是一 ...

  9. Leetcode: Range Sum Query 2D - Mutable && Summary: Binary Indexed Tree

    Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper lef ...

  10. stucts2 基础程序

    参考<Struts2+Hibernate+Spring> index.jsp