内容简介:cat命令的用途是连接文件或标准输入并打印。这个命令常用来显示文件内容,或者将几个文件连接起来显示,或者从标准输入读取内容并显示,它常与重定向符号配合使用。
cat命令的用途是连接文件或标准输入并打印。这个命令常用来显示文件内容,或者将几个文件连接起来显示,或者从标准输入读取内容并显示,它常与重定向符号配合使用。
1.命令格式:
cat [选项] [文件]…
2.命令功能:
cat主要有三大功能:
1.一次显示整个文件:cat filename
2.从键盘创建一个文件:cat > filename 只能创建新文件,不能编辑已有文件.
3.将几个文件合并为一个文件:cat file1 file2 > file
3.命令参数:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
-A, --show-all 等价于 -vET -b, --number-nonblank 对非空输出行编号 -e 等价于 -vE -E, --show-ends 在每行结束处显示 $ -n, --number 对输出的所有行编号,由1开始对所有输出的行数编号 -s, --squeeze-blank 有连续两行以上的空白行,就代换为一行的空白行 -t 与 -vT 等价 -T, --show-tabs 将跳格字符显示为 ^I -u (被忽略) -v, --show-nonprinting 使用 ^ 和 M- 引用,除了 LFD 和 TAB 之外 |
4.使用实例:
实例一:把 log2012.log 的文件内容加上行号后输入 log2013.log 这个文件里
命令:
|
1 |
cat -n log2012.log log2013.log |
输出:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
[root@localhost test]# cat log2012.log 2012-01 2012-02 ======[root@localhost test]# cat log2013.log 2013-01 2013-02 2013-03 ======[root@localhost test]# cat -n log2012.log log2013.log 1 2012-01 2 2012-02 3 4 5 ====== 6 2013-01 7 2013-02 8 9 10 2013-03 11 ======[root@localhost test]# |
说明:
实例二:把 log2012.log 和 log2013.log 的文件内容加上行号(空白行不加)之后将内容附加到 log.log 里。
命令:
|
1 |
cat -b log2012.log log2013.log log.log |
输出:
|
1 2 3 4 5 6 7 8 |
[root@localhost test]# cat -b log2012.log log2013.log log.log 1 2012-01 2 2012-02 3 ====== 4 2013-01 5 2013-02 6 2013-03 7 ======[root@localhost test]# |
实例三:把 log2012.log 的文件内容加上行号后输入 log.log 这个文件里
命令:
输出:
|
1 2 3 4 5 6 7 8 9 |
[root@localhost test]# cat log.log [root@localhost test]# cat -n log2012.log > log.log [root@localhost test]# cat -n log.log 1 2012-01 2 2012-02 3 4 5 ====== [root@localhost test]# |
实例四:使用here doc来生成文件
输出:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[root@localhost test]# cat >log.txt <<EOF > Hello > World > Linux > PWD=$(pwd) > EOF [root@localhost test]# ls -l log.txt -rw-r--r-- 1 root root 37 10-28 17:07 log.txt [root@localhost test]# cat log.txt Hello World Linux PWD=/opt/soft/test [root@localhost test]# |
说明:
注意粗体部分,here doc可以进行字符串替换。
备注:
tac (反向列示)
命令:
|
1 |
tac log.txt |
输出:
|
1 2 3 4 5 |
[root@localhost test]# tac log.txt PWD=/opt/soft/test Linux World Hello |
说明:
tac 是将 cat 反写过来,所以他的功能就跟 cat 相反, cat 是由第一行到最后一行连续显示在萤幕上,而 tac 则是由最后一行到第一行反向在萤幕上显示出来!
本系列文章:
每天一个 Linux 命令(1):ls命令
每天一个 Linux 命令(2):cd命令
每天一个 Linux 命令(3):pwd命令
每天一个 Linux 命令(4):mkdir命令
每天一个 Linux 命令(5):rm 命令
每天一个 Linux 命令(6):rmdir 命令
每天一个 Linux 命令(7):mv命令
每天一个 Linux 命令(8):cp 命令
每天一个 Linux 命令(9):touch 命令
以上所述就是小编给大家介绍的《每天一个 Linux 命令(10):cat 命令》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- composer更新命令及常用命令
- Linux命令行与命令
- AWK命令和SED命令
- 每天一个 Linux 命令(60): scp命令
- 每天一个 Linux 命令(59): rcp 命令
- 每天一个 Linux 命令(58): telnet 命令
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Music Recommendation and Discovery
Òscar Celma / Springer / 2010-9-7 / USD 49.95
With so much more music available these days, traditional ways of finding music have diminished. Today radio shows are often programmed by large corporations that create playlists drawn from a limited......一起来看看 《Music Recommendation and Discovery》 这本书的介绍吧!