每日一命令(10)cat (concatenate files and print on the standard output)

cat concatenate files and print on the standard output 拼接文件和输出文件

man cat 查看命令文档

cat 查看文件
cat > file 创建文件,但是不能编辑已经存在的文件

cat options file

-A, --show-all 等价于 -vET
-b, --number-nonblank 对非空输出行编号
-e 等价于 -vE
-E, --show-ends 在每行结束处显示 $
-n, --number 对输出的所有行编号
-s, --squeeze-blank 不输出多行空行
-t 与 -vT 等价
-T, --show-tabs 将跳 字符显示为 ^I
-u (被忽略)
-v, --show-nonprinting 使用 ^ 和 M- 引用,除了 LFDTAB 之外
--help 显示此帮助信息并离开

cat file1.txt 输出文件内容

root@nginx02  ~
# ll
total 56
-rw-------. 1 root root  1073 May 26 22:40 anaconda-ks.cfg
-rw-r--r--. 1 root root    51 Jun 15 07:19 file1.txt
-rw-r--r--. 1 root root    53 Jun 15 07:22 file2.txt
-rw-r--r--. 1 root root    51 Jun 15 07:19 file3.txt
-rw-r--r--. 1 root root    18 Jun 15 07:18 file4.txt
-rw-r--r--. 1 root root 22179 May 26 22:40 install.log
-rw-r--r--. 1 root root  5890 May 26 22:38 install.log.syslog

root@nginx02  ~
# cat file1.txt 
123123
asdfasfdsa
sdfsfsd
sdfsfsd
sdfsdfds
werqda

cat -bn -b 对空白行不编号,-n编号

root@nginx02  ~
# cat -b file2.txt 
     1  123123
     2  asdfasfdsa

     3  sdfsfsd

     4  sdfsfsd

     5  sdfsdfds
     6  werqda

root@nginx02  ~
# cat -n file2.txt 
     1  123123
     2  asdfasfdsa
     3  
     4  sdfsfsd
     5  
     6  sdfsfsd
     7  
     8  sdfsdfds
     9  werqda

cat file1.txt file2.txt > file5.txt 拼接文件

root@nginx02  ~
# cat file1.txt file2.txt > file5.txt

root@nginx02  ~
# ll
total 60
-rw-------. 1 root root  1073 May 26 22:40 anaconda-ks.cfg
-rw-r--r--. 1 root root    51 Jun 15 07:19 file1.txt
-rw-r--r--. 1 root root    53 Jun 15 07:22 file2.txt
-rw-r--r--. 1 root root    51 Jun 15 07:19 file3.txt
-rw-r--r--. 1 root root    18 Jun 15 07:18 file4.txt
-rw-r--r--. 1 root root   104 Jun 15 07:27 file5.txt
-rw-r--r--. 1 root root 22179 May 26 22:40 install.log
-rw-r--r--. 1 root root  5890 May 26 22:38 install.log.syslog

root@nginx02  ~
# cat file5.txt 
123123
asdfasfdsa
sdfsfsd
sdfsfsd
sdfsdfds
werqda

123123
asdfasfdsa

sdfsfsd

sdfsfsd

sdfsdfds
werqda

cat -s file2.txt 如果有多行空白,只显示一行空白

root@nginx02  ~
# cat -n  file2.txt 
     1  123123
     2  asdfasfdsa
     3  
     4  sdfsfsd
     5  
     6  sdfsfsd
     7  
     8  sdfsdfds
     9  werqda
    10  
    11  
    12  

root@nginx02  ~
# vat -ns file2.txt 
-bash: vat: command not found

root@nginx02  ~
# cat -ns file2.txt 
     1  123123
     2  asdfasfdsa
     3  
     4  sdfsfsd
     5  
     6  sdfsfsd
     7  
     8  sdfsdfds
     9  werqda
    10  
root@nginx02  ~
# cat -n file2.txt 
     1  123123
     2  asdfasfdsa
     3  
     4  
     5  
     6  sdfsfsd
     7  
     8  sdfsfsd
     9  
    10  sdfsdfds
    11  werqda
    12  
    13  
    14  

