Linux命令——cat、more、less、head、tail

cat

一次顯示整個文件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$
View Code

從鍵盤建立一個文件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

more

分屏顯示文本文件內容,從前日後翻,翻到文件的尾部 顯示結束。結束時不能往前翻了

b鍵往前翻一屏  

回車 往下翻一行

空格 往下翻一屏

less

分屏顯示

向下翻一行 向下鍵 或 回車

向上翻一行 向上鍵

  向下翻一屏 pagegdown 或 空格鍵

  向上翻一屏 pageup

  查找內容:

    /text 或 ?text

  :q退出less命令

head

 顯示文本文件的前幾行,默認顯示前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
View Code

tail

顯示文本文件的後幾行,默認顯示後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 ~]# 
View Code

-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
View Code

.。。。。

相關文章
相關標籤/搜索