Warning: include(/home/blog66rr/public_html/wp-content/plugins/hyper-cache/cache.php): failed to open stream: No such file or directory in /home/blog66rr/public_html/wp-content/advanced-cache.php on line 24

Warning: include(/home/blog66rr/public_html/wp-content/plugins/hyper-cache/cache.php): failed to open stream: No such file or directory in /home/blog66rr/public_html/wp-content/advanced-cache.php on line 24

Warning: include(): Failed opening '/home/blog66rr/public_html/wp-content/plugins/hyper-cache/cache.php' for inclusion (include_path='.:/opt/cpanel/ea-php70/root/usr/share/pear') in /home/blog66rr/public_html/wp-content/advanced-cache.php on line 24
如何操作 linux grep 指令,搜索內文或是匯出。 – unethost無限空間虛擬主機 技術分享部落格

如何操作 linux grep 指令,搜索內文或是匯出。

linux_grep_wp

要在大量的文件中,找出相對的內容,並且匯出。這時如果是使用linux當server,
只要登入shell後,在透過 grep 的指令就可以快速找出文件或是匯出內容。

修改 theme為例

很多免費版模,如果想在版模的下方改掉原本的公司資訊,或是增加自己的資訊,
這時只要登入 shell ,並登入相對應的資料夾(比方說 /template)
輸入語法為: grep ‘Power’ *  或 grep -r ‘Power’ *
(增加 -r 參數,才會在針對子資料夾下去搜索內容)

如下方圖片所示,預設是print在screen上面,就會搜索出該內容出現在哪一隻程式裡,就可以在透過vim或是nano指令去修改該檔。

linux_grep01

如果是查找log檔,
想要匯出特定的資料呢?

有時需要過濾log檔,將特定登入帳號的記錄取出,如果是從密密麻麻的log檔,
用人工去看,是相當辛苦的事,但用grep指令,就會輕鬆不少。

在linux shell 下, 輸入:  grep ‘unethost’ access_log > log.txt
unethost可以改成特定字串的名稱,然後搜索到後,就會匯出到 log.txt 檔內。

 

今天先簡單的介紹兩種用法,有機會我們會介紹更多的linux指令及其應用。

 

(本篇文章由unethost.com客服人員-Michael完成)

註冊網域請點我。我們提供虛擬主機試用,七天滿意保證,
功能完整使用不受限制,歡迎點我申請。