root@nginx02  ~
# cat -sn file2.txt 
     1  123123
     2  asdfasfdsa
     3  
     4  sdfsfsd
     5  
     6  sdfsfsd
     7  
     8  sdfsdfds
     9  werqda
    10  

cat > 创建文件 ctrl+c 保存

root@nginx02  ~
# ll
total 60
-rw-------. 1 root root  1073 May 26 22:40 anaconda-ks.cfg
-rw-r--r--. 1 root root     0 Jun 15 07:36 EOF
-rw-r--r--. 1 root root    51 Jun 15 07:19 file1.txt
-rw-r--r--. 1 root root    28 Jun 15 07:36 file2.txt
-rw-r--r--. 1 root root    51 Jun 15 07:19 file3.txt
-rw-r--r--. 1 root root    18 Jun 15 07:18 file4.txt
-rw-r--r--. 1 root root   104 Jun 15 07:27 file5.txt
-rw-r--r--. 1 root root 22179 May 26 22:40 install.log
-rw-r--r--. 1 root root  5890 May 26 22:38 install.log.syslog

root@nginx02  ~
# cat > file6.txt
^C

root@nginx02  ~
# ll
total 60
-rw-------. 1 root root  1073 May 26 22:40 anaconda-ks.cfg
-rw-r--r--. 1 root root     0 Jun 15 07:36 EOF
-rw-r--r--. 1 root root    51 Jun 15 07:19 file1.txt
-rw-r--r--. 1 root root    28 Jun 15 07:36 file2.txt
-rw-r--r--. 1 root root    51 Jun 15 07:19 file3.txt
-rw-r--r--. 1 root root    18 Jun 15 07:18 file4.txt
-rw-r--r--. 1 root root   104 Jun 15 07:27 file5.txt
-rw-r--r--. 1 root root     0 Jun 15 07:40 file6.txt
-rw-r--r--. 1 root root 22179 May 26 22:40 install.log
-rw-r--r--. 1 root root  5890 May 26 22:38 install.log.syslog

cat > file6.txt << EOF ….. EOF 创建文件并且输入文件内容 内容的开始和结束必须的一模一样,顺便什么名字都可以

root@nginx02  ~
# ll
total 60
-rw-------. 1 root root  1073 May 26 22:40 anaconda-ks.cfg
-rw-r--r--. 1 root root     0 Jun 15 07:36 EOF
-rw-r--r--. 1 root root    51 Jun 15 07:19 file1.txt
-rw-r--r--. 1 root root    28 Jun 15 07:36 file2.txt
-rw-r--r--. 1 root root    51 Jun 15 07:19 file3.txt
-rw-r--r--. 1 root root    18 Jun 15 07:18 file4.txt
-rw-r--r--. 1 root root   104 Jun 15 07:27 file5.txt
-rw-r--r--. 1 root root     0 Jun 15 07:40 file6.txt
-rw-r--r--. 1 root root 22179 May 26 22:40 install.log
-rw-r--r--. 1 root root  5890 May 26 22:38 install.log.syslog

root@nginx02  ~
# cat > file6.txt <<EOF 
> sdfsdf
> adfasdf
> agda
> asd
> asdg
> adfs
> EOF

root@nginx02  ~
# ll
total 64
-rw-------. 1 root root  1073 May 26 22:40 anaconda-ks.cfg
-rw-r--r--. 1 root root     0 Jun 15 07:36 EOF
-rw-r--r--. 1 root root    51 Jun 15 07:19 file1.txt
-rw-r--r--. 1 root root    28 Jun 15 07:36 file2.txt
-rw-r--r--. 1 root root    51 Jun 15 07:19 file3.txt
-rw-r--r--. 1 root root    18 Jun 15 07:18 file4.txt
-rw-r--r--. 1 root root   104 Jun 15 07:27 file5.txt
-rw-r--r--. 1 root root    34 Jun 15 07:42 file6.txt
-rw-r--r--. 1 root root 22179 May 26 22:40 install.log
-rw-r--r--. 1 root root  5890 May 26 22:38 install.log.syslog
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值