要在檔案裡找出符合某段文字的行,最直覺的工具就是 grep。
語法:grep string file
例如 grep abc file1,它會把 file1 中所有含 abc 的整行印出來。搭配 -i 忽略大小寫、-n 顯示行號、-v 反選,實務上非常好用。
whereis command:顯示指令的所在路徑。
which command:顯示指令路徑,同時列出使用者自訂的別名。
whatis command:用一行摘要說明這個指令是做什麼的。
find search-path -name filename -print:在指定路徑底下搜尋特定檔案並印出路徑,例如 find / -name file1 -print 就是從根目錄開始找 file1。
語法:diff [-r] name1 name2,兩個參數可以都是檔案,也可以都是目錄。
diff file1 file2 會逐行指出兩個檔案的不同;加上 -r 後 diff -r dir1 dir2 則會遞迴比對兩個目錄下所有檔案的差異。
要指定預設印表機,可在 .login 中設定環境變數 PRINTER,例如 setenv PRINTER sp2,之後的列印工作就會送到 sp2。
lpr [-Pprinter-name] filename,如 lpr file1 或 lpr -Psp2 file1。
enscript [-Pprinter-name] filename,如 enscript -Psp1 file3,會以較美觀的排版輸出。
ptroff [-Pprinter-name] [-man][-ms] filename。例如 ptroff -man /usr/local/man/man1/ptroff.1 以 troff 格式印出 ptroff 的使用手冊;ptroff -Psp2 -man /usr/man/man1/lpr1 則是送到 sp2 印出 lpr 的手冊。
lpq [-Pprinter-name] 可以查詢印表機狀態、工作順序編號與提出的使用者,例如 lpq -Psp1。
!! 重複執行上一個指令;!n 執行編號 n 的指令;!string 重複執行最近一次以 string 開頭的指令,例如 !cat。
想先看看上一個指令的內容再決定要不要執行,可以用 !!:p 把它印出來而不執行。