[팁] 파일 내용 일괄수정
BSD / Linux 2007/12/16 02:48
MySQL 설치시 함께 설치되는 replace 라는 명령을 이용한 파일 내용 치환.
1. 현재 디렉토리내 모든 파일에서 dotname를 dothost로 변경
1. 현재 디렉토리내 모든 파일에서 dotname를 dothost로 변경
replace dotname dothost -- *
2. 현재 디렉토리내 모든 파일에서 dotname는 dothost로, dothost는 dotname로 변경
replace dotname dothost dothost dotname -- *
3. 하위 디렉토리를 포함하여 위의 작업을 할때
4. replace가 아닌 perl을 이용한 명령.
여러 파일들 내부에 포함하고 있는 특정 문자열을 일괄 변경하여주는 정규식.
웹호스팅 계정 이전의 경우 유용할것 같다.
replace dotname dothost -- `find . -type f -name '*' -print`
또는
find . -type f -name '*' -exec replace dotname dothost -- {} \;
4. replace가 아닌 perl을 이용한 명령.
find ./ -type f \( -iregex ".*\.php3?" -o -iregex ".*\.html?" -o -iregex ".*\.css" -o -iregex ".*\.cgi" \) -exec perl -p -i -e 's|dotname|dothost|g' {} \;
여러 파일들 내부에 포함하고 있는 특정 문자열을 일괄 변경하여주는 정규식.
웹호스팅 계정 이전의 경우 유용할것 같다.

이올린에 북마크하기
이올린에 추천하기


