1.echo
2.cat
#查看文件内容,合并多个文件,创建新文件及编辑文件,显示行号
-n #给输出结果加上行号
-A #给输出的内容每行的结尾加上一个标识符
[root@lxy ~]# cat test.txt
123
456
[root@lxy ~]# cat -n test.txt
1 123
2 456
[root@lxy ~]# cat -A test.txt
123$
456$
[root@lxy ~]# echo \'123456 \' >>test.txt
[root@lxy ~]# cat test.txt
123
456
123456
[root@lxy ~]# cat -A test.txt
123$
456$
123456 $
#合并多个文件
[root@lxy ~]# cat hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@lxy ~]# cat test.txt
123
456
123456
[root@lxy ~]# cat hosts test.txt
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
123
456
123456
[root@lxy ~]# cat hosts test.txt >test.log
[root@lxy ~]# cat test.log
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
123
456
123456
#创建一个文件及编辑文件
[root@lxy ~]# cat >file.txt<<EOF
> oldboy
> 123456
> olfgirl
> EOF
[root@lxy ~]# cat file.txt
oldboy
123456
olfgirl
[root@lxy ~]# cat >>file.txt<<eof
> test
> eof
[root@lxy ~]# cat file.txt
oldboy
123456
olfgirl
test
3.tac
#倒着显示文件内容,默认显示文件最后一行
[root@lxy ~]# tac file.txt
test
olfgirl
123456
oldboy
4.more
#分页显示文件内容,文件内容显示完成之后会自动退出
[root@lxy ~]# cp /etc/services ./
-n #n表示数字,指定一页显示多少行
+n #指定从第几行开始显示文件内容
内部命令
空格/f #向下翻页
b #向上翻页
回车键 #向下翻一行
= #显示当前光标所在的行数
/ #搜索,不会高亮显示
n #向下查找,用在/中
q #退出
h #帮助信息
5.less
6.head
#显示文件的头部信息,默认显示前十行
-n #取消默认输出,后面跟数字,指定显示多少行
-c #显示文件的前几个字符
[root@lxy ~]# head services
# /etc/services:
# $Id: services,v 1.55 2013/04/14 ovasik Exp $
#
# Network services, Internet style
# IANA services version: last updated 2013-04-10
#
# Note that it is presently the policy of IANA to assign a single well-known
# port number for both TCP and UDP; hence, most entries here have two entries
# even if the protocol doesn\'t support UDP operations.
# Updated from RFC 1700, ``Assigned Numbers\'\' (October 1994). Not all ports
[root@lxy ~]# head -n 1 services
# /etc/services:
[root@lxy ~]# head -1 services
# /etc/services:
[root@lxy ~]# head -2 services
# /etc/services:
# $Id: services,v 1.55 2013/04/14 ovasik Exp $
[root@lxy ~]# head -c 5 services #显示文件的前5个字符
# /et[root@lxy ~]#
7.tail
#显示文件尾部信息,默认显示最后十行内容
-n #取消默认输出,指定显示多少行
-c #显示文件最后几个字符
-f #实时查看文件内容的更新
-F #实时查看文件内容的更新,当文件不存在时,会一直尝试读取该文件
[root@lxy ~]# tail services
3gpp-cbsp 48049/tcp # 3GPP Cell Broadcast Service Protocol
isnetserv 48128/tcp # Image Systems Network Services
isnetserv 48128/udp # Image Systems Network Services
blp5 48129/tcp # Bloomberg locator
blp5 48129/udp # Bloomberg locator
com-bardac-dw 48556/tcp # com-bardac-dw
com-bardac-dw 48556/udp # com-bardac-dw
iqobject 48619/tcp # iqobject
iqobject 48619/udp # iqobject
matahari 49000/tcp # Matahari Broker
[root@lxy ~]# tail -n 1 services
matahari 49000/tcp # Matahari Broker
[root@lxy ~]# tail -1 services
matahari 49000/tcp # Matahari Broker
[root@lxy ~]# cat -n services | tail -1
11176 matahari 49000/tcp # Matahari Broker
| #管道,将管道前面的命令的输出结果交给管道后面的命令进行处理
[root@lxy ~]# tail -c5 services #显示最后5个字符,
oker #最后有一个换行符
[root@lxy ~]# tail -f test.log #实时的查看文件的更新
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
123
456
123456
123
[root@lxy ~]# tail -20f /var/log/messages #指定从最后的20行内容开始显示
[root@lxy ~]# tail -F file.log #会实时的查看文件内容的更新,文件不存在时,会一直尝试读取,直到文件存在或者手动退出
tail: cannot open ‘file.log’ for reading: No such file or directory
tail: ‘file.log’ has appeared; following end of new file
123
^C
8.tailf
#实时查看文件的更新,默认显示最后十行,当文件没有更新时,不会读取磁盘。减少磁盘的io读写
-n #取消默认输出,显示指定的行数
[root@lxy ~]# tailf /var/log/messages
[root@lxy ~]# tailf -20 /var/log/messages