鍍金池/ 教程/ Linux/ 文件內(nèi)容查閱
Linux 學(xué)習(xí)記錄--開機(jī)掛載錯誤
日志系統(tǒng)
數(shù)據(jù)流重定向
內(nèi)存交換空間的構(gòu)建
文件系統(tǒng)簡介
Linux 學(xué)習(xí)記錄--軟件安裝 RPM|SRPM|YUM
文件特殊權(quán)限
目錄配置 FHS
文件內(nèi)容查閱
Boot Loader
文件壓縮
Linux 學(xué)習(xí)記錄--文件權(quán)限
Linux 命令縮寫
命令與文件的查詢
文件|目錄的默認(rèn)權(quán)限與隱藏權(quán)限
shell script
服務(wù)
Linux 學(xué)習(xí)記錄--程序編譯與函數(shù)庫
正則表達(dá)式與其應(yīng)用
關(guān)機(jī)相關(guān)指令
shell
vim 與 vi 常用命令
系統(tǒng)調(diào)用:進(jìn)程控制
文件系統(tǒng)簡單操作
磁盤掛載與卸載
有名管道通訊
磁盤分區(qū),格式化與檢驗(yàn)
工作管理與進(jìn)程管理
匿名管道通訊
Linux 學(xué)習(xí)記錄--啟動流程
文件與目錄管理
管道命令
命名別名與歷史命令
文件備份|還原
shell變量
Linux 學(xué)習(xí)記錄--ACL 權(quán)限控制
內(nèi)核|內(nèi)核模塊編譯
文件管理相關(guān)系統(tǒng)編程

文件內(nèi)容查閱

cat:由第一行開始顯示文件內(nèi)容
tac:由最后一行開始顯示文件內(nèi)容
nl:顯示的時(shí)候,順便輸出行號
more:一頁一頁的顯示文件內(nèi)容
less:與 more 類似,但是它可以往前翻頁
head:只看頭幾行
tail:只看結(jié)尾幾行
touch:文件創(chuàng)建與文件時(shí)間修改

cat(concatenate)

語法:cat [-AbEnTv]
選項(xiàng)與參數(shù)
-A:相當(dāng)于-vET 的整合參數(shù)
-b:列出行號,僅針對非空白行做行號顯示
-n:輸出行號,空白與非空白都會列出
-E:將結(jié)尾的斷行字符¥顯示出來
-v:列出一些看不出的特殊字符
-T:將 Tab 按鍵以∧I 顯示出來

舉例


[root@localhost tmp]# cat /etc/issue
CentOS release 5.10 (Final)
Kernel \r on an \m

[root@localhost tmp]# cat -n /etc/issue
     1  CentOS release 5.10 (Final)
     2  Kernel \r on an \m
     3
[root@localhost tmp]# cat -A /etc/issue
CentOS release 5.10 (Final)$
Kernel \r on an \m$
$  

添加行號與打印(nl)

語法 :[root@www ~]# nl [-bnw] 文件
選項(xiàng)與參數(shù)
-b:指定行號指定的方式,主要有兩種:
-b a :表示不論是否為空行,也同樣列出行號(類似 cat -n);
-b t :如果有空行,空的那一行不要列出行號(默認(rèn)值);
-n:列出行號表示的方法,主要有三種:
-n ln :行號在螢?zāi)坏淖钭蠓斤@示;
-n rn :行號在自己欄位的最右方顯示,且不加 0 ;
-n rz :行號在自己欄位的最右方顯示,且加 0 ;
-w:行號欄位的占用的位數(shù)。

舉例


 [root@www ~]# nl /etc/issue
     1  CentOS release 5.3 (Final)
     2  Kernel \r on an \m

這個文件其實(shí)有三行,第三行為空白(沒有任何字節(jié)),  
因?yàn)樗强瞻仔?,所?nl 不會加上行號喔  

[root@www ~]# nl -b a /etc/issue
     1  CentOS release 5.3 (Final)
     2  Kernel \r on an \m
     3
[root@www ~]# nl -b a -n rz /etc/issue
000001  CentOS release 5.3 (Final)
000002  Kernel \r on an \m
000003
自動在自己欄位的地方補(bǔ)上 0 了~默認(rèn)欄位是六位數(shù),如果想要改成 3 位數(shù)?  

[root@www ~]# nl -b a -n rz -w 3 /etc/issue
001     CentOS release 5.3 (Final)
002     Kernel \r on an \m
003

語法:more|less文件

