歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> 學習Linux >> Linux文本查看命令(cat,tac,rev,head,tail,more,less) 詳解

Linux文本查看命令(cat,tac,rev,head,tail,more,less) 詳解

日期:2017/3/6 9:23:37   编辑:學習Linux

Linux文本查看命令(cat,tac,rev,head,tail,more,less) 詳解


Linux文本查看命令(cat,tac,rev,head,tail,more,less) 詳解


Linux中我們總會有查看文本某些內容的時候,如果我們僅因為查看文本就使用vi進去文件又增加了不少額外的操作不方便。下面介紹一些文本查看命令,大家看後應該會有所幫助

--------------------------------------------------------------------------------
cat

cat - concatenate files and print on the standard output
表達格式:cat [OPTION]... [FILE]...
常用選項:
-A:顯示所有控制符
-n:顯示行數
-E:顯示行結束符

下面以幾個例子來具體說明cat及其選項的使用
實驗目錄/test 文本/test/cat1 /test/cat2
1234567891011121314 [root@localhost test]# ll /test/
總用量 8
-rw-r--r--. 1 root root 43 8月 7 16:46 cat1
-rw-r--r--. 1 root root 19 8月 7 16:46 cat2
[root@localhost test]# cat cat1
hi,everyone
now I will show how to use cat
[root@localhost test]# cat -An cat1
1 hi,everyone$
2 now I will show how to use cat$
[root@localhost test]# cat -nE cat1 cat2
1 hi,everyone$
2 now I will show how to use cat$
3 This is an example$

cat後面可以接多個文件,常用選項可以組合使用

--------------------------------------------------------------------------------
tac cat的反向顯示,按文本反向

tac - concatenate and print files in reverse
tac [OPTION]... [FILE]...
[root@localhost test]# tac cat1
now I will show how to use cat
hi,everyone

tac選項都不常用,因此不予介紹

--------------------------------------------------------------------------------
rev 文件內容按行反向顯示

rev - reverse lines of a file or files
rev [options] [file ...]
[root@localhost test]# rev cat1
enoyreve,ih
tac esu ot woh wohs lliw I won

rev無有價值可介紹選項

--------------------------------------------------------------------------------
head

head - output the first part of files
head [OPTION]... [FILE]...
常用選項:
-c #:顯示前多少個字節
-n #:顯示前多少行,n可以省去
head file 默認顯示文件前十行內容
[root@localhost test]# head -3 head
12345
67890
12
[root@localhost test]# head -c 3 head
[root@localhost test]#

--------------------------------------------------------------------------------
tail

tail - output the last part of files
tail [OPTION]... [FILE]...
常用選項:
-c #:顯示後多少個字節
-n #:顯示後多少行,n可以省去
-f :跟蹤顯示文件新追加的內容,常用日志監控
123456789101112 [root@localhost test]# tail -3 head
345
123
6
[root@localhost test]# tail -c 5 head
23
6
[root@localhost test]# tail -f /var/log/messages
Aug 7 17:15:04 localhost dhclient[9668]: DHCPDISCOVER on eno16777728 to 255.255.255.255 port 67 interval 11 (xid=0x7773726a)
Aug 7 17:15:05 localhost NetworkManager[916]: <warn> (eno16777728): DHCPv4 request timed out.
Aug 7 17:15:05 localhost NetworkManager[916]: <info> (eno16777728): DHCPv4 state changed unknown -> timeout
...

--------------------------------------------------------------------------------
more 特點:翻屏至文件尾部後自動退出

more - file perusal filter for crt viewing
表達格式:more [options] file [...]
[root@localhost ~]# man /etc/init.d/functions
...
;; stop) s=$"Stopping
$prog (via systemctl): " ;; reload|try‐
reload) s=$"Reloading $prog configuration (via
systemctl): " ;; restart|try‐restart|con‐
drestart) s=$"Restarting $prog (via systemctl): "
;; esac
Manual page functions line 1 (press h for help or q to quit)

--------------------------------------------------------------------------------
less

less - opposite of more
在less中可以使用之前在man裡面的搜索功能,可以簡單的認為less是more的加強版。

less翻屏至文件尾部後不自動退出。

本文永久更新鏈接地址:

http://xxxxxx/Linuxjc/1148627.html TechArticle

Copyright © Linux教程網 All Rights Reserved