5월, 2020의 게시물 표시

find by permmision 예제

permission 으로 파일 찾기 1) 디렉토리 permission 755 만 찾기 $> find . -type d -perm 755 2) 디렉토리 permission 755 아닌 것만 찾아서 755로 바꾸기 $> find . -type d -not -perm 755 -exec chmod 755 {} \; 3) 파일 permission 644 아닌 것만 찾아서 644로 바꾸기 $> find . -type f -not -perm 644 -exec chmod 644 {} \; 4) 현재 디렉토리만 원할때는 = -maxdepth $> find . -maxdepth 1 -type d -not -perm 755 Symbolic Notation u = user g = group o = other a = all r = read w = write x = execute 1) 파일에 그룹 permission 읽기 추가 하기(=와 +는 같음) $> chmod g=r {파일명} $> chmod g+r {파일명} 2) 파일에 여러 permission 붙이기 $> chmod o=rw,g=rx,o=r {파일명} $> chmod o+rw,g+rx,o+r {파일명} 참고) 1.  https://askubuntu.com/a/518260/847914 2.  https://www.ostechnix.com/find-files-based-permissions/

sed 치환

LINUX $> sed -i 's/{target}/{substitution}/g' {file_name} -i : inplace update. 즉 해당 파일내 치환 s/ : substitute /g: global. {target}과 매칭되는 모든 문자를 {substitution}으로 치환 ex) sed -i 's/abcde/ABCDE/g' test.txt MAC mac은 -i 뒤에 백업 파일 extention을 넣어줘야 한다. 그래서 아래처럼 하면 backup 파일 생성하지 않고 바로 inplace update. $> sed -i '' 's/{target}/{substitution}/g' {file_name} 응용 현재 디렉토리에서 file extension이 sh인 모든 파일 내용 변경 $> find ./ -type f -name "*.sh" -exec sed -i 's/abcde/ABCDE/g' {} \; mac은 -i 뒤에 '' 추가 $> find ./ -type f -name "*.sh" -exec sed -i '' 's/abcde/ABCDE/g' {} \;