Linux命令大全: cat命令 – 在终端设备上显示文件内容

1. 详情

Linux系统中有很多个用于查看文件内容的命令,每个命令又都有自己的特点,比如这个cat命令就是用于查看内容较少的纯文本文件的。cat这个命令也很好记,因为cat在英语中是“猫”的意思,小猫咪是不是给您一种娇小、可爱的感觉呢?

注意:当文件内容较大时,文本内容会在屏幕上快速闪动(滚屏),用户往往看不清所显示的具体内容。因此对于较长文件内容可以按Ctrl+S键,停止滚屏;以及Ctrl+Q键可以恢复滚屏;而按Ctrl+C(中断)键则可以终止该命令的执行。或者对于大文件,干脆用more命令吧!

语法格式:cat [参数] [文件]

常用参数:

参数描述
-n显示行数(空行也编号)
-s显示行数(多个空行算一个编号)
-b显示行数(空行不编号)
-E每行结束处显示$符号
-T将TAB字符显示为 ^I符号
-v使用 ^ 和 M- 引用,除了 LFD 和 TAB 之外
-e等价于”-vE”组合
-t等价于”-vT”组合
-A等价于 -vET组合
–help显示帮助信息
–version显示版本信息

2. 参考实例

  1. 查看文件的内容:
cat filename.txt
  1. 查看文件的内容,并显示行数编号:
cat -n filename.txt
  1. 查看文件的内容,并添加行数编号后输出到另外一个文件中:
cat -n linuxcool.log > linuxprobe.log 
  1. 清空文件的内容:
 cat /dev/null > /root/filename.txt
  1. 持续写入文件内容,碰到EOF符后结束并保存:
cat > filename.txt <<EOF
> Hello, World 
> Linux!
> EOF
  1. 将软盘设备制作成镜像文件:
cat /dev/fd0 > fdisk.iso

3. 系统文档(mkdir cat)


NAME
       cat - concatenate files and print on the standard output

SYNOPSIS
       cat [OPTION]... [FILE]...
DESCRIPTION
       Concatenate FILE(s) to standard output.

       With no FILE, or when FILE is -, read standard input.

       -A, --show-all
              equivalent to -vET

       -b, --number-nonblank
              number nonempty output lines, overrides -n

       -e     equivalent to -vE

       -E, --show-ends
              display $ at end of each line

       -n, --number
              number all output lines

       -s, --squeeze-blank
              suppress repeated empty output lines

       -t     equivalent to -vT

       -T, --show-tabs
              display TAB characters as ^I

       -u     (ignored)

       -v, --show-nonprinting
              use ^ and M- notation, except for LFD and TAB

       --help display this help and exit

       --version
              output version information and exit

EXAMPLES
       cat f - g
              Output f's contents, then standard input, then g's contents.

       cat    Copy standard input to standard output.

AUTHOR
       Written by Torbjorn Granlund and Richard M. Stallman.

REPORTING BUGS
       GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
       Report cat translation bugs to <http://translationproject.org/team/>

COPYRIGHT
       Copyright © 2016 Free Software Foundation, Inc.  License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
       This is free software: you are free to change and redistribute it.  There is NO WARRANTY, to the extent permitted by law.

SEE ALSO
       tac(1)

       Full documentation at: <http://www.gnu.org/software/coreutils/cat>
       or available locally via: info '(coreutils) cat invocation'

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值