linux cat 命令

功能

连接文件或显示文件的内容

语法

cat [选项] 文件

选项

-n,--number  显示行号
-b,--number-nonblank  不显示空白行的行号
-s,--squeeze-blank  连续两个或以上的空白行替换成一个来显示

示例

cat a.txt显示文件的内容

lychie@ubuntu:/test$ cat a.txt

You laugh at me for being different,

but I laugh at you for being the same.

Don't go around saying the world owes you a living.

The world owes you nothing. It was here first.

cat -n a.txt显示文件的内容

lychie@ubuntu:/test$ cat -n a.txt
     1
     2  You laugh at me for being different,
     3
     4  but I laugh at you for being the same.
     5
     6  Don't go around saying the world owes you a living.
     7
     8  The world owes you nothing. It was here first.

cat -b a.txt显示文件的内容

lychie@ubuntu:/test$ cat -b a.txt

     1  You laugh at me for being different,

     2  but I laugh at you for being the same.

     3  Don't go around saying the world owes you a living.

     4  The world owes you nothing. It was here first.

cat > b.txt << OFF生成文件

lychie@ubuntu:/test$ cat > b.txt << OFF
> ------ END ------
> OFF
lychie@ubuntu:/test$

cat a.txt b.txt > c.txt合并 a.txt、b.txt 的内容并存储到 c.txt 中

lychie@ubuntu:/test$ ls
a.txt  b.txt
lychie@ubuntu:/test$ cat a.txt b.txt > c.txt
lychie@ubuntu:/test$ ls
a.txt  b.txt  c.txt
lychie@ubuntu:/test$ cat -b c.txt

     1  You laugh at me for being different,

     2  but I laugh at you for being the same.

     3  Don't go around saying the world owes you a living.

     4  The world owes you nothing. It was here first.

     5  ------ END ------

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值