Chinaunix首页 | 论坛 | 博客
  • 博客访问: 537304
  • 博文数量: 142
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1452
  • 用 户 组: 普通用户
  • 注册时间: 2013-09-12 16:28
文章分类

全部博文(142)

文章存档

2016年(10)

2015年(60)

2014年(72)

我的朋友

分类: LINUX

2015-03-05 15:36:54

cat 命令有三大功能:
1.一次显示整个文件
   cat filename
2. 从键盘创建一个文件
   cat > filename
 只能创建新文件,不能编辑修改已有的文件
3.将几个文件合并为一个文件
   cat file1 file2 > file

语法:
    cat [OPTION] ... [FILE]...
参数:
FILE  是cat要处理的单个文件路径名或多个文件路径名列表,如果不指定任何参数或指定一个连字符(-)代替文件名,cat就从标准输入读取信息,然后打印

option选项:
    -b, --number-nonblank
        对非空白行添加行数编号
    -n,--number
         对所有行从1开始编号,包括空白行
    -s,--squeeze-blank
        抑制重复的空行,即多个空行的话,只输出一个空行
    -E, --show-ends
       在每行结束处显示 $
    -T, --show-tabs
        将Tab键显示为^I


例子1--------一次性显示一个文件:

点击(此处)折叠或打开

  1. gwwu@hz-dev2.wgw.com:~/test/shell>cat cat_file
  2. wgw

  3. love

  4. tyx


  5. and



  6. wjx
  7.         T A B c
  8. gwwu@hz-dev2.wgw.com:~/test/shell>cat -n cat_file
  9.      1 wgw
  10.      2
  11.      3 love
  12.      4
  13.      5 tyx
  14.      6
  15.      7
  16.      8 and
  17.      9
  18.     10
  19.     11
  20.     12 wjx
  21.     13 T A B c
  22. gwwu@hz-dev2.wgw.com:~/test/shell>cat -b cat_file
  23.      1 wgw

  24.      2 love

  25.      3 tyx


  26.      4 and



  27.      5 wjx
  28.      6 T A B c
  29. gwwu@hz-dev2.wgw.com:~/test/shell>cat -s cat_file
  30. wgw

  31. love

  32. tyx

  33. and

  34. wjx
  35.         T A B c
  36. gwwu@hz-dev2.wgw.com:~/test/shell>cat -sn cat_file
  37.      1 wgw
  38.      2
  39.      3 love
  40.      4
  41.      5 tyx
  42.      6
  43.      7 and
  44.      8
  45.      9 wjx
  46.     10 T A B c
  47. gwwu@hz-dev2.wgw.com:~/test/shell>cat -sb cat_file
  48.      1 wgw

  49.      2 love

  50.      3 tyx

  51.      4 and

  52.      5 wjx
  53.      6 T A B c
  54. gwwu@hz-dev2.wgw.com:~/test/shell>cat -sbT cat_file
  55.      1 wgw

  56.      2 love

  57.      3 tyx

  58.      4 and

  59.      5 wjx
  60.      6 ^IT^IA B^Ic
  61. gwwu@hz-dev2.wgw.com:~/test/shell>cat -sbE cat_file
  62.      1 wgw$
  63. $
  64.      2 love$
  65. $
  66.      3 tyx$
  67. $
  68.      4 and$
  69. $
  70.      5 wjx$
  71.      6 T A B c$
  72. gwwu@hz-dev2.wgw.com:~/test/shell>
例子2----链接文件cat_file_1和cat_file_2:
      

点击(此处)折叠或打开

  1. gwwu@hz-dev2.wgw.com:~/test/shell>cat cat_file_1
  2. abc wgw

  3. dfadf


  4. vim

  5. cat_file1

  6. gwwu@hz-dev2.wgw.com:~/test/shell>cat cat_file_2
  7. tyx wjx

  8. love


  9. ok

  10. cat_file_2


  11. gwwu@hz-dev2.wgw.com:~/test/shell>cat cat_file_1 cat_file_2 > cat_file_3
  12. gwwu@hz-dev2.wgw.com:~/test/shell>cat cat_file_3
  13. abc wgw

  14. dfadf


  15. vim

  16. cat_file1

  17. tyx wjx

  18. love


  19. ok

  20. cat_file_2


  21. gwwu@hz-dev2.wgw.com:~/test/shell>

例子3---创建一个新文件,如果文件已经存在,则覆盖

点击(此处)折叠或打开

  1. gwwu@hz-dev2.wgw.com:~/test/shell>cat > cat_file
  2. a
  3. b
  4. c
  5. gwwu@hz-dev2.wgw.com:~/test/shell>more cat_file
  6. a
  7. b
  8. c



阅读(859) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~