每日一个linux命令09-cat

1. 命令解析

命令用途

  1. 显示整个文件的内容;
  2. 创建一个新文件,并从键盘向文件输入内容;
  3. 将几个文件的内容合并到一个新文件;

命令格式

cat [OPTION]... FILE...

命令参数

-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

2. 示例

2.1 显示文件内容

[root@test catTest]# cat f1
Hello
This
is
My
Password=${pwd}

2.2 创建一个新文件,使用here doc的方式录入内容

[root@test catTest]# cat <<EOF > f3
> This
> is
> f3
> EOF
[root@test catTest]# cat f3
This
is
f3

2.3 显示文件内容并标出行号,包括空行 -n

[root@test catTest]# cat -n f3
     1  This
     2  is
     3  f3
     4  
     5  
     6  After blank is
     7  new line
     8  

2.4 显示文件内容并标出行号,不包括空行 -b

root@test catTest]# cat -b f3
     1  This
     2  is
     3  f3


     4  After blank is
     5  new line

2.5 合并文件

root@test catTest]# cat f1 f3 > f4

2.6 倒序输出

[root@test catTest]# cat f3
This
is
f3


After blank is
new line

[root@test catTest]# tac f4

new line
After blank is


f3
is
This
this is f1\n

2.7 在显示每行的结尾时附加$ -E

[root@test catTest]# cat -ET f4
this is f1\n$
This$
is$
f3$
$
$
After blank is$
new line$
$

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 转载来自链接:真机测试Could not find Developer Disk Image - CCSS'S B...
    墨狂之逸才阅读 18,574评论 0 51
  • 午夜梦醒,下意识的按下开关。温和的暖光占据了房间。 这个城市的气候变化无常,初秋的脚步刚刚到来,刺骨的寒意就已...
    千音百调阅读 474评论 0 1
  • 我是谁? 我是一个与众不同的人,上小学的时候我就告诉自己。后来明白了每个人都是这么想的,每个人都想做不平凡的人。 ...
    Flora唐阅读 277评论 1 1
  • 提权继承的问题: 1.是哪个用户运行的程序,提权后就是该用户的权限,可利用 ps -aux查看运行程序的所有者 2...
    xiaobaozi阅读 388评论 0 0
  • 风晕桂飘香, 沉醉烟路殇。 可叹念时荡, 遥托明月疆。
    万俟苏苏阅读 262评论 0 0