2010-01-02 117 views
0

我有幾個PHP文件,並有那些對.html文件的引用。搜索多個php文件,並替換文本?

我需要更換名 「.html」 改爲 「.PHP」

我怎樣才能在bash做到這一點?

+2

你可能想仔細檢查這個結果。例如,您不希望將另一個* .html文件的外部鏈接重新命名爲PHP。 – 2010-01-02 02:43:36

回答

2
for file in $(find . -name "*.php"); do 
    sed "s/\.html/.php/g" $file > $$ && mv $$ $file 
done 
+0

'sed --in-place' – 2010-01-02 03:51:39

0

嘗試SED:

find -name "filenamepattern.php" -print0 | xargs -0 sed 's/\.html/\.php/g' 
+0

論壇正在吃斜線。只需在每個時期添加一個。 – Codism 2010-01-02 02:42:36

1
find -name '*.php' -exec sed -ie 's:.html:.php:g' {} \; 
0

GNU找到

find /path -type f -iname '*.php' -exec sed -i.bak 's/\.html/\.php/g' {} +;