zoukankan      html  css  js  c++  java
  • 每天一个Linux命令-cat

    1、cat 查看文件内容:
    [root@localhost ~]# cat /etc/profile    注:查看/etc/目录下的profile文件内容;
    [root@localhost ~]# cat -b /etc/fstab   注:查看/etc/目录下的profile内容,并且对非空白行进行编号,行号从1开始;
    [root@localhost ~]# cat -n /etc/profile    注:对/etc目录中的profile的所有的行(包括空白行)进行编号输出显示;
    [root@localhost ~]# cat -E /etc/profile     注:查看/etc/下的profile内容,并且在每行的结尾处附加$符号;
     
    cat 加参数-n 和nl工具差不多,文件内容输出的同时,都会在每行前面加上行号;
    [root@localhost ~]# cat -n /etc/profile
    [root@localhost ~]# nl /etc/profile

    cat 可以同时显示多个文件的内容,比如我们可以在一个cat命令上同时显示两个文件的内容;
    [root@localhost ~]# cat /etc/fstab /etc/profile
     
    cat 对于内容极大的文件来说,可以通过管道|传送到more 工具,然后一页一页的查看;
    [root@localhost ~]# cat /etc/fstab /etc/profile | more
     
    2、cat 的创建、连接文件功能实例:
    cat 有创建文件的功能,创建文件后,要以EOF或STOP结束;
    [root@localhost ~]# cat > linuxsir.org.txt << EOF 注:创建linuxsir.org.txt文件;
    > 我来测试 cat 创建文件,并且为文件输入内容;       注:这是为linuxsir.org.txt文件输入内容;
    > 北南南北 测试;                   注:这是为linuxsir.org.txt文件输入内容;
    > EOF   注:退出编辑状态;

    [root@localhost ~]# cat linuxsir.org.txt 注:我们查看一下linuxsir.org.txt文件的内容;

    我来测试 cat 创建文件,并且为文件输入内容;
    北南南北 测试;
     
    cat 还有向已存在的文件追加内容的功能;
    [root@localhost ~]# cat linuxsir.txt 注:查看已存在的文件linuxsir.txt 内容;
    I am BeiNanNanBei From LinuxSir.Org .    注:内容行
    我正在为cat命令写文档

    [root@localhost ~]# cat >> linuxsir.txt << EOF   注:我们向linuxsir.txt文件追加内容;
    > 我来测试cat向文档追加内容的功能;       注:这是追回的内容
    > OK?
    > OK~
    > 北南 呈上
    > EOF   注:以EOF退出;

    cat 连接多个文件的内容并且输出到一个新文件中;
    假设我们有sir01.txt、sir02.tx和sir03.txt ,并且内容如下;
    [root@localhost ~]# cat sir01.txt  
    123456
    i am testing
    [root@localhost ~]# cat sir02.txt
    56789
    BeiNan Tested
    [root@localhost ~]# cat sir03.txt
    09876
    linuxsir.org testing

    注意:其原理是把三个文件的内容连接起来,然后创建sir04.txt文件,并且把几个文件的内容同时写入sir04.txt中。特别值得一提的是,如果您输入到一个已经存在的sir04.txt 文件,会把sir04.txt内容清空。

    [root@localhost ~]# cat sir01.txt sir02.txt sir03.txt > sir04.txt
    [root@localhost ~]# more sir04.txt
    123456
    i am testing
    56789
    BeiNan Tested
    09876
    linuxsir.org testing
     
    cat 把一个或多个已存在的文件内容,追加到一个已存在的文件中
    [root@localhost ~]# cat sir00.txt
    linuxsir.org forever

    [root@localhost ~]# cat sir01.txt sir02.txt sir03.txt >> sir00.txt

    [root@localhost ~]# cat sir00.txt
    linuxsir.org forever
    123456
    i am testing
    56789
    BeiNan Tested
    09876
    linuxsir.org testing

  • 相关阅读:
    【转】C#进阶系列——WebApi 接口参数不再困惑:传参详解
    微信内测小程序,苹果你怎么看?
    给你一个团队,你应该怎么管?
    ios修改产品名
    【原创】windows下搭建vue开发环境+IIS部署
    【原】“系统”重新启动
    Ubuntu root密码修改
    【转】网络编程常见问题总结
    Python + Selenium -Python 3.6 3.7 安装 PyKeyboard PyMouse
    python3 获取当前路径及os.path.dirname sys.path.dirname的使用
  • 原文地址:https://www.cnblogs.com/3ddan/p/10389361.html
Copyright © 2011-2022 走看看