Linux shell cat 命令

返回上一级

Linux shell 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。

-e : 等价于 -vE。

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

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

-t: 等价于"-vT"选项;

范例

demo1.txt 的文件内容加上行号后输出到 demo2.txt 这个文件中

demo1.txt 文件内容

[root@localhost ~]# cat demo1.txt
Linux networks are becoming more and more common, but scurity is often an overlooked
issue. Unfortunately, in today’s environment all networks are potential hacker targets,
fro0m tp-secret military research networks to small home LANs.
Linux Network Securty focuses on securing Linux in a networked environment, where the
security of the entire network needs to be considered rather than just isolated machines.
It uses a mix of theory and practicl techniques to teach administrators how to install and
use security applications, as well as how the applcations work and why they are necesary.

demo1.txt 的文件内容加上行号后输出到 demo2.txt 这个文件

[root@localhost ~]# cat -n demo1.txt > demo2.txt

demo2.txt 文件中的内容

[root@localhost ~]# cat demo2.txt
     1  Linux networks are becoming more and more common, but scurity is often an overlooked
     2  issue. Unfortunately, in today’s environment all networks are potential hacker targets,
     3  fro0m tp-secret military research networks to small home LANs.
     4  Linux Network Securty focuses on securing Linux in a networked environment, where the
     5  security of the entire network needs to be considered rather than just isolated machines.
     6  It uses a mix of theory and practicl techniques to teach administrators how to install and
     7  use security applications, as well as how the applcations work and why they are necesary.
[root@localhost ~]#

把文件 demo1.txtdemo2.txt 的内容加上行号(空白行不加)之后将内容 附加demo3.txt 文件中:

[root@localhost ~]# cat -b demo1.txt  demo2.txt >> demo3.txt

清空 /etc/test.txt 文件内容

[root@localhost ~]# cat /dev/null > /etc/test.txt

cat 也可以用来制作镜像文件

cat 命令可以制作软盘的镜像文件,将软盘放好后输入

[root@localhost ~]# cat /dev/fd0 > OUTFILE

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

[root@localhost ~]#  cat IMG_FILE > /dev/fd0

注意

  1. OUTFILE 指输出的镜像文件名
  2. IMG_FILE 指镜像文件
  3. 若从镜像文件写回 device 时,device 容量需与相当
  4. 通常用制作开机磁片

返回上一级

Linux Shell 命令大全

关于   |   FAQ   |   我们的愿景   |   广告投放   |  博客

  简单教程,简单编程 - IT 入门首选站

Copyright © 2013-2022 简单教程 twle.cn All Rights Reserved.