Linux'de dosyalar içinde toplu "find and replace" işlemi yapmak için oldukça kullanışlı bir komut:
You can do a find and replace on files from the Linux shell using the
find
andsed
commands. The first example below shows doing a find and replace only in the current directory while the second example below shows doing a find and replace recursing into subdirectories…
- Replace “www.trendics.com” with “tools.trendics.com” in all html files in the current directory…
find .
-maxdepth 1
-name "*.html" -type f -exec sed -i 's/www.trendics.com/tools.trendics.com/' {} \;
- Replace “www.trendics.com” with “tools.trendics.com” in all text files and all subdirectories…
find . -name "*.txt" -type f -exec sed -i 's/www.trendics.com/tools.trendics.com/' {} \;
Here is how this works…
- The dot after the find command specifies to start in the current directory
- The
-maxdepth 1
specifies to only include the current directory- The
-name "*.txt"
switch specifies to only find txt files- The
-type f
specifies to only match files- The
-exec xyz {} \;
specifies to execute xyz for each file where xyz is a sed command specifying to substitute “tools.trendics.com” for “www.trendics.com”
Kaynak: Trendics Blog
Hiç yorum yok:
Yorum Gönder