首页 技术 正文
技术 2022年11月7日
0 收藏 556 点赞 612 浏览 1594 个字

Cat命令:一般用作打开文件,查看文件内容(可以一次查看多个文件),参数有如下几个:

-a 或 –all,显示全部

-b 或–number-nonblank 对非空输出行编号

  -n 或 –number 由 1 开始对所有输出的行数编号

  -s 或 –squeeze-blank 当遇到有连续两行以上的空白行,就代换为一行的空白行

A.用于查看文件内容:cat blank.txt     查看名为blank的txt文件内容;

B.用于创建新的文件并输入内容:cat > filename <<EOF,enter后输入文件内容,结尾处<<EOF结束;

C . 将几个文件合为一个文件:cat filename1 filename2 filename3 > newfilename  ,举例如下:<cat还可以把一个或多个已存在的文件内容,追加到一个已存在的文件中

  cat s01  s02  s03 >> sA ,’>’意思是创建,’>>’是追加,不要记错>

A例.[root@localhost ~]# cat -n initial-setup-ks.cfg original-ks.cfg

1   #version=DEVEL

2   #
Install OS instead of upgrade

3   install

4   #
X Window System configuration information

5   xconfig  –startxonboot

B例.[root@localhost ~]# cat >
123 << EOF #新建一个以123命名的文件

    >
hallo world

    >
how are you

    >
i am  fine

    >
EOF

  [root@localhost
~]# cat 123

  hallo
world

  how
are you

  i
am  fine

  [root@localhost
~]# cat >> 123

  i am
very hot,how about you ?

  ^C

  [root@localhost
~]# cat 123

  hallo
world

  how
are you

  i
am  fine

  i am
very hot,how about you ? 已经累加到目标文件

C例.[root@localhost ~]# cat > 123 #新建3份文件,分别为123、abc、EFG,并为各文件输入内容

    this
is the frist file^C

  [root@localhost
~]# cat > abc

    the
second file is setting now^C

  [root@localhost
~]# cat > EFG

    the
last one ^C

  [root@localhost
~]# ls -a

    . 123 
anaconda-ks.cfg  .bash_logout   .bashrc 
.config  .dbus  initial-setup-ks.cfg  original-ks.cfg  .xauth7xzQQg

    ..  abc 
.bash_history   
.bash_profile  .cache   .cshrc  
EFG    mongodb_simple        .tcshrc

  [root@localhost
~]# cat 123 abc EFG > newone

  [root@localhost
~]# ls -a   #查看目录时,目标文件已经存在,

    .   123 
anaconda-ks.cfg  .bash_logout   .bashrc 
.config  .dbus  initial-setup-ks.cfg  newone #目标文件夹   .tcshrc

    ..  abc 
.bash_history   
.bash_profile  .cache   .cshrc  
EFG    mongodb_simple        original-ks.cfg  .xauth7xzQQg

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,029
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,519
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,367
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,146
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,859