cat

cat 命令用于连接文件并打印到标准输出设备上。

使用权限

所有使用者

语法格式
cat [-AbeEnstTuv] [--help] [--version] fileName
参数说明:
-n 或 --number:由 1 开始对所有输出的行数编号。

-b 或 --number-nonblank:和 -n 相似,只不过对于空白行不编号。

-s 或 --squeeze-blank:当遇到有连续两行以上的空白行,就代换为一行的空白行。

-v 或 --show-nonprinting:使用 ^ 和 M- 符号,除了 LFD 和 TAB 之外。

-E 或 --show-ends : 在每行结束处显示 $。

-T 或 --show-tabs: 将 TAB 字符显示为 ^I。

-A, --show-all:等价于 -vET。

-e:等价于"-vE"选项;

-t:等价于"-vT"选项;
实例:
-n:文件加上行号
> :覆盖
>>:追加
#把 textfile1 的文档内容加上行号后输入 textfile2 这个文档里:
[root@c7-41 test]# cat file1
a
b
c
d

[root@c7-41 test]# cat file2
qwq
qew
fdf
df
[root@c7-41 test]# cat -n file1 > file2  
[root@c7-41 test]# cat file2   # > 直接覆盖了
     1  a
     2  b
     3  c
     4  d
     5

[root@c7-41 test]# cat file3
fds
dfsdg
sdgs
dg
[root@c7-41 test]# cat file1
a
b
c
d

[root@c7-41 test]# cat -n file1 >> file3  # >> 追加
[root@c7-41 test]# cat file3
fds
dfsdg
sdgs
dg
     1  a
     2  b
     3  c
     4  d
     5

-b:(空白行不加行号)
#把 textfile1 和 textfile2 的文档内容加上行号(空白行不加)之后将内容附加到 textfile3 文档里:
[root@c7-41 test]# cat file1
a
b
c
d

[root@c7-41 test]# cat -b file1 >> file2 
[root@c7-41 test]# cat file2
     1  a
     2  b
     3  c
     4  d


/dev/null :清空
[root@c7-41 test]# pwd
/root/test
[root@c7-41 test]# cat file1
a
b
c
d

[root@c7-41 test]# cat /dev/null > /root/test/file1  #加绝对地址
[root@c7-41 test]# cat file1  

制作镜像

cat 也可以用来制作镜像文件。例如要制作软盘的镜像文件,将软盘放好后输入:

cat /dev/fd0 > OUTFILE

相反的,如果想把 image file 写到软盘,输入:

cat IMG_FILE > /dev/fd0
  1. OUTFILE 指输出的镜像文件名。
  2. IMG_FILE 指镜像文件。
  3. 若从镜像文件写回 device 时,device 容量需与相当。
  4. 通常用制作开机磁片。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

云原生解决方案

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值