Contents
see List작성일 2026. 04. 09.
시스템 관리 필수 터미널 명령어
GUI 도구로는 확인하기 어려운 시스템 상태 파악, 네트워크 진단, 프로세스 관리를 터미널 명령어로 해결하는 방법을 정리한다. macOS와 Linux 환경 모두에서 사용할 수 있는 명령어를 중심으로 다루고, OS별 차이가 있는 경우 구분하여 설명한다.
1. 프로세스 관리
ps - 프로세스 목록 조회
# 모든 프로세스 상세 출력
ps aux
# 메모리 사용량 기준 상위 10개
ps aux --sort=-%mem | head -11
# CPU 사용량 기준 상위 10개
ps aux --sort=-%cpu | head -11
# 특정 프로세스 찾기
ps aux | grep -i "node"
# macOS: 트리 형태로 표시
ps -axo pid,ppid,comm | head -30
# Linux: 프로세스 트리
pstree -p프로세스 제어
# PID로 프로세스 종료
kill 12345 # SIGTERM (정상 종료 요청)
kill -9 12345 # SIGKILL (강제 종료)
# 이름으로 종료
pkill -f "node server.js"
killall node
# 포트를 점유하는 프로세스 찾기 + 종료
lsof -i :3000
# COMMAND PID USER FD TYPE DEVICE NODE NAME
# node 1234 user 22u IPv6 0x... TCP *:3000
kill $(lsof -t -i :3000) # PID만 추출하여 종료
# macOS: 특정 포트 점유 확인
lsof -nP -iTCP:8080 -sTCP:LISTEN백그라운드 작업 관리
# 백그라운드 실행
npm run build &
# 현재 백그라운드 작업 확인
jobs -l
# 포그라운드로 전환
fg %1
# 실행 중인 작업을 백그라운드로
# Ctrl+Z (일시 중지) -> bg %1
# 터미널 종료 후에도 유지
nohup python train.py > output.log 2>&1 &
# 또는 disown으로 분리
long_running_task &
disown %12. 시스템 리소스 모니터링
실시간 모니터링
# top 대체: htop (대화형 프로세스 모니터)
brew install htop # macOS
sudo apt install htop # Linux
htop
# F4: 필터, F5: 트리 모드, F6: 정렬, F9: kill
# macOS 전용: 시스템 리소스 한눈에
vm_stat # 가상 메모리 통계
sysctl -n hw.memsize # 총 RAM (바이트)
system_profiler SPHardwareDataType # 하드웨어 정보
# Linux 전용
free -h # 메모리 사용량
cat /proc/cpuinfo # CPU 정보
lscpu # CPU 아키텍처 정보디스크 사용량
# 디스크 전체 사용량
df -h
# 현재 디렉토리의 폴더별 크기
du -sh */
# 상위 10개 큰 폴더
du -sh */ | sort -rh | head -10
# 특정 디렉토리 깊이 제한
du -h --max-depth=2 /var/log
# macOS: 휴지통 크기 확인
du -sh ~/.Trash
# 큰 파일 찾기 (100MB 이상)
find / -type f -size +100M 2>/dev/null
# ncdu: 대화형 디스크 사용량 분석
brew install ncdu # macOS
ncdu / # 루트부터 분석3. 네트워크 진단
연결 상태 확인
# 현재 네트워크 연결 목록
# macOS
netstat -an | grep LISTEN
# Linux
ss -tlnp
# 특정 포트 연결 확인
# macOS
lsof -nP -iTCP -sTCP:LISTEN
# Linux
ss -tlnp | grep :8080
# DNS 조회
dig example.com
nslookup example.com
# 경로 추적
traceroute example.com
# macOS에서 더 빠른 traceroute
traceroute -q 1 -w 2 example.com
# ping (5회만)
ping -c 5 example.com
# HTTP 응답 시간 측정
curl -o /dev/null -s -w \
"DNS: %{time_namelookup}s\nConnect: %{time_connect}s\nTTFB: %{time_starttransfer}s\nTotal: %{time_total}s\n" \
https://example.com네트워크 인터페이스 설정
# IP 주소 확인
# macOS
ifconfig en0 | grep inet
ipconfig getifaddr en0 # 간단히 IP만
# Linux
ip addr show eth0
hostname -I
# 외부 IP 확인
curl -s ifconfig.me
curl -s ipinfo.io/ip
# macOS Wi-Fi 정보
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I
# 대역폭 테스트
brew install speedtest-cli
speedtest-cli4. 파일 및 텍스트 처리
텍스트 처리 파이프라인
# 로그에서 에러 추출 + 빈도 분석
grep "ERROR" app.log | \
awk '{print $4}' | \
sort | uniq -c | sort -rn | head -10
# CSV 특정 컬럼 추출 (2번째 컬럼)
cut -d',' -f2 data.csv
# JSON을 CSV로 변환 (jq 활용)
jq -r '.users[] | [.name, .email, .age] | @csv' \
users.json > users.csv
# 파일 비교
diff -u old.conf new.conf
colordiff old.conf new.conf # 색상 diff
# 실시간 로그 모니터링
tail -f /var/log/syslog
# 여러 파일 동시 모니터링
tail -f app.log error.log
# 특정 패턴이 나타나면 알림
tail -f app.log | grep --line-buffered "CRITICAL"5. SSH와 원격 관리
# SSH 키 생성 (Ed25519 권장)
ssh-keygen -t ed25519 -C "[email protected]"
# SSH 설정 (~/.ssh/config)
Host dev-server
HostName 10.0.1.100
User deploy
Port 22
IdentityFile ~/.ssh/id_ed25519
ServerAliveInterval 60
ServerAliveCountMax 3
Host prod-*
User admin
ProxyJump bastion
Host bastion
HostName bastion.example.com
User jump
# 간편 접속
ssh dev-server
# 파일 전송
scp local-file.tar.gz dev-server:/tmp/
rsync -avz --progress ./dist/ dev-server:/var/www/
# 포트 포워딩
ssh -L 5432:db-server:5432 bastion # 로컬 포워딩
ssh -R 8080:localhost:3000 remote # 원격 포워딩
# SSH 터널을 통한 DB 접속
ssh -L 5432:rds-endpoint:5432 bastion &
psql -h localhost -p 5432 -U admin mydb6. 자동화 스크립트 패턴
#!/bin/bash
# 서버 헬스체크 스크립트
SERVERS=("web1:8080" "web2:8080" "api:3000" "db:5432")
LOG_FILE="/var/log/healthcheck.log"
for entry in "${SERVERS[@]}"; do
host="${entry%%:*}"
port="${entry##*:}"
if nc -z -w 3 "$host" "$port" 2>/dev/null; then
echo "$(date '+%Y-%m-%d %H:%M:%S') [OK] $host:$port" \
>> "$LOG_FILE"
else
echo "$(date '+%Y-%m-%d %H:%M:%S') [FAIL] $host:$port" \
>> "$LOG_FILE"
# 알림 발송
curl -s -X POST "https://hooks.slack.com/..." \
-d "{\"text\": \"$host:$port DOWN\"}"
fi
donecron 작업 관리
# crontab 편집
crontab -e
# 매일 새벽 3시 백업
0 3 * * * /home/user/scripts/backup.sh >> /var/log/backup.log 2>&1
# 매 5분마다 헬스체크
*/5 * * * * /home/user/scripts/healthcheck.sh
# 매주 월요일 오전 9시 리포트
0 9 * * 1 /home/user/scripts/weekly-report.sh
# 현재 cron 작업 확인
crontab -l
# macOS: launchctl로 관리 (권장)
# ~/Library/LaunchAgents/com.user.backup.plist7. macOS 전용 유용 명령어
# Finder에서 현재 디렉토리 열기
open .
# 기본 앱으로 파일 열기
open file.pdf
open -a "Visual Studio Code" project/
# 클립보드 연동
echo "copied" | pbcopy # 복사
pbpaste # 붙여넣기
pbpaste | wc -l # 클립보드 내용 줄 수
# 잠자기 방지
caffeinate -t 3600 # 1시간 동안 잠자기 방지
caffeinate -s # AC 전원 연결 시 잠자기 방지
# 스크린샷 저장 위치 변경
defaults write com.apple.screencapture location ~/Screenshots
killall SystemUIServer
# DNS 캐시 초기화
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
# Spotlight 재색인
sudo mdutil -E /이 가이드에서 다룬 명령어들을 숙달하면 서버 관리, 디버깅, 자동화 작업을 훨씬 효율적으로 처리할 수 있다. 처음에는 자주 쓰는 명령어 위주로 익히고, 필요할 때마다 man 페이지를 참고하며 범위를 넓혀가는 것을 권장한다.