使用shell过滤文本:
为什么下面这个不行呢?因为使用了管道!
[root@localhost shop]# find . -name "*.php" -mtime -90 | xargs ls -alt
//这个命令的结果是下面这个样子的,一长串。。。。
//然而,grep -l 命令的参数不可以是一长串的参数,所以用grep -l去过滤上面这个find命令的结果将会有错误
-rw-r--r-- 1 root root 2466 Dec 25 2014 ./languages/en_us/admin/payment.php
-rw-r--r-- 1 root root 1842 Dec 25 2014 ./languages/en_us/payment/alipay.php
-rw-r--r-- 1 root root 2437 Dec 25 2014 ./languages/zh_cn/admin/payment.php
-rw-r--r-- 1 root root 1675 Dec 25 2014 ./languages/zh_cn/payment/alipay.php
-rw-r--r-- 1 root root 2454 Dec 25 2014 ./languages/zh_tw/admin/payment.php
-rw-r--r-- 1 root root 6982 Dec 24 2014 ./includes/fckeditor/editor/dialog/fck_spellerpages/spellerpages/server-scripts/spellchecker.php
-rw-r--r-- 1 root root 35385 Dec 24 2014 ./includes/lib_base.php
[root@localhost shop]# grep -l "eval" `find . -name "*.php" -mtime -90 | xargs ls -alt`
grep: invalid option -- -
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.
正确的命令是:
[root@localhost shop]# find . -name "*.php" -mtime -90
//当我们不使用xargs,得出来的结果如下,这正是grep -l所支持的参数形式!
./includes/fckeditor/editor/dialog/fck_spellerpages/spellerpages/server-scripts/spellchecker.php
./includes/lib_base.php
./config.php
./data/config.php
./data/global.php
./languages/en_us/payment/alipay.php
[root@localhost shop]# grep -l "eval" `find . -name "*.php" -mtime -90`
./includes/lib_base.php
./config.php
./data/global.php
./temp/compiled/admin/menu.htm.php