zoukankan      html  css  js  c++  java
  • cat命令使用

    cat - concatenate files and print on the standard output

    连/拼接多个文件,然后将这些文件的内容打印到标准输出

    一. cat 主要功能:

    1.显示文件全部内容:

    形如: cat 文件名

    [hupeng@hupeng-vm shell]$cat 1.txt

    2.创建新的文件

    形如: cat > 文件名

    [hupeng@hupeng-vm shell]$cat > 1.txt  #输入ctrl+D退出输入
    hello 
    world
    [hupeng@hupeng-vm shell]$cat 1.txt 
    hello
    world

    3.将多个文件的内容合并到新的文件

    形如: cat 文件1 文件2 > 新文件名

    [hupeng@hupeng-vm shell]$echo "hello world" > 1.txt
    [hupeng@hupeng-vm shell]$echo "hello shell" > 2.txt
    [hupeng@hupeng-vm shell]$cat 1.txt 2.txt > 3.txt
    [hupeng@hupeng-vm shell]$cat 3.txt 
    hello world
    hello shell

    二.常用参数

    -n 给输出行编号(包括空行)

    -b 给输出行编号(忽略空行)

    [hupeng@hupeng-vm shell]$echo -e "hello world
    hello shell
    
    hello linux" > out.txt
    [hupeng@hupeng-vm shell]$cat out.txt 
    hello world
    hello shell
    
    hello linux
    [hupeng@hupeng-vm shell]$cat -n out.txt  #输出带编号
         1    hello world
         2    hello shell
         3    
         4    hello linux
    [hupeng@hupeng-vm shell]$cat -b out.txt  #跳过空行编号
         1    hello world
         2    hello shell
    
         3    hello linux

    三、cat << EOF使用

    EOF(end of file),其实它只是一个标志,可以用其他合法字符替换,如HHH

    [hupeng@hupeng-vm shell]$cat << EOF  #从终端获取多行输入,直接打印到标准输出
    > hello world
    > hello linux
    > hello c/c++
    > hello shell
    > EOF
    hello world
    hello linux
    hello c/c++
    hello shell
    [hupeng@hupeng-vm shell]$cat << EOF > out.txt #将标准输入中个内容从定向到文件
    > hi linux
    > hi shll
    > EOF
    [hupeng@hupeng-vm shell]$cat out.txt 
    hi linux
    hi shll

    使用HHH替换EOF

    [hupeng@hupeng-vm shell]$cat << HHH
    > hello
    > world
    > end with HHH
    > HHH
    hello
    world
    end with HHH

        

  • 相关阅读:
    【Linux】- Systemd 命令篇
    【Linux】- 守护进程的启动方法
    【Linux】- CentOS安装docker及docker-compose
    【Python】- scrapy 爬取图片保存到本地、且返回保存路径
    解决百度ueditor支持iframe框架页面的视频播放问题
    php CURL 请求头和响应头获取
    phpcms pc标签 start不生效的原因
    单点登录的实现
    Linux下删除相互依赖的包
    如何通过js关闭微信浏览器页面
  • 原文地址:https://www.cnblogs.com/hupeng1234/p/6738267.html
Copyright © 2011-2022 走看看