반응형

안녕하세요 가야태자 @talkit 입니다. 

리눅스/Linux tail 문서의 끝(꼬리)를 보는 명령어. The command for text tail. https://talkit.tistory.com/681

어제 글에 이어서 반대의 개념을 알아 보겠습니다. 

우선 계속 알아보듯이 man을 실행해 보겠습니다. 

man head
HEAD(1)                                     User Commands                                    HEAD(1)

NAME
       head - output the first part of files

SYNOPSIS
       head [OPTION]... [FILE]...

DESCRIPTION
       Print  the  first 10 lines of each FILE to standard output.  With more than one FILE, precede
       each with a header giving the file name.

       With no FILE, or when FILE is -, read standard input.

       Mandatory arguments to long options are mandatory for short options too.

       -c, --bytes=[-]NUM
              print the first NUM bytes of each file; with the leading '-', print all but  the  last
              NUM bytes of each file

       -n, --lines=[-]NUM
              print the first NUM lines instead of the first 10; with the leading '-', print all but
              the last NUM lines of each file

       -q, --quiet, --silent
              never print headers giving file names

       -v, --verbose
              always print headers giving file names

       -z, --zero-terminated
              line delimiter is NUL, not newline

       --help display this help and exit

       --version
              output version information and exit

       NUM may have a multiplier suffix: b 512, kB 1000, K  1024,  MB  1000*1000,  M  1024*1024,  GB
       1000*1000*1000,  G 1024*1024*1024, and so on for T, P, E, Z, Y.  Binary prefixes can be used,
       too: KiB=K, MiB=M, and so on.

AUTHOR
       Written by David MacKenzie and Jim Meyering.

REPORTING BUGS
       GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
       Report any translation bugs to <https://translationproject.org/team/>

COPYRIGHT
       Copyright © 2020 Free Software Foundation, Inc.  License GPLv3+: GNU GPL version 3  or  later
       <https://gnu.org/licenses/gpl.html>.
       This  is free software: you are free to change and redistribute it.  There is NO WARRANTY, to
       the extent permitted by law.

SEE ALSO
       tail(1)

head는 리눅스에서 위에도 나와 있듯이 문서의 시작 부분을 보여주는 명령어 입니다. 

잼있는 것은 맨 마지막에 SEE ALSO에 어제 같이 이야기한 tail이라는 명령어가 있습니다. ^^

head [옵션들] 파일명

위와 같이 사용할 수 있습니다. 

실제로 옵션 없이 temp.txt 를 지난 번 글처럼 출력해 보겠습니다. 

head temp.txt
 
2022-12-01, 경기도, 1
2022-12-01, 강원도, 2
2022-12-01, 경상남도, 3
2022-12-01, 경상북도, 4
2022-12-01, 전라남도, 5
2022-12-01, 전라북도, 6
2022-12-01, 충청남도, 6
2022-12-01, 충청북도, 7
2022-12-02, 경기도, 2
2022-12-02, 강원도, 3

10줄이 잘 출력 되고 있습니다. 

다른 옵션들은 저는 거의 안쓰고 가끔 -n정도를 사용합니다. 

-n은 tail 명령어와 마찬가지로 줄수를 늘리거나 줄여 줍니다. 

-n으로 오늘은 5줄만 출력해보겠습니다. 

head -n 5 temp.txt

2022-12-01, 경기도, 1
2022-12-01, 강원도, 2
2022-12-01, 경상남도, 3
2022-12-01, 경상북도, 4
2022-12-01, 전라남도, 5

위와 같이 앞에서 다섯줄만 잘 출력 되고 있습니다. 

head는 정말로 가끔만 쓰는 명령어여서 ^^

여기서 줄이겠습니다.

감사합니다. 

반응형

+ Recent posts