C.W.K.
Stream
Lesson 08 of 10 · published

wc, head, tail

~10 min · wc, head, tail, follow

Level 0창 구경꾼
0 XP0/95 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

사소해 보이지만 평생 쓰는 도구 셋

wc 세고, head 위 보고, tail 아래 봐. 각자 알아야 할 flag 한두 개뿐, 그리고 그걸 닳도록 쓰게 돼.

wc — word count

  • wc -l file — 줄 수. 90% 의 경우.
  • wc -w file — 단어 수.
  • wc -c file — 바이트 수.
  • wc -m file — 글자 수 (UTF-8 에서 바이트와 다름).

파이프에서: find . | wc -l 파일 수, git log --oneline | wc -l 커밋 수, cat file | wc -c 가 파일 사이즈.

head — 첫 N

  • head file — 첫 10 줄 (기본).
  • head -n 20 file — 첫 20 줄.
  • head -n -5 file — 끝 5 줄 빼고 다 (GNU 한정).
  • head -c 100 file — 첫 100 바이트.

tail — 마지막 N

  • tail file — 마지막 10 줄.
  • tail -n 50 file — 마지막 50 줄.
  • tail -n +10 file — 10 번째 줄부터 끝까지.
  • tail -f file — append 되는 새 줄을 라이브로 follow. 라이브 로그에 필수.
  • tail -F file — 파일 rotate 돼도 follow.

킬러 콤보

tail -f /var/log/system.log | grep -i error — 라이브 에러 스트림. find . -name '*.py' | head — 검색 결과 미리보기. history | tail -20 — 최근 command.

Code

라이브 로그 follow·bash
# macOS unified log alternative
log stream --predicate 'eventMessage CONTAINS "error"' --info
# Plain file
tail -F /var/log/system.log | grep -i pippa
흔한 세기 레시피·bash
find . -name '*.ts' -type f | wc -l       # TS file count
git log --oneline | wc -l                 # commits
wc -l < access.log                        # log line count (no filename)
find . -name '*.py' -exec wc -l {} + | tail -1   # total LOC

External links

Exercise

Mac 로그에서 tail -f /var/log/system.log 로 라이브 스트림 보기 → Ctrl+C. 프로젝트 파일 개수 find . -type f | wc -l. 이어서 head -3 ~/.zshrc, tail -10 ~/.zshrc.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.