-
10 個 UNIX 良好使用習慣
Posted on December 16th, 2006 1 comment這是在 IBM developerWorks 的文章,列出了 10 個在 *NIX 下良好的使用習慣,其中有些也有犯下。以下是作者的10 個建議,並加上簡單中文簡介:
1. Make directory trees in a single swipe.
可以在用 mkdir 時加上 -p 選項,就可以遞迴建立目錄。2. Change the path; do not move the archive.
在 tar 指令加上 -C 選項,指令解壓的目的地,不需把壓縮檔移動。3. Combine your commands with control operators.
用 control operators 合拼指令,例如 “;”, “&&” 及 “||”。4. Quote variables with caution.
用雙引號括起變數。5. Use escape sequences to manage long input.
用 escape sequences 處理較長的指令輸入。6. Group your commands together in a list.
group 起一組指令。7. Use xargs outside of find.
用 xargs 過濾從 find 得出的結果。8. Know when grep should do the counting — and when it should step aside.
grep 可以加上 -c 選項計算結果總數,不用透過 pipe 執行 wc。9. Match certain fields in output, not just lines.
可以用類似 awk 這些工具配合 grep 使用,傳回指定欄位,不是一整行結果。10. Stop piping cats.
不要用 cat 透過 pipe 報行 grep 搜索檔案,改用 grep 直接執行。以上中文解釋可能寫得不好,詳細內容可參考原文: Learn 10 good UNIX usage habits
One response to “10 個 UNIX 良好使用習慣”
-
thexool December 18th, 2006 at 15:43
第3條翻譯有問題。”;” 不是任何操作符,他表示前一個命令之行完畢就繼續下一個命令,不判斷上一個命令的結果是否正确。
“&&” 和 “||” 就不同。”&&”的意思是上一個命令執行成功才執行下一個命令,返回結果是兩個命令都成功則為true,否則為false;”||”的意思是上一格命令失敗了才執行下一個命令,返回的結果是兩邊的命令有一個成功即為true,只有全部失敗時才位false。
改一下吧,呵呵
Leave a reply
-
