8

Linux之cat命令

 2 years ago
source link: https://segmentfault.com/a/1190000041143637
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

cat命令的用途是连接文件或者标准输入并打印。这个命令常用来显示文件内容,或者将几个文件拼接起来显示,或者从标准输入读取内容并显示,它常与重定向符号配合使用。

cat [选项] [文件]...

命令的功能

  • 读取显示整个文件 cat filename
  • 从键盘读取输入到文件cat > 1.txt
  • 将多个文件合并成一个文件cat 1.txt 2.txt > 3.txt
  • -A, --show-all 等价于 -vET
  • -b, --number-nonblank 对非空输出行编号
  • -e 等价于 -vE
  • -E, --show-ends 在每行结束处显示 $
  • -n, --number 对输出的所有行编号,由1开始对所有输出的行数编号
  • -s, --squeeze-blank 有连续两行以上的空白行,就代换为一行的空白行
  • -t 与 -vT 等价
  • -T, --show-tabs 将跳格字符显示为 ^I
  • -u (被忽略)
  • -v, --show-nonprinting 使用 ^ 和 M- 引用,除了 LFD 和 TAB 之外

1.txt的内容加上行号输入到2.txt

>cat 1.txt
入门小站

rumenz.com
rumenz

123
345

9999

3333
> cat -n 1.txt > 2.txt
>cat 2.txt
     1  入门小站
     2
     3  rumenz.com
     4  rumenz
     5
     6  123
     7  345
     8
     9
    10  9999
    11
    12  3333

1.txt的内容(空白行不加行号)输入到2.txt

> cat -b 1.txt > 2.txt
> cat 2.txt
     1  入门小站

     2  rumenz.com
     3  rumenz

     4  123
     5  345


     6  9999

     7  3333

使用here doc来生成文件

cat > 3.txt <<EOF
> 入门小站
> rumenz
> rumenz.com
> 
> 
> `date`
> EOF

> cat 3.txt
入门小站
rumenz
rumenz.com


Thu Feb  4 23:40:09 CST 2021

同时显示多个文件的内容

> cat 1.txt 2.txt

原文链接:https://rumenz.com/rumenbiji/...
微信公众号:入门小站

linux常用命令速查手册PDF下载

3669页vim参考手册PDF下载

阿里云ECS运维Linux系统诊断PDF下载

Docker速查手册PDF下载

Linux学习笔记【强悍总结值得一看】PDF下载

shell简明教程PDF下载


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK