서버에서 특정확장자 파일 지우기 방법은?
작성자 정보
- 초록매실 작성
- 작성일
컨텐츠 정보
- 961 조회
- 0 추천
- 목록
본문
/home/i2디렉토리밑에 html파일을 지워보도록 하겠습니다.
관련명령어는 'find' 와 'awk' 입니다.
[root@localhost home]# find /home/i2 -name *.html // 모든 html파일찾기
/home/i2/61.215.18.129_1.html
/home/i2/61.215.18.129_2.html
/home/i2/61.215.18.202_2.html
/home/i2/61.215.18.203_2.html
/home/i2/61.215.18.204_2.html
/home/i2/61.215.18.205_2.html
/home/i2/61.215.18.206_2.html
/home/i2/kontor.usrsys.html
/home/i2/localhost_2.html
[root@localhost home]# find /home/i2 -name *.html > imsi // 파일리스트를 imsi에저장
[root@localhost home]# cat imsi
/home/i2/61.215.18.129_1.html
/home/i2/61.215.18.129_2.html
/home/i2/61.215.18.202_2.html
/home/i2/61.215.18.203_2.html
/home/i2/61.215.18.204_2.html
/home/i2/61.215.18.205_2.html
/home/i2/61.215.18.206_2.html
/home/i2/kontor.usrsys.html
/home/i2/localhost_2.html
[root@localhost home]# awk '{print "rm -f " $1}' imsi > imsi2 // 텍스트 추출
[root@localhost home]# cat imsi2 //반복명령라인이 생긴것을 확인
rm -f /home/i2/61.215.18.129_1.html
rm -f /home/i2/61.215.18.129_2.html
rm -f /home/i2/61.215.18.202_2.html
rm -f /home/i2/61.215.18.203_2.html
rm -f /home/i2/61.215.18.204_2.html
rm -f /home/i2/61.215.18.205_2.html
rm -f /home/i2/61.215.18.206_2.html
rm -f /home/i2/kontor.usrsys.html
rm -f /home/i2/localhost_2.html
[root@localhost home]# chmod 755 imsi2 // 쉘명령을위해 권한변경
[[root@localhost home]# sh ./imsi2 //스크립트실행
[root@localhost home]# find /home/i2 -name *.html //지워졌는지 확인
관련자료
-
이전
-
다음