여러 파일 grep 하기 + 파일명 보기

(여러 파일 grep 하기, grep 파일명 보기에서 넘어옴)

1 개요[ | ]

여러 파일 grep 하기
grep 파일 여러 개 보기
grep 파일명 보기
  • H: 파일명 출력(with filename)
  • n: 줄번호 출력(line number)
  • i: 대소문자 구분 안함(ignore case)

2 방법 1: grep[ | ]

[root@zetawiki ~]# grep -Hni Error /var/log/messages*
/var/log/messages:1104:Sep 15 16:20:48 localhost NetworkManager[1817]: <warn> bluez error getting default adapter: The name org.bluez was not provided by any .service files
/var/log/messages:2248:Sep 27 08:19:16 localhost NetworkManager[1862]: <warn> bluez error getting default adapter: The name org.bluez was not provided by any .service files
/var/log/messages:3420:Sep 28 11:26:54 localhost NetworkManager[1747]: <warn> bluez error getting default adapter: The name org.bluez was not provided by any .service files
/var/log/messages-20130706:1079:Jul  6 19:53:07 localhost NetworkManager[1813]: <warn> bluez error getting default adapter: The name org.bluez was not provided by any .service files
... (생략)

3 방법 2: xargs + grep[ | ]

[root@zetawiki ~]# ls -al /var/log/messages* | awk '{print $NF}' | xargs grep -Hni Error 
/var/log/messages:1104:Sep 15 16:20:48 localhost NetworkManager[1817]: <warn> bluez error getting default adapter: The name org.bluez was not provided by any .service files
/var/log/messages:2248:Sep 27 08:19:16 localhost NetworkManager[1862]: <warn> bluez error getting default adapter: The name org.bluez was not provided by any .service files
/var/log/messages:3420:Sep 28 11:26:54 localhost NetworkManager[1747]: <warn> bluez error getting default adapter: The name org.bluez was not provided by any .service files
/var/log/messages-20130706:1079:Jul  6 19:53:07 localhost NetworkManager[1813]: <warn> bluez error getting default adapter: The name org.bluez was not provided by any .service files
... (생략)

4 방법 3: find + grep[ | ]

/var/log의 messages* 파일들에 대해 Error라는 문자열로 grep한 결과

[root@zetawiki ~]# find /var/log -maxdepth 1 -type f -name 'messages*' -exec grep -Hni Error {} \;
/var/log/messages-20130706:1079:Jul  6 19:53:07 localhost NetworkManager[1813]: <warn> bluez error getting default adapter: The name org.bluez was not provided by any .service files
/var/log/messages:1104:Sep 15 16:20:48 localhost NetworkManager[1817]: <warn> bluez error getting default adapter: The name org.bluez was not provided by any .service files
/var/log/messages:2248:Sep 27 08:19:16 localhost NetworkManager[1862]: <warn> bluez error getting default adapter: The name org.bluez was not provided by any .service files
/var/log/messages:3420:Sep 28 11:26:54 localhost NetworkManager[1747]: <warn> bluez error getting default adapter: The name org.bluez was not provided by any .service files
... (생략)
→ 어느 파일의 몇번째 행에서 발견되었는지가 출력된다.

5 같이 보기[ | ]

6 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}