본문 바로가기
IT/윈도우

윈도우파일검색

by psluckyguy 2026. 8. 17.
반응형

 

 

PowerShell – Select-String

리눅스 grep과 가장 유사한 느낌을 원하면 PowerShell 이 좋습니다.

powershell
 
cd C:\path\to\folder

# 모든 파일 재귀 검색
Get-ChildItem -Recurse -File | Select-String -Pattern "검색어" -SimpleMatch

# 파일 경로 + 줄 번호 + 내용까지 보기
Get-ChildItem -Recurse -File | Select-String -Pattern "검색어" | Select-Object Path, LineNumber, Line

# 특정 확장자만 (예: .txt, .log, .md)
Get-ChildItem -Recurse -File -Include *.txt,*.log,*.md |
  Select-String -Pattern "검색어" |
  Select-Object Path, LineNumber, Line
  • -SimpleMatch : 정규식 없이 단순 문자열 매칭 (대부분의 텍스트 검색에 충분)
  • -Pattern : 정규식 패턴도 가능 (고급 검색)

 

PowerShell: 특정 폴더 제외하며 내용 검색

예: node_modules, .git, temp 폴더를 제외하고 "검색어" 가 포함된 파일 찾기

powershell
 
cd C:\path\to\folder

$excludeFolders = @('node_modules', '.git', 'temp')

Get-ChildItem -Recurse -File |
  Where-Object {
    $path = $_.FullName
    $excludeFolders | ForEach-Object {
      if ($path -like "*\$_\*") { return $false }
    }
    return $true
  } |
  Select-String -Pattern "검색어" -SimpleMatch |
  Select-Object Path, LineNumber, Line

조금 더 간단하게 쓰려면 -Exclude + 경로 필터링을 조합해도 됩니다:

powershell
 
cd C:\path\to\folder

$exclude = @('node_modules', '.git', 'temp')

Get-ChildItem -Recurse -File |
  Where-Object {
    $exclude | ForEach-Object { $_.FullName -notlike "*\$_\*" } | Measure-Object | Select-Object -ExpandProperty Count
  } |
  Select-String -Pattern "검색어" -SimpleMatch

더 실용적인 패턴 (자주 쓰는 형태)

powershell
 
cd C:\path\to\folder

$exclude = @('node_modules', '.git', 'temp', 'bin', 'obj')

Get-ChildItem -Recurse -File |
  Where-Object {
    $full = $_.FullName
    $exclude | ForEach-Object {
      if ($full -like "*\$_\*") { return $false }
    }
    return $true
  } |
  Select-String -Pattern "검색어" -SimpleMatch |
  Select-Object Path, LineNumber, Line
  • $exclude 배열에 제외할 폴더 이름만 추가하면 됩니다.
  • Select-Object Path, LineNumber, Line 부분까지 넣으면 “어느 파일, 몇 번째 줄, 어떤 내용”이 한눈에 보입니다.
반응형