linux:cli:grep

grep

파일 내에 문자 패턴(정규표현식 지원)을 찾는다

grep [OPTIONS]... PATTERN [FILES]...
cat [FILES]... | grep [OPTIONS]... PATTERN
  • grep [<OPTIONS>…] PATTERN [FILES]
    • Pattern selection and interpretation:
      • -E, –extended-regexp: PATTERN is an extended regular expression. 확장된 정규표현식으로 검색
      • -F, –fixed-strings: PATTERN is a set of newline-separated strings.
      • -G, –basic-regexp: (default) PATTERN is a basic regular expression. 기본 정규표현식으로 검색
      • -e, –regexp=PATTERN: use PATTERN for matching
      • -i, –ignore-case: ignore case distinctions. 대소문자 무시
      • -w, –word-regexp: force PATTERN to match only whole words. 단어와 일치하는 행만 출력.
      • -x, –line-regexp: force PATTERN to match only whole lines. 전체 행과 일치하는 행만 출력.
    • Miscellaneous:
      • -v, –invert-match: select non-jmatching lines. 일치하지 않는 행만 표시
    • Output Control:
      • -m, –max-count=NUM: stop after NUM selected lines. 최대 검색 갯수 제한.
      • -n, –line-number: print line number with output lines. 줄번호 표시
      • –H, –with-filename: print file name with output lines. 파일명 표시
      • -r, –recursive: like –directories=recurse. 하위 디렉토리 재귀 호출
      • -l, –files-with-matches: print only names of FIELS with seleted lines. 일치하는 파일명만 표시.
      • -c, –count: print only a count of selected lines per FILE. 일치 하는 행의 수를 출력
      • –color[=WHEN], –colour[=WHEN]: use marker to highlight the matching strings; (WHEN: 'always', 'never', 'auto')
  • Pipeline
  • egrep: 정규표현식으로 찾음. grep -E 와 동일
  • fgrep: 문자열 패턴으로 찾음. grep -F 와 동일
  • linux/cli/grep.txt
  • 마지막으로 수정됨: 2025/10/27 00:48
  • 저자 writer