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

ParameterDescription
-Path읽을 파일의 경로
Select-Object -First n처음 n줄을 반환
Select-Object -Last n마지막 n줄을 반환
Select-Object -Index특정 라인 번호를 반환 (예: 0..10)

Practice

인터랙티브 PowerShell 환경에서 위 명령들을 직접 실행해 보세요. 반복 연습을 통해 이러한 패턴을 몸에 익힐 수 있습니다.

  • Getting Started – 첫 번째 명령어
  • Command Discovery – 존재하는 명령어 찾기
  • Getting Help – 명령어 이해하기
  • Working with Files – 복사, 이동, 삭제
  • Filtering Data – Where-ObjectSelect-Object
  • Pipelines – 명령어 연결하기

Further Resources

0 조회
Back to Blog

관련 글

더 보기 »

내가 마침내 봇에게 '지루한' 일을 맡긴 방법

Google Cloud NEXT ’26에 대한 나의 견해: 우리 모두를 위한 “Agentic” 시대 NEXT ’26에 참석한 모든 사람들은 “Agents”에 대해 이야기하고 있습니다. 이것이 공상과학 용어처럼 들린다면, …