linux 啟動(dòng)時(shí)會(huì)看到很多啟動(dòng)信息。 一般 linux 啟動(dòng)分為5個(gè)階段:
內(nèi)核的引導(dǎo) Boot運(yùn)行 init系統(tǒng)初始化建立終端用戶(hù)登陸系統(tǒng)Linux 常見(jiàn)的rc的含義
在linux中經(jīng)常會(huì)碰到 bashrc,rc.d,rc.local等帶有rc的文件或目錄,一般都是啟動(dòng)時(shí)需要加載的。
英文原義:RC (runcom,run command)中文釋義:含有程序(應(yīng)用程序甚至操作系統(tǒng))啟動(dòng)指令的腳本文件注解:這一文件在操作系統(tǒng)啟動(dòng)時(shí)會(huì)自動(dòng)執(zhí)行,它含有要運(yùn)行的指令(命令或其它腳本)列表。
真正的rc啟動(dòng)腳本實(shí)際上都是放在/etc/rc.d/init.d/目錄下。 而這些rc啟動(dòng)腳本有著類(lèi)似的用法,它們一般能接受start、stop、restart、status等參數(shù)。
用戶(hù)登陸方式
一般來(lái)說(shuō),用戶(hù)的登錄方式有三種:
Linux 的賬號(hào)驗(yàn)證程序是 login,login 會(huì)接收 mingetty 傳來(lái)的用戶(hù)名作為用戶(hù)名參數(shù)。 然后 login 會(huì)對(duì)用戶(hù)名進(jìn)行分析:如果用戶(hù)名不是 root,且存在 /etc/nologin 文件,login 將輸出 nologin 文件的內(nèi)容,然后退出。 這通常用來(lái)系統(tǒng)維護(hù)時(shí)防止非root用戶(hù)登錄。只有/etc/securetty中登記了的終端才允許 root 用戶(hù)登錄,如果不存在這個(gè)文件,則 root 用戶(hù)可以在任何終端上登錄。 /etc/usertty文件用于對(duì)用戶(hù)作出附加訪問(wèn)限制,如果不存在這個(gè)文件,則沒(méi)有其他限制。
Linux 文件屬性
Linux 是一種典型的多用戶(hù)系統(tǒng),不同的用戶(hù)處于不同的地位,擁有不同的權(quán)限。 為了保護(hù)系統(tǒng)的安全性,Linux系統(tǒng)對(duì)不同的用戶(hù)訪問(wèn)同一文件(包括目錄)的權(quán)限做了不同的規(guī)定。
在 Linux 中,可以使用 ls -l 命令來(lái)顯示一個(gè)文件的屬性以及文件所屬的用戶(hù)和組。如:

代碼語(yǔ)言:Javascript代碼運(yùn)行次數(shù):0運(yùn)行復(fù)制
ls -ltotal 23028-rw-rw-r-- 1 deploy deploy 2 Dec 25 21:54 10-rw-rw-r-- 1 deploy deploy 0 Dec 18 16:48 6-rw-rw-r-- 1 deploy deploy 97119 Dec 20 23:52 arthas-boot.jar-rw-rw-r-- 1 deploy deploy 461 Dec 18 20:49 awkvars.out-rw-rw-r-- 1 deploy deploy 5 Dec 27 12:36 emp.awk-rw-r--r-- 1 deploy deploy 81 Dec 17 16:12 emp.data-rw-r--r-- 1 deploy deploy 23 Dec 29 12:35 hello.txt-rw-rw-r-- 1 deploy deploy 43379 Dec 28 12:27 index.html-rw-r--r-- 1 deploy deploy 109230 Dec 18 14:52 loan.txtdrwxr-xr-x 4 deploy deploy 4096 Jan 9 16:17 lua-5.3.0-rw-rw-r-- 1 deploy deploy 278045 Jan 6 2015 lua-5.3.0.tar.gzdrwxr-xr-x 4 deploy deploy 4096 Mar 18 2015 luarocks-2.2.1-rw-rw-r-- 1 deploy deploy 114431 Oct 31 04:52 luarocks-2.2.1.tar.gzdrwxr-xr-x 19 deploy deploy 4096 Dec 28 14:18 Python-3.7.2-rw-rw-r-- 1 deploy deploy 22897802 Dec 24 11:42 Python-3.7.2.tgz
在 Linux 中第一個(gè)字符代表這個(gè)文件時(shí)目錄、文件或鏈接文件等等。
為 d 表示是目錄為 – 表示是文件為 l 表示是鏈接文件(link file)為 b 表示為裝置文件里面的可供儲(chǔ)存的接口設(shè)備(可隨機(jī)存取裝置)為 c 表示為裝置文件里面的串行端口設(shè)備,例如鍵盤(pán)、鼠標(biāo)(一次性讀取裝置)
接下來(lái)的字符中,且均為 rwx 的三個(gè)參數(shù)的組合,其中 r 表示可讀,w 表示可寫(xiě), x 表示可執(zhí)行。 這三個(gè)權(quán)限的位置不會(huì)改變,如果沒(méi)有權(quán)限,就會(huì)出現(xiàn)減號(hào) -。

