반응형
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 부분까지 넣으면 “어느 파일, 몇 번째 줄, 어떤 내용”이 한눈에 보입니다.
반응형
'IT > 윈도우' 카테고리의 다른 글
| 윈도우 공유 폴더(SMB/CIFS)를 리눅스 서버에서 마운트하기 (0) | 2026.08.01 |
|---|---|
| 윈도우 레지스트리 설명 해당 항목 찾기 (0) | 2023.11.02 |
| 윈도우 명령어 모음 (0) | 2022.05.29 |