RHCSA--Vim 文件查看和查找文件

该文展示了如何在Linux环境中利用vi命令创建文件并插入日期,将/grub2/grub.cfg内容追加到新文件,删除包含#字符的行,以及启用VI的行号显示。同时,通过grep命令查找XML文件中包含re的行并复制到另一个文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

(1) 应用vi命令在/tmp文件夹下创建文件,文件名newfile。在newfile首行输入日期时间

[root@localhost ~]# date > /tmp/newfile
[root@localhost ~]# cat /tmp/newfile
Tue Mar 21 05:50:24 AM EDT 2023

 (2) 将/boot/grub2/grub.cfg文档的内容读入到newfile文档中(在日期的下一行即第2行)

(3) 查找文档中包含#号字符的行,将整行删除

(4) 开启VI的行号提示功能

:g/#/d
:/#  
E486: Pattern not found: # 

2、文件查看:查看newfile文件的第6行

[root@localhost ~]# head -6 /tmp/newfile |tail -1
Tue Mar 21 05:50:24 AM EDT 2023
[root@localhost ~]# 

3、查找文件 /usr/share/xml/xml.xsd 中包含字符串 re 的所有行。将所有这些行的副本按原始顺序放在文件/root/files 中

[root@localhost ~]# grep re /usr/share/xml/xml.xsd
<?xml-stylesheet href="../../2008/09/xsd.xsl" type="text/xsl"?>
      See <a href="http://www.w3.org/XML/1998/namespace.html">
      <a href="http://www.w3.org/TR/REC-xml">
      Note that local names in this namespace are intended to be
      The names currently defined in this namespace are listed below.
      See further below in this document for more information about <a
      href="#usage">how to refer to this schema document from your own
      XSD schema documents</a> and about <a href="#nsversioning">the
       any element; its value is inherited.  This name is reserved
      Attempting to install the relevant ISO 2- and 3-letter
      going to be a realistic possibility.  
      See BCP 47 at <a href="http://www.rfc-editor.org/rfc/bcp/bcp47.txt">
      and the IANA language subtag registry at
      <a href="http://www.iana.org/assignments/language-subtag-registry">
       http://www.iana.org/assignments/language-subtag-registry</a>
     <xs:restriction base="xs:string">
     </xs:restriction>
       value is inherited.  This name is reserved by virtue of its
   <xs:restriction base="xs:NCName">
    <xs:enumeration value="preserve"/>
   </xs:restriction>
       provides a URI to be used as the base for interpreting any
       relative URIs in the scope of the element on which it
       appears; its value is inherited.  This name is reserved
      href="http://www.w3.org/TR/xmlbase/">http://www.w3.org/TR/xmlbase/</a>
       should be interpreted as if declared to be of type ID.
       This name is reserved by virtue of its definition in the
      href="http://www.w3.org/TR/xml-id/">http://www.w3.org/TR/xml-id/</a>
  <xs:attribute ref="xml:base"/>
  <xs:attribute ref="xml:lang"/>
  <xs:attribute ref="xml:space"/>
  <xs:attribute ref="xml:id"/>
      the original XML Working Group.  This name is reserved by 
	In appreciation for his vision, leadership and
	February, 2000, reserves for Jon Bosak in perpetuity
     <pre>
     </pre>
     <pre>
     </pre>
      Subsequently, qualified reference to any of the attributes or the
      group defined below will have the desired effect, e.g.
     <pre>
           &lt;attributeGroup ref="xml:specialAttrs"/>
     </pre>
      <a href="http://www.w3.org/2009/01/xml.xsd">
      <a href="http://www.w3.org/2001/xml.xsd">
      The schema document at that URI may however change in the future,
      in order to remain compatible with the latest version of XML
      document at <a href="http://www.w3.org/2001/xml.xsd">
      <a href="http://www.w3.org/2009/01/xml.xsd">
      Previous dated (and unchanging) versions of this schema 
      document are at:
      <li><a href="http://www.w3.org/2009/01/xml.xsd">
      <li><a href="http://www.w3.org/2007/08/xml.xsd">
      <li><a href="http://www.w3.org/2004/10/xml.xsd">
      <li><a href="http://www.w3.org/2001/03/xml.xsd">
[root@localhost ~]# cat /usr/share/xml/xml.xsd |grep re

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值