linux cat 命令

来源:互联网 发布:c语言黑客代码大全 编辑:程序博客网 时间:2024/06/14 06:41

功能

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

语法

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