PowerShell에서 파일 읽기: Get-Content 설명
발행: (2026년 4월 25일 PM 05:07 GMT+9)
2 분 소요
원문: Dev.to
Source: Dev.to
Overview
Get-Content는 파일의 내용을 읽어 파이프라인에 씁니다.
특히 큰 파일이나 로그 파일을 다룰 때, 수정하기 전에 파일을 미리 확인하는 데 유용합니다.
Basic Usage
# Read the entire file
Get-Content notes.txt
Previewing Files
# Show the first 10 lines (safe for big files)
Get-Content notes.txt | Select-Object -First 10
# Show the last 5 lines (useful for log files)
Get-Content logfile.txt | Select-Object -Last 5
Reading Specific Lines
# Show lines 0 through 10 (inclusive)
Get-Content notes.txt | Select-Object -Index 0..10
# Preview the first 5 lines of a file you are about to process
Get-Content myfile.txt | Select-Object -First 5
Reading Logs for Diagnostics
# Show the most recent 20 lines of an error log
Get-Content error.log | Select-Object -Last 20
Common Parameters
| Parameter | Description |
|---|---|
-Path | 읽을 파일의 경로 |
Select-Object -First n | 처음 n줄을 반환 |
Select-Object -Last n | 마지막 n줄을 반환 |
Select-Object -Index | 특정 라인 번호를 반환 (예: 0..10) |
Practice
인터랙티브 PowerShell 환경에서 위 명령들을 직접 실행해 보세요. 반복 연습을 통해 이러한 패턴을 몸에 익힐 수 있습니다.
Related Topics (PowerShell for Beginners series)
- Getting Started – 첫 번째 명령어
- Command Discovery – 존재하는 명령어 찾기
- Getting Help – 명령어 이해하기
- Working with Files – 복사, 이동, 삭제
- Filtering Data –
Where-Object와Select-Object - Pipelines – 명령어 연결하기