一次显示整个文件bash
-n:显示行号less
-b :和 -n 类似,只不过对于空白行不编号ide
-s:当遇到有连续两行以上的空白行,就代换为一行的空白行spa
-E显示换行符3d
[root@localhost ~]# cat haha.txt -n 1 /usr/bin/cp 2 3 4 5 /usr/bin/gzip [root@localhost ~]# cat haha.txt -b 1 /usr/bin/cp 2 /usr/bin/gzip [root@localhost ~]# cat haha.txt -bs 1 /usr/bin/cp 2 /usr/bin/gzip [root@localhost ~]# cat haha.txt -bsE 1 /usr/bin/cp$ $ 2 /usr/bin/gzip$
从键盘建立一个文件code
cat > filenameblog
输入完内容后Ctrl+D能够保存。千万不要Ctrl+C,这样不会保存文件内容。ip
cat >filename <<EOFit
也能够使用Ctrl+D,可是会警告 -bash: warning: here-document at line 36 delimited by end-of-file (wanted `EOF')event
可是文件内容仍是被保存下来了。
最好的作法仍是按照规矩来,EOF结束文件输入
将几个文件合并为一个文件
cat file1 file2 > file
分屏显示文本文件内容,从前日后翻,翻到文件的尾部 显示结束。结束时不能往前翻了
b键往前翻一屏
回车 往下翻一行
空格 往下翻一屏
分屏显示
向下翻一行 向下键 或 回车
向上翻一行 向上键
向下翻一屏 pagegdown 或 空格键
向上翻一屏 pageup
查找内容:
/text 或 ?text
:q退出less命令
显示文本文件的前几行,默认显示前10行
改成显示前2行(-n能够省)
[root@51cto ~]# head -n2 install.log Installing libgcc-4.4.7-3.el6.x86_64 warning: libgcc-4.4.7-3.el6.x86_64: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY [root@51cto ~]# head -2 install.log Installing libgcc-4.4.7-3.el6.x86_64 warning: libgcc-4.4.7-3.el6.x86_64: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
显示文本文件的后几行,默认显示后10行
改成显示前2行(-n能够省)
[root@51cto ~]# tail -2 install.log Installing rootfiles-8.1-6.1.el6.noarch *** FINISHED INSTALLING PACKAGES ***[root@51cto ~]# tail -n2 install.log Installing rootfiles-8.1-6.1.el6.noarch *** FINISHED INSTALLING PACKAGES ***[root@51cto ~]#
-f follow 一直跟踪 再也不退出 ctrl+c结束
[root@51cto ~]# ping www.baidu.com > wangyan.txt [root@51cto ~]# tail -f wangyan.txt PING www.a.shifen.com (61.135.169.125) 56(84) bytes of data. 64 bytes from 61.135.169.125: icmp_seq=1 ttl=128 time=64.6 ms 64 bytes from 61.135.169.125: icmp_seq=2 ttl=128 time=58.8 ms 64 bytes from 61.135.169.125: icmp_seq=3 ttl=128 time=56.9 ms 64 bytes from 61.135.169.125: icmp_seq=4 ttl=128 time=127 ms 64 bytes from 61.135.169.125: icmp_seq=5 ttl=128 time=121 ms 64 bytes from 61.135.169.125: icmp_seq=6 ttl=128 time=117 ms 64 bytes from 61.135.169.125: icmp_seq=7 ttl=128 time=109 ms
.。。。。