More:
空白鍵 (space):代表向下翻一頁;
Enter :代表向下翻『一行』;
/字串 :代表在這個顯示的內(nèi)容當(dāng)中,向下搜尋『字串』這個關(guān)鍵字;
f :立刻顯示出檔名以及目前顯示的行數(shù); q :代表立刻離開 more ,不再顯示該文件內(nèi)容。
b 或 [ctrl]-b :代表往回翻頁,不過這動作只對文件有用,對管線無用。

Less:
空白鍵 :向下翻動一頁;
[pagedown]:向下翻動一頁;
[pageup] :向上翻動一頁;
/字串 :向下搜尋『字串』的功能;
?字串 :向上搜尋『字串』的功能;
n :重復(fù)前一個搜尋 (與 / 或 ? 有關(guān)!)
N :反向的重復(fù)前一個搜尋 (與 / 或 ? 有關(guān)!)
q :離開 less 這個程序;

舉例


[root@localhost tmp]# more /etc/man.config 
#
# Generated automatically from man.conf.in by the
……..
# and to determine the correspondence between extensions and decompressors.
#
# MANBIN                /usr/local/bin/man
#
--More--(31%) 

取出前面幾行(head)

語法:head [-nnumber] 文件
選項(xiàng)與參數(shù):
-n:后面接數(shù)字,代表行數(shù)
number 默認(rèn)值是10 當(dāng) number 是負(fù)數(shù),代表列出前面所有行數(shù)但是不包括后面 number 行

取出后面幾行(tail)

語法:tail [-nnumber] 文件
選項(xiàng)與參數(shù):
-n:后面接數(shù)字,代表行數(shù)
number 默認(rèn)值是10 當(dāng) number 是正數(shù)(+ number),代表該文件從 number 以后才會列出來

修改文件時(shí)間|創(chuàng)建新文件(touch)

時(shí)間屬性
Mtime(modificationtime):當(dāng)文件內(nèi)容數(shù)據(jù)更改時(shí)就會更新這個時(shí)間,內(nèi)容數(shù)據(jù)指的是文件的內(nèi)容,不包括文件的權(quán)限和屬性
Ctime(Statetime):當(dāng)文件的狀態(tài)(權(quán)限和屬性)更改時(shí)會更新這個時(shí)間
Atime(accesstime):當(dāng)文件內(nèi)容被取用就會修改這個時(shí)間
舉例


[root@localhost ~]# ls -l --time-style=long-iso  /etc/man.config 默認(rèn)是修改mtime
-rw-r--r-- 1 root root 4617 2012-05-30 20:34 /etc/man.config
[root@localhost ~]# ls -l --time=ctime --time-style=long-iso  /etc/man.config
-rw-r--r-- 1 root root 4617 2014-02-14 10:06 /etc/man.config
[root@localhost ~]# ls -l --time=atime --time-style=long-iso  /etc/man.config
-rw-r--r-- 1 root root 4617 2014-02-21 10:19 /etc/man.config

語法:touch[-acdmt] 文件
選項(xiàng)與參數(shù)
-a:僅修改訪問時(shí)間 atime
-c:僅修改文件的時(shí)間,若該文件不存在則不創(chuàng)建新文件
-d:后面可接欲修改的日期,也可以使用—date=”時(shí)間或日期”
-m:僅修改 mtime
-t:后面可以接欲修改的時(shí)間

主要功能
創(chuàng)建一個空文件
修改文件日期(mtime,atime)
舉例


[root@localhost tmp]# cp -a /etc/man.config ./newman.config
[root@localhost tmp]# ls -l --time-style=long-iso  newman.config 指定時(shí)間格式
-rw-r--r-- 1 root root 4617 2012-05-30 20:34 newman.config
[root@localhost tmp]# touch -m -t 0709150203  newman.config //只修改mtime
[root@localhost tmp]# ls -l --time-style=long-iso  newman.config
-rw-r--r-- 1 root root 4617 2007-09-15 02:03 newman.config
 [root@localhost tmp]# ls -l --time=atime --time-style=long-iso  newman.config //只修改atime
-rw-r--r-- 1 root root 4617 2014-02-21 10:33 newman.config
[root@localhost tmp]# touch -a -t 0809150203  newman.config 
 [root@localhost tmp]# ls -l --time=atime --time-style=long-iso  newman.config
-rw-r--r-- 1 root root 4617 2008-09-15 02:03 newman.config
[root@localhost tmp]# 
[root@localhost tmp]# touch -d "2 days ago"  newman.config //默認(rèn)修改atime 與 mtime
[root@localhost tmp]# ls -l --time=atime --time-style=long-iso  newman.config
-rw-r--r-- 1 root root 4617 2014-02-19 10:36 newman.config
[root@localhost tmp]# ls -l  --time-style=long-iso  newman.config
-rw-r--r-- 1 root root 4617 2014-02-19 10:36 newman.config