Code前端首页关于Code前端联系我们

Linux命令列表:cat

terry 2年前 (2023-09-28) 阅读数 56 #未命名

cat用于附加文件或标准输入和打印。该命令经常用于显示一个文件的内容,或者连接多个文件进行显示,或者从标准输入读取内容并显示它们。通常与重定向符号结合使用。

1。命令格式

cat [选项] [文件]…

2.命令功能

cat有三个主要功能:

  1. 一次查看整个文件:cat 文件名
  2. 从键盘创建文件:❙cat❙ 只有cat >❙可以创建新文件,无法编辑现有文件。
  3. 将多个文件合并为一个文件:cat file1 file2 > file
    命令参数:
    • -A、❙-‷相当于 -vET
    • - b--number-nonblank,表示非空白输出行号
    • -e
    • -e❙♻❙♻❙♻❙♻ ♻ , --显示结束 在最后显示 $
    • -n, -, -‷每行的所有输出行开始from 1 -s, --squeeze-blank 如果有两个以上连续空行,则将其替换为一行空行和❙♻相当于vt-t,tabs-show-tabsshow show跳跃字符在♝-v、 --显示非打印 使用 ^M-❙,M-
    • TAB 外侧

4.使用示例

示例一

将行号添加到文件 mylog1.log 的内容中,然后在此文件中键入 mylog2.log。
命令:

cat -n mylog1.log mylog2.log
Shell

输出:

[yiibai@localhost test]$ cat mylog1.log
this is line 1
this is line 2
[yiibai@localhost test]$ cat mylog2.log
log2 this is line 1
log2 this is line 2
log2 this is line 3
[yiibai@localhost test]$ cat -n mylog1.log mylog2.log
     1  this is line 1
     2  this is line 2
     3  log2 this is line 1
     4  log2 this is line 2
     5  log2 this is line 3
[yiibai@localhost test]$
Shell

示例二❙❙ ’1❙。并将文件mylog2.log

的内容添加到行号后(不添加空行),将内容添加到log.log
命令:

cat -b mylog1.log mylog2.log log.log
Shell

输出:

yiibai@localhost test]$ cat -b mylog1.log mylog2.log >> log.log
[yiibai@localhost test]$ cat log.log
     1  this is line 1
     2  this is line 2
     3  log2 this is line 1
     4  log2 this is line 2
     5  log2 this is line 3
[yiibai@localhost test]$
Shell

示例三 此处使用

版权声明

本文仅代表作者观点,不代表Code前端网立场。
本文系作者Code前端网发表,如需转载,请注明页面地址。

热门