用慣 unix / Linux 系統的人一定覺得命令列太好用了,加上 unix 上豐富的工具程式及 shell script,整個組合起來,豈是一個爽字可以形容… 視窗系統就是慢–點、點、點、選、點、點、放下滑鼠打字、選ok、ok、ok…

grep 應該是最好用的工具之一,用來搜尋文字檔案內特定的內容,有有心人在 Windows 也移植了它,在 可以抓到.

通常的用法像是
C> grep -i wp_title *.php
在 *.php 檔案中,尋找 wp_title 字串,-i 表示不管大小寫.
結果:
general-template.php:function wp_title($sep = '»', $display = true) {
general-template.php:   $title = apply_filters('wp_title', $title, $sep);

在 *.php 檔案中,找到一個檔案 (general-template.php) 出現兩次 wp_title.

搭配 wc (word count),用 pipe 連起來
C> grep -i wp_title *.php | wc
結果:
       2       14      150
算出結果有2列,14個字,150位元。如果結果有很多就愈顯好用。

包含 wc 的很多 unix 工具程式之 Windows/DOS 版可以在 取得,像 tail, gawk, sed, diff, patch 等等都很好用1,裡面也有個 grep,不過找目錄下檔案的內容不 work,grep 以上述版本較佳.

  1. unxutils 共包含下列 unix utilities: agrep, ansi2knr, basename, bc, bison, bunzip2, bzip2, bzip2recover, cat, chgrp, chmod, chown, cksum, cmp, comm, compress, cp, csplit, cut, date, dc, dd, df, diff, diff3, dircolors, dirname, du, echo, egrep, env, expand, expr, factor, fgrep, find, flex, fmt, fold, fsplit, gawk, gclip, gplay, grep, gsar, gunzip, gzip, head, id, indent, install, join, jwhois, less, lesskey, ln, logname, ls, m4, make, makedepend, makemsg, man, md5sum, mkdir, mkfifo, mknod, mv, mvdir, nl, od, paste, patch, pathchk, pclip, pr, printenv, printf, pwd, recode, rm, rman, rmdir, sdiff, sed, seq, shar, sleep, sort, split, stego, su, sum, sync, tac, tail, tar, tee, test, touch, tr, type, uname, unexpand, uniq, unrar, unshar, unzip, uudecode, uuencode, wc, wget, which, whoami, xargs, yes, zcat, zip(回文章)