檔案內容查閱
cat:由第一行開始顯示檔案內容
tac:由最後一行開始顯示檔案內容
nl:顯示的時候,順便輸出行號
more:一頁一頁的顯示檔案內容
less:與more類似,但是它可以往前翻頁
head:只看頭幾行
tail:只看結尾幾行
touch:檔案建立與檔案時間修改
cat(concatenate)
文法:cat[-AbEnTv]
選項與參數:
-A:相當於-vET的整合參數
-b:列出行號,僅針對非空白行做行號顯示
-n:輸出行號,空白與非空白都會列出
-E:將結尾的斷行字元¥顯示出來
-v:列出一些看不出的特殊字元
-T:將Tab按鍵以∧I顯示出來
舉例:
[root@localhost tmp]# cat /etc/issueCentOS 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/issueCentOS release 5.10 (Final)$Kernel \r on an \m$$
添加行號與列印(nl)
文法:[root@www~]#nl[-bnw]檔案
選項與參數:
-b:指定行號指定的方式,主要有兩種:
-ba:表示不論是否為空白行,也同樣列出行號(類似cat-n);
-bt:如果有空行,空的那一行不要列出行號(預設值);
-n:列出行號表示的方法,主要有三種:
-nln:行號在螢幕的最左方顯示;
-nrn:行號在自己欄位的最右方顯示,且不加0;
-nrz:行號在自己欄位的最右方顯示,且加0;
-w:行號欄位的佔用的位元。
舉例
[root@www ~]# nl /etc/issue 1 CentOS release 5.3 (Final) 2 Kernel \r on an \m這個檔案其實有三行,第三行為空白(沒有任何位元組),因為他是空白行,所以 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/issue000001 CentOS release 5.3 (Final)000002 Kernel \r on an \m000003自動在自己欄位的地方補上 0 了~預設欄位是六位元,如果想要改成 3 位元?[root@www ~]# nl -b a -n rz -w 3 /etc/issue001 CentOS release 5.3 (Final)002 Kernel \r on an \m003
文法:more|less檔案
More:
空白鍵(space):代表向下翻一頁;
Enter:代表向下翻『一行』;
/字串:代表在這個顯示的內容當中,向下搜尋『字串』這個關鍵字;
:f:立刻顯示出檔名以及目前顯示的行數;
q:代表立刻離開more,不再顯示該檔案內容。
b或[ctrl]-b:代表往回翻頁,不過這動作只對檔案有用,對管線無用。
Less:
空白鍵:向下翻動一頁;
[pagedown]:向下翻動一頁;
[pageup]:向上翻動一頁;
/字串:向下搜尋『字串』的功能;
?字串:向上搜尋『字串』的功能;
n:重複前一個搜尋(與/或?有關!)
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]檔案
選項與參數:
-n:後面接數字,代表行數
number預設值是10當number是負數,代表列出前面所有行數但是不包括後面number行
取出後面幾行(tail)
文法:tail[-nnumber]檔案
選項與參數:
-n:後面接數字,代表行數
number預設值是10當number是正數(+number),代表該檔案從number以後才會列出來
修改檔案時間|建立新檔案(touch)
時間屬性
Mtime(modificationtime):當檔案內容資料更改時就會更新這個時間,內容資料指的是檔案的內容,不包括檔案的許可權和屬性
Ctime(Statetime):當檔案的狀態(許可權和屬性)更改時會更新這個時間
Atime(accesstime):當檔案內容被取用就會修改這個時間
舉例:
[root@localhost ~]# ls -l --time-style=long-iso /etc/man.config 預設是修改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]檔案
選項與參數:
-a:僅修改訪問時間atime
-c:僅修改檔案的時間,若該檔案不存在則不建立新檔案
-d:後面可接欲修改的日期,也可以使用—date=”時間或日期”
-m:僅修改mtime
-t:後面可以接欲修改的時間
主要功能:
建立一個空檔案
修改檔案日期(mtime,atime)
舉例:
[root@localhost tmp]# cp -a /etc/man.config ./newman.config[root@localhost tmp]# ls -l --time-style=long-iso newman.config 指定時間格式-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 //預設修改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