找回密码
 立即注册
Qt开源社区 门户 查看内容

【技术篇:Linux shell】Linux shell 操作命令 cat

2019-9-30 11:39| 发布者: admin| 查看: 819| 评论: 0

摘要: Linux shell 操作命令 cat Linux shell 命令行 让你真正开始 Linux之旅,本文描述Linux 操作命令 cat1、简介 cat 命令是 concatenate 的缩写2、主要功能 cat 命令的功能是将 文件 或 标准输入 组合输出 到 标准输 ...


Linux shell 操作命令 cat

    Linux shell 命令行 让你真正开始 Linux之旅,本文描述 Linux 操作命令 cat

1、简介

    cat 命令是 concatenate 的缩写

2、主要功能

    cat 命令的功能是将 文件 或 标准输入 组合输出 到 标准输出

3、用法/命令格式
    cat[选项][文件]

    4、常用参数解析

    语法

    参数

    说明

    cat {文件1} ... {文件N}


    将 单个 或 多个 文件 内容 输出到 标准输出
      # cat /etc/hosts /etc/hosts /etc/hosts127.0.0.1 localhost127.0.1.1 ubuntu
      # The following lines are desirable for IPv6 capable hosts::1 localhost ip6-localhost ip6-loopbackff02::1 ip6-allnodesff02::2 ip6-allrouters127.0.0.1 localhost127.0.1.1 ubuntu
      # The following lines are desirable for IPv6 capable hosts::1 localhost ip6-localhost ip6-loopbackff02::1 ip6-allnodesff02::2 ip6-allrouters127.0.0.1 localhost127.0.1.1 ubuntu
      # The following lines are desirable for IPv6 capable hosts::1 localhost ip6-localhost ip6-loopbackff02::1 ip6-allnodesff02::2 ip6-allrouters

      5、辅助功能

      5.1 行号输出

      5.1.1 显示 所有 行号

      语法

      参数

      说明

      cat [ -n ] {文件}

      -n

      对输出的所有行编号(行号 从 1 开始)
        # cat -n /etc/hosts1127.0.0.1 localhost2127.0.1.1 ubuntu34# The following lines are desirable for IPv6 capable hosts5 ::1 localhost ip6-localhost ip6-loopback6ff02::1 ip6-allnodes     7  ff02::2 ip6-allrouters

        5.1.2 不输出 空行

        语法

        参数

        说明

        cat [ -b 或者 --number-nonblank ] {文件}

        -b --number-nonblank

        对非空输出行编号(空行 仍然 输出显示)
          # cat -b /etc/hosts1127.0.0.1 localhost2127.0.1.1 ubuntu
          3# The following lines are desirable for IPv6 capable hosts4 ::1 localhost ip6-localhost ip6-loopback5ff02::1 ip6-allnodes     6  ff02::2 ip6-allrouters

          5.1.3 连续 空行 只输出 一行

          语法

          参数

          说明

          cat [ -s 或者 --squeeze-blank ] {文件}

          -s --squeeze-blank

          有连续两行以上的空白行,就代换为一行的空白行(可与 -n 连用)
            # cat -s /etc/hosts127.0.0.1 localhost127.0.1.1 ubuntu
            # The following lines are desirable for IPv6 capable hosts::1 localhost ip6-localhost ip6-loopbackff02::1 ip6-allnodesff02::2 ip6-allrouters

            5.2 结尾 添加 $

            语法

            参数

            说明

            cat [ -E 或者 --show-ends ] {文件}

            -E --show-ends

            在每行结束处显示 $(包括空行)
              # cat -E /etc/hosts127.0.0.1 localhost$127.0.1.1 ubuntu$$# The following lines are desirable for IPv6 capable hosts$::1 localhost ip6-localhost ip6-loopback$ff02::1 ip6-allnodes$ff02::2 ip6-allrouters$

              6、内容扩展

              6.1 文本内容写入

              ## 清空文本 原有内容,再写入

              # cat > test << EOF

              ## 文本 末尾 追加 内容

              # cat >> test << EOF


              6.2 反向输出文本内容

                  tac 是将 cat 反写过来,功能就跟 cat 相反

              • cat 是由 第一行 到 最后一行 连续输出显示

              • tac 是由 最后一行 到 第一行 反向 连续输出显示


              6.3 其他 文本 查看方式

                  more、less 、nl 、tail 命令工具 也可以 查看 文本内容



              微信公众号 欢迎 扫码 关注






              ----------------------------------------------------------------------------------------------------------------------
              我们尊重原创,也注重分享,文章来源于微信公众号:石头逍遥,建议关注公众号查看原文。如若侵权请联系qter@qter.org。
              ----------------------------------------------------------------------------------------------------------------------

              鲜花

              握手

              雷人

              路过

              鸡蛋
              
              公告
              可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了