cat可以读取、显示和拼接文件内容
1. 打印单个文件:
root@debian:/home/chicol/scripts# cat file.txt
This is a line inside file.txt
This is second line inside file.txt
打印多个文件:
root@debian:/home/chicol/scripts# cat one.txt two.txt
This is line from one.txt
This is line from two.txt
root@debian:/home/chicol/scripts#
2. 读取标准输入:
root@debian:/home/chicol/scripts# ls | cat
1
1_12fname.sh
a1
a2
a3
calcu.sh
file.txt
functions.sh
ifs2.sh
ifs.sh
null
one.txt
out.txt
password.sh
printf.sh
sleep.sh
test1.sh
text.txt
three.txt
time_take.sh
tmp.txt
two.txt
将标准输入和文件内容拼接:
root@debian:/home/chicol/scripts# ls | cat - file.txt
1
1_12fname.sh
a1
a2
a3
calcu.sh
file.txt
functions.sh
ifs2.sh
ifs.sh
null
one.txt
out.txt
password.sh
printf.sh
sleep.sh
test1.sh
text.txt
three.txt
time_take.sh
tmp.txt
two.txt
This is a line inside file.txt
This is second line inside file.txt
这里将"-"当作stdin文本的文件名。
3. cat打印文件内容的几个选项用法:
cat -s :当文件中有连续空白行时,使用-s选项打印时,会去掉多余的空白行,只保留一个空白行
cat -n: 打印文件内容时显示行号
cat -T: 可以区别显示制表符和空格,制表符显示为“^I”
这里来看下这几个选项在一起使用的例子:
root@debian:/home/chicol/scripts# cat three.txt
This is first line.
This is second line
This is third line.
Tab line.
Space line.
root@debian:/home/chicol/scripts# cat -snT three.txt
1 This is first line.
2
3 This is second line
4
5 This is third line.
6 ^ITab line.
7 Space line.
root@debian:/home/chicol/scripts#
阅读(1099) | 评论(0) | 转发(0) |