질문&답변
클라우드/리눅스에 관한 질문과 답변을 주고 받는 곳입니다.
리눅스 분류

서버에서 특정확장자 파일 지우기 방법은?

작성자 정보

  • 초록매실 작성
  • 작성일

컨텐츠 정보

본문

/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  //지워졌는지 확인      

관련자료

댓글 0
등록된 댓글이 없습니다.

공지사항


뉴스광장


  • 현재 회원수 :  60,134 명
  • 현재 강좌수 :  36,188 개
  • 현재 접속자 :  431 명