Linux 文件屬性和屬組
對(duì)于文件來(lái)說(shuō),它都有一個(gè)特定的所有者,也就是對(duì)該文件具有所有權(quán)的用戶(hù)。 同時(shí),在 Linux 系統(tǒng)中,用戶(hù)是按組分類(lèi)的,一個(gè)用戶(hù)屬于一個(gè)或多個(gè)組。 文件所有者以外的用戶(hù)又可以分為文件所有者的同組用戶(hù)和其他用戶(hù)。
因此,Linux 系統(tǒng)按文件所有者、文件所有者同組用戶(hù)和其它用戶(hù)來(lái)規(guī)定了不同的文件訪問(wèn)權(quán)限。
代碼語(yǔ)言:JavaScript代碼運(yùn)行次數(shù):0運(yùn)行復(fù)制
ls -ltotal 64drwxr-xr-x 2 root root 4096 Feb 15 14:46 crondrwxr-xr-x 3 mysql mysql 4096 Apr 21 2014 mysql
在上面實(shí)例中,mysql 文件是一個(gè)目錄文件,屬主和屬組都為 mysql,屬主有可讀、可寫(xiě)、可執(zhí)行的權(quán)限; 與屬主同組的其他用戶(hù)有可讀和可執(zhí)行的權(quán)限;其它用戶(hù)也有可讀和可執(zhí)行的權(quán)限。
對(duì)于 root 用戶(hù),一般情況下,文件的權(quán)限對(duì)其不起作用。
更改文件屬性1. chgrp 更改文件屬組-R : 遞歸更改文件屬組,就是在更改某個(gè)目錄文件的屬組時(shí),如果加上 -R 的參數(shù),那么該目錄下的所有文件的屬組都會(huì)更改。2. chown 更改文件屬主,也可以同時(shí)更改文件屬組
進(jìn)入 /root 目錄(~)將install.log的擁有者改為bin這個(gè)賬號(hào):
代碼語(yǔ)言:javascript代碼運(yùn)行次數(shù):0運(yùn)行復(fù)制
[root@www ~] cd ~[root@www ~]# chown bin install.log[root@www ~]# ls -l-rw-r--r-- 1 bin users 68495 Jun 25 08:53 install.log
將install.log的擁有者與群組改回為root:
代碼語(yǔ)言:javascript代碼運(yùn)行次數(shù):0運(yùn)行復(fù)制
[root@www ~]# chown root:root install.log[root@www ~]# ls -l-rw-r--r-- 1 root root 68495 Jun 25 08:53 install.log
chmode: 更改文9個(gè)屬性
Linux 文件屬性有2中設(shè)置方法,一種是數(shù)字,一種是符號(hào)。 Linux 文件的基本權(quán)限有9個(gè)。分別是owner/group/others三種身份各有自己的read/write/execute權(quán)限。 文件權(quán)限字符為 -rwxrwxrwx 這九個(gè)權(quán)限是三個(gè)三個(gè)一組的。其中,我們可以使用數(shù)字來(lái)代表各個(gè)權(quán)限,個(gè)權(quán)限的分?jǐn)?shù)對(duì)照表如下:
r: 4w: 2x: 1
每種身份各自的三個(gè)權(quán)限分?jǐn)?shù)是需要累加的。 例如 -rwxrwx— 分?jǐn)?shù)則為:
owner: rwx = 4+2+1 = 7group: rwx = 4+2+1 = 7others:— = 0+0+0 = 0
所以該文件的權(quán)限數(shù)字就是770了。
變更權(quán)限的指令chmod語(yǔ)法是這樣的:
選項(xiàng)與參數(shù):
xyz: 就是剛剛提到的數(shù)字類(lèi)型的權(quán)限屬性,為 rwx 屬性數(shù)值的相加。-R : 進(jìn)行遞歸的持續(xù)變更,亦即連同次目錄下的所有文件都會(huì)變更
實(shí)例,將 .hashrc 文件的所有權(quán)限都設(shè)定為啟用,則命令如下:
代碼語(yǔ)言:javascript代碼運(yùn)行次數(shù):0運(yùn)行復(fù)制
[root@www ~]# ls -al .bashrc-rw-r--r-- 1 root root 395 Jul 4 11:45 .bashrc# 777表示 -rwxrwxrwx 的權(quán)限符號(hào)表示[root@www ~]# chmod 777 .bashrc [root@www ~]# ls -al .bashrc-rwxrwxrwx 1 root root 395 Jul 4 11:45 .bashrc
符號(hào)類(lèi)型改變文件權(quán)限
還有一個(gè)改變權(quán)限的方法,從之前的介紹中我們可以發(fā)現(xiàn)基本上就9個(gè)權(quán)限分別是:
ownergroupothers
那么我們可以用 u、g 和 o 來(lái)代表三種身份的權(quán)限!
如果我們要將文件設(shè)置為 -rwxr-xr– ,可以使用 chmod u=rwx,g=rx,o=r 文件名 來(lái)設(shè)定:
代碼語(yǔ)言:javascript代碼運(yùn)行次數(shù):0運(yùn)行復(fù)制
[deploy@sz-local3 lff]$ ll hello.txt -rwxrwx--- 1 deploy deploy 23 Dec 29 12:35 hello.txt[deploy@sz-local3 lff]$ chmod u=rwx,g=rwx,o=rwx hello.txt [deploy@sz-local3 lff]$ ll hello.txt -rwxrwxrwx 1 deploy deploy 23 Dec 29 12:35 hello.txt
拿掉全部人的可執(zhí)行權(quán)限:
代碼語(yǔ)言:javascript代碼運(yùn)行次數(shù):0運(yùn)行復(fù)制
[deploy@sz-local3 lff]$ ll hello.txt -rwxrwxrwx 1 deploy deploy 23 Dec 29 12:35 hello.txt[deploy@sz-local3 lff]$ chmod a-x hello.txt [deploy@sz-local3 lff]$ ll hello.txt -rw-rw-rw- 1 deploy deploy 23 Dec 29 12:35 hello.txt
更多實(shí)例:
代碼語(yǔ)言:javascript代碼運(yùn)行次數(shù):0運(yùn)行復(fù)制
[deploy@sz-local3 lff]$ ll hello.txt -rw-rw-rw- 1 deploy deploy 23 Dec 29 12:35 hello.txt[deploy@sz-local3 lff]$ chmod a+rwx hello.txt [deploy@sz-local3 lff]$ ll hello.txt -rwxrwxrwx 1 deploy deploy 23 Dec 29 12:35 hello.txt[deploy@sz-local3 lff]$ chmod u-x,g-x,o-x hello.txt [deploy@sz-local3 lff]$ ll hello.txt -rw-rw-rw- 1 deploy deploy 23 Dec 29 12:35 hello.txt
Linux 文件與目錄管理處理目錄的常用命令ls: 列出目錄cd : 切換目錄pwd : 顯示當(dāng)前目錄mkdir : 創(chuàng)建一個(gè)新的目錄rmdir : 刪除一個(gè)空目錄cp : 復(fù)制文件或目錄rm : 移除文件或目錄mv : 移動(dòng)文件或目錄,或修改文件與目錄的名稱(chēng)
可以使用 man [命令] 來(lái)查看各個(gè)命令的使用文檔,如: man cp等。
ls (列出目錄)
選項(xiàng)與參數(shù):
-a : 全部的文件,連同隱藏(開(kāi)頭為 . 的文件)一起列出來(lái)-d : 僅僅列出目錄本身,而不是列出目錄內(nèi)的文件內(nèi)容-l :長(zhǎng)數(shù)據(jù)串列出,包含文件的屬性與權(quán)限等數(shù)據(jù)cd (切換目錄)
cd 是 Change Directory 的縮寫(xiě)。
pwd (顯示當(dāng)前所在的目錄)-P : 顯示出確實(shí)的路徑,而非使用連接路徑mkdir (創(chuàng)建新目錄)
選項(xiàng)參數(shù):
-m : 配置文件的權(quán)限!直接配置,無(wú)需使用默認(rèn)權(quán)限。-p : 幫助你直接將所需要的目錄(包含上一級(jí)目錄遞歸創(chuàng)建)代碼語(yǔ)言:javascript代碼運(yùn)行次數(shù):0運(yùn)行復(fù)制
[deploy@sz-local3 lff]$ mkdir test #創(chuàng)建目錄test[deploy@sz-local3 lff]$ ls10 arthas-boot.jar emp.awk hello.txt loan.txt lua-5.3.0.tar.gz luarocks-2.2.1.tar.gz Python-3.7.2.tgz tmpDir6 awkvars.out emp.data index.html lua-5.3.0 luarocks-2.2.1 Python-3.7.2 test[deploy@sz-local3 lff]$ mkdir test1/test2/test3 #創(chuàng)建連接目錄,失敗mkdir: cannot create directory `test1/test2/test3': No such file or directory[deploy@sz-local3 lff]$ mkdir -p test1/test2/test3 #加上-p參數(shù)后,創(chuàng)建連接目錄OK[deploy@sz-local3 lff]$ ls10 arthas-boot.jar emp.awk hello.txt loan.txt lua-5.3.0.tar.gz luarocks-2.2.1.tar.gz Python-3.7.2.tgz test16 awkvars.out emp.data index.html lua-5.3.0 luarocks-2.2.1 Python-3.7.2 test tmpDir
實(shí)例: 創(chuàng)建權(quán)限為 rwx–x–x 的目錄:
代碼語(yǔ)言:javascript代碼運(yùn)行次數(shù):0運(yùn)行復(fù)制
[deploy@sz-local3 test1]$ mkdir test2[deploy@sz-local3 test1]$ lltotal 4drwxrwxr-x 2 deploy deploy 4096 Jan 15 19:55 test2[deploy@sz-local3 test1]$ mkdir -m 711 test7 # 指定權(quán)限 rwx--x--x[deploy@sz-local3 test1]$ lltotal 8drwxrwxr-x 2 deploy deploy 4096 Jan 15 19:55 test2drwx--x--x 2 deploy deploy 4096 Jan 15 19:56 test7
rmdir (刪除空的目錄)
選項(xiàng)參數(shù):
-p : 連同上一級(jí)(空的)目錄也一起刪除代碼語(yǔ)言:javascript代碼運(yùn)行次數(shù):0運(yùn)行復(fù)制
# 創(chuàng)建連接目錄[deploy@sz-local3 test1]$ mkdir -p tst1/tst2/tst3/tst4 [deploy@sz-local3 test1]$ lstst1# 使用 rmdir 命令嘗試刪除,無(wú)法刪除存在內(nèi)容的目錄 [deploy@sz-local3 test1]$ rmdir tst1rmdir: failed to remove `tst1': Directory not empty[deploy@sz-local3 test1]$ rmdir -p tst1rmdir: failed to remove `tst1': Directory not empty# 使用 rmdir -p 刪除上一級(jí)空目錄[deploy@sz-local3 test1]$ rmdir -p tst1/tst2/tst3/tst4
注意: rmdir 僅能刪除空的目錄,使用 rm 命令可以來(lái)刪除非空目錄。
cp (復(fù)制文件或目錄)
選項(xiàng)與參數(shù):
-a : 相當(dāng)于 -pdr。-d : 若來(lái)源為連接屬性(link file),則復(fù)制連接檔屬性而非文件本身-f : 為強(qiáng)制的意思,若目標(biāo)文件已經(jīng)存在且無(wú)法開(kāi)啟,則移除后再?lài)L試一次-i : 若目標(biāo)檔已存在,在覆蓋時(shí)會(huì)先詢(xún)問(wèn)動(dòng)作的進(jìn)行-l : 進(jìn)行硬式連結(jié)(hard link)的連結(jié)檔創(chuàng)建,而非復(fù)制文件本身;-p : 連同文件的屬性一同復(fù)制過(guò)去,而非使用默認(rèn)屬性-r : 遞歸復(fù)制,用于目錄的復(fù)制行為-s : 復(fù)制成為符號(hào)鏈接檔,即快捷方式-u : 若目標(biāo)比源舊才升級(jí)目標(biāo)檔代碼語(yǔ)言:javascript代碼運(yùn)行次數(shù):0運(yùn)行復(fù)制
[deploy@sz-local3 test1]$ lltotal 0-rwxrwxrwx 1 deploy deploy 0 Jan 15 20:21 hello.txt[deploy@sz-local3 test1]$ cp hello.txt hello2.txt[deploy@sz-local3 test1]$ lltotal 0-rwxrwxr-x 1 deploy deploy 0 Jan 15 20:26 hello2.txt #默認(rèn)屬性-rwxrwxrwx 1 deploy deploy 0 Jan 15 20:21 hello.txt[deploy@sz-local3 test1]$ cp -p hello.txt hello3.txt #連同屬性賦值[deploy@sz-local3 test1]$ [deploy@sz-local3 test1]$ lltotal 0-rwxrwxr-x 1 deploy deploy 0 Jan 15 20:26 hello2.txt-rwxrwxrwx 1 deploy deploy 0 Jan 15 20:21 hello3.txt-rwxrwxrwx 1 deploy deploy 0 Jan 15 20:21 hello.txt
rm (移除文件或目錄)
選項(xiàng)與參數(shù):
-f : 忽略不存在的文件,不會(huì)出現(xiàn)警告信息-i : 互動(dòng)模式,在刪除前會(huì)詢(xún)問(wèn)使用者是否動(dòng)作-r : 遞歸刪除。代碼語(yǔ)言:javascript代碼運(yùn)行次數(shù):0運(yùn)行復(fù)制
[deploy@sz-local3 test1]$ lshello2.txt hello3.txt hello.txt[deploy@sz-local3 test1]$ rm -i hello.txt rm: remove regular empty file `hello.txt'? n #取消刪除[deploy@sz-local3 test1]$ lshello2.txt hello3.txt hello.txt[deploy@sz-local3 test1]$ rm -i hello.txt rm: remove regular empty file `hello.txt'? y #確認(rèn)刪除[deploy@sz-local3 test1]$ lshello2.txt hello3.txt[deploy@sz-local3 test1]$ rm -f hello2.txt [deploy@sz-local3 test1]$ lshello3.txt[deploy@sz-local3 test1]$ rm -rf hello3.txt [deploy@sz-local3 test1]$ ls
mv (移動(dòng)文件與目錄,或修改名稱(chēng))
選項(xiàng)與參數(shù):
-f : 強(qiáng)制。如果目標(biāo)文件已經(jīng)存在,不會(huì)詢(xún)問(wèn),直接覆蓋。-i :若目標(biāo)文件已存在,則詢(xún)問(wèn)是否覆蓋。-u : 若目標(biāo)文件已存在,且源比較新,才會(huì)升級(jí)。代碼語(yǔ)言:javascript代碼運(yùn)行次數(shù):0運(yùn)行復(fù)制
[deploy@sz-local3 test1]$ cat hello.txt hello[deploy@sz-local3 test1]$ cat boy.txt boy[deploy@sz-local3 test1]$ mv hello.txt boy.txt # 將hello.txt命名為boy.txt,原來(lái)的boy.txt沒(méi)了[deploy@sz-local3 test1]$ lsboy.txt tmpdir[deploy@sz-local3 test1]$ cat boy.txt hello[deploy@sz-local3 test1]$ mv boy.txt tmpdir/[deploy@sz-local3 test1]$ lstmpdir[deploy@sz-local3 test1]$ cd tmpdir/[deploy@sz-local3 tmpdir]$ lsboy.txt[deploy@sz-local3 test1]$ echo 'hello' > hello.txt[deploy@sz-local3 test1]$ echo 'boy' > boy.txt[deploy@sz-local3 test1]$ mv -i hello.txt boy.txt #提示是否覆蓋已存在的boy.txt文件mv: overwrite `boy.txt'?
Linux 文件內(nèi)容查看
Linux 系統(tǒng)中使用以下命令來(lái)查看文件的內(nèi)容:
cat : 由第一行開(kāi)始顯示內(nèi)容tac : 從最后一行開(kāi)始顯示,可以看出 tac 是 cat 的倒寫(xiě)nl : 顯示的時(shí)候,順道輸出行號(hào)more : 一頁(yè)一頁(yè)的顯示文件less : 與 more 類(lèi)似,但是比more更好的是,less可以往前翻頁(yè)head : 只看頭幾行tail : 只看尾幾行cat 由第一行開(kāi)始顯示文件內(nèi)容
選項(xiàng)與參數(shù):
-A : 相當(dāng)于 -vET 的組合項(xiàng),可列出一些特殊字符而不是空白而已-b : 列出行號(hào),僅針對(duì)非空白行做行號(hào)顯示,空白行不標(biāo)行號(hào)-E : 將結(jié)尾的斷行字節(jié)$顯示出來(lái)-n : 列出行號(hào),連同空白行也會(huì)有行號(hào),與 -b 選項(xiàng)不同-T : 將tab鍵以 ^| 顯示出倆-v : 列出一些看不出來(lái)的特殊字符tac 和cat相反
QuickSortTest.java 的內(nèi)容如下:
代碼語(yǔ)言:javascript代碼運(yùn)行次數(shù):0運(yùn)行復(fù)制
package org.byron4j.cookbook.algrithms;import org.junit.Test;public class QuickSortTest { @Test public void test(){ int[] arr = new int[]{6, 2, 4, 1, 5, 9}; QuickSort.sortCore(arr, 0, 5); for (int i : arr) { System.out.println(i); } }}
示例如下:
代碼語(yǔ)言:javascript代碼運(yùn)行次數(shù):0運(yùn)行復(fù)制
[deploy@sz-local3 test1]$ cat QuickSortTest.java package org.byron4j.cookbook.algrithms;import org.junit.Test;public class QuickSortTest { @Test public void test(){ int[] arr = new int[]{6, 2, 4, 1, 5, 9}; QuickSort.sortCore(arr, 0, 5); for (int i : arr) { System.out.println(i); } }}[deploy@sz-local3 test1]$ [deploy@sz-local3 test1]$ [deploy@sz-local3 test1]$ tac QuickSortTest.java } } } System.out.println(i); for (int i : arr) { QuickSort.sortCore(arr, 0, 5); int[] arr = new int[]{6, 2, 4, 1, 5, 9}; public void test(){ @Testpublic class QuickSortTest {import org.junit.Test;package org.byron4j.cookbook.algrithms;
nl 顯示行號(hào)查看內(nèi)容
選項(xiàng)與參數(shù):
-b : 指定行號(hào)指定的方式,主要有兩種: -b a:表示不論是否為空行,也同樣列出行號(hào)(類(lèi)似 cat -n);-b t:如果有空行,空的那一行不要列出行號(hào)(默認(rèn)值)-n :列出行號(hào)表示的方法,有三種: -n ln : 行號(hào)在屏幕的最左方顯示-n rn : 行號(hào)在行號(hào)欄位的最右方顯示-n rz : 行號(hào)在行號(hào)欄位的最右方顯示,且補(bǔ)足0-w : 行號(hào)欄位的占用的位數(shù)
實(shí)例,分別展示了行號(hào)在行號(hào)欄位的展示位置:
代碼語(yǔ)言:javascript代碼運(yùn)行次數(shù):0運(yùn)行復(fù)制
[deploy@sz-local3 test1]$ nl -nln QuickSortTest.java 1 package org.byron4j.cookbook.algrithms;2 3 import org.junit.Test;4 5 public class QuickSortTest {6 @Test7 public void test(){8 int[] arr = new int[]{6, 2, 4, 1, 5, 9};9 QuickSort.sortCore(arr, 0, 5);10 for (int i : arr) {11 System.out.println(i);12 }13 }14 }[deploy@sz-local3 test1]$ nl -nrn QuickSortTest.java 1 package org.byron4j.cookbook.algrithms; 2 3 import org.junit.Test; 4 5 public class QuickSortTest { 6 @Test 7 public void test(){ 8 int[] arr = new int[]{6, 2, 4, 1, 5, 9}; 9 QuickSort.sortCore(arr, 0, 5); 10 for (int i : arr) { 11 System.out.println(i); 12 } 13 } 14 }[deploy@sz-local3 test1]$ nl -nrz QuickSortTest.java 000001 package org.byron4j.cookbook.algrithms;000002000003 import org.junit.Test;000004000005 public class QuickSortTest {000006 @Test000007 public void test(){000008 int[] arr = new int[]{6, 2, 4, 1, 5, 9};000009 QuickSort.sortCore(arr, 0, 5);000010 for (int i : arr) {000011 System.out.println(i);000012 }000013 }000014 }
more 一頁(yè)一頁(yè)的翻動(dòng)
lovelyman.txt 摘錄了魏巍的《誰(shuí)是最可愛(ài)的人?》文章。下面以此為例演示:

使用了 more lovelyman.txt查看文件內(nèi)容,一頁(yè)后顯示了當(dāng)前所占文件內(nèi)容的比例。 在 more 這個(gè)程序的運(yùn)行過(guò)程中,你有幾個(gè)按鍵可以按的:
空白鍵 : 代表向下翻一頁(yè)Enter : 代表向下翻一行/str : 代表這個(gè)顯示的內(nèi)容當(dāng)中,向下搜尋str這個(gè)關(guān)鍵字:f : 立刻顯示出文檔名以及當(dāng)前顯示的行數(shù)q : quit,表示立刻離開(kāi)more,不再顯示該文件內(nèi)容b 或 ctrl-b : 代表往回翻頁(yè),但是這只對(duì)文件有用,對(duì)管道無(wú)用less 一頁(yè)一頁(yè)翻動(dòng)
less 運(yùn)行時(shí)可以輸入的命令有:
空白鍵 : 向下翻一頁(yè)pagedow : 向下翻一頁(yè)pageup : 向上翻一頁(yè)/str : 向下搜尋str?str : 向上搜尋strn : 重復(fù)前一個(gè)搜尋(與/或?相關(guān))N : 反向的重復(fù)前一個(gè)搜尋(與/或?相關(guān))q : 離開(kāi)less這個(gè)程序head 去除文件前面幾行代碼語(yǔ)言:javascript代碼運(yùn)行次數(shù):0運(yùn)行復(fù)制
[deploy@sz-local3 test1]$ head -n 5 QuickSortTest.java package org.byron4j.cookbook.algrithms;import org.junit.Test;public class QuickSortTest {
tail 取出文件后面幾行-n : 后面接數(shù)字,代表顯示幾行的意思-f :表示持續(xù)偵測(cè)后面所接的檔名,要等到按下ctrl-c才會(huì)結(jié)束tail的偵測(cè)代碼語(yǔ)言:javascript代碼運(yùn)行次數(shù):0運(yùn)行復(fù)制
[deploy@sz-local3 test1]$ tail -n 5 QuickSortTest.java for (int i : arr) { System.out.println(i); } }}