강좌
클라우드/리눅스에 관한 강좌입니다.
리눅스 분류

파일내용확인실무 1편:대표적인 파일내용 확인 명령어 cat 활용법

작성자 정보

  • 관리자 작성
  • 작성일

컨텐츠 정보

본문

파일내용확인실무 1:대표적인 파일내용 확인 명령어 cat 활용법

 

 

 

 

 

리눅스에서 텍스트 파일의 내용을 확인하는 가장 대표적인 방법은 cat을 이용하는 것이다.

 

 

 

텍스트로 된 파일일 경우에는 그 내용을 읽거나 알아볼 수 있지만, 바이너리(Binary)파일일 경우에는 내용을 출력은 하지만 알아볼 수는 없다.

 

 

 

 그리고 cat명령어는 2개 이상의 파일이름이 지정되면 모든 파일이 연결되어 보여진다는 것도 알아두면 유용하다.

 

 

 

 

 

먼저 cat의 간단한 예부터 보도록 하자. 아래와 같이 간단히 "cat 파일명"이라고 하면 그 파일의 내용을 간단히 보여준다.

 

 

 

 

 

[root@sulinux ~]#ls -l README

-rwx------ 1 root root 13755  3 19 07:00 README

[root@sulinux ~]#

[root@sulinux ~]#cat README

                         chkrootkit V. 0.47

 

          Nelson Murilo <nelson@pangeia.com.br> (main author)

            Klaus Steding-Jessen <jessen@cert.br> (co-author)

 

          This program locally checks for signs of a rootkit.

         chkrootkit is available at: http://www.chkrootkit.org/

 

 

                 No illegal activities are encouraged!

         I'm not responsible for anything you may do with it.

 

           This tool includes software developed by the

           DFN-CERT, Univ. of Hamburg (chklastlog and chkwtmp),

           and small portions of ifconfig developed by

           Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>.

이하생략

 

 

 

 

 

 

 

, 위의 예는 README파일의 내용을 cat명령어로 확인한 것이다.

 

 

 

 cat명령어를 사용하는 가장 흔하고 쉬운 방법이다.

 

 

 

 

 

이번에는 -b옵션을 사용하면 각행에 번호를 붙여서 파일의 내용을 출력한 예이다.

 

 

 

 이때 빈 행에는 행 번호를 붙이지 않는다.

 

 

 

  

 

[root@sulinux ~]#cat -b README

     1                           chkrootkit V. 0.47

 

     2            Nelson Murilo <nelson@pangeia.com.br> (main author)

     3              Klaus Steding-Jessen <jessen@cert.br> (co-author)

 

     4            This program locally checks for signs of a rootkit.

     5           chkrootkit is available at: http://www.chkrootkit.org/

 

 

     6                   No illegal activities are encouraged!

     7           I'm not responsible for anything you may do with it.

 

     8             This tool includes software developed by the

     9             DFN-CERT, Univ. of Hamburg (chklastlog and chkwtmp),

    10             and small portions of ifconfig developed by

    11             Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>.

[root@sulinux ~]#

 

 

 

 

, 위의 예는 README파일의 내용을 행번호를 붙여서 출력한 것이다.

 

 

 

 보다시피 빈행의 행번호는 붙어있지 않는다.

 

 

 

 

 

행번호를 붙여서 파일의 내용을 확인할 때에  빈행에도 번호를 붙이고자 한다면 다음 예와 같이 -n옵션을 사용하면 된다.

 

 

 

 

 

[root@sulinux ~]#cat -n README

     1                           chkrootkit V. 0.47

     2

     3            Nelson Murilo <nelson@pangeia.com.br> (main author)

     4              Klaus Steding-Jessen <jessen@cert.br> (co-author)

     5

     6            This program locally checks for signs of a rootkit.

     7           chkrootkit is available at: http://www.chkrootkit.org/

     8

     9

    10                   No illegal activities are encouraged!

    11           I'm not responsible for anything you may do with it.

    12

    13             This tool includes software developed by the

    14             DFN-CERT, Univ. of Hamburg (chklastlog and chkwtmp),

    15             and small portions of ifconfig developed by

    16             Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>.

[root@sulinux ~]#

 

 

 

 

 

위의 예를보면 비어있는 행에도 행번호가 붙여져 있다는 것을 알 수 있다.

 

 

 

 그런데 위의 예에서는 연속되는 2개이상의 빈행에도 모두 행번호가 붙어있다.

 

 

 

 만약 2개이상의 빈 행이 연속될 경우에 한행으로만 출력하려고 한다면 -s 또는 -sn옵션을 사용하면 된다.

 

 

 

 가끔씩 매우 유용할 때가 있으므로 꼭 알아두기 바란다.

 

 

 

 

 

그리고 다음은 파일의 내용을 화면단위로 확인하는 방법에 대한 예이다.

 

 

 

 

 

[root@sulinux ~]#cat README | more

 

 

 

 

그리고 다음은 cat으로 출력되는 내용을 특정파일에 저장하는 방법이다.

 

 

 

 

 

[root@sulinux ~]#cat README > /root/README.TXT

 

 

 

 

위의 예는 README라는 파일의 내용을 cat으로 출력하여 그 결과를 /root/README.TXT파일에 저장하는 것이다.

 

 

 

 가끔씩 유용할 때가 있으므로 참고로 알아두자.

 

관련자료

댓글 0
등록된 댓글이 없습니다.

공지사항


뉴스광장


  • 현재 회원수 :  60,042 명
  • 현재 강좌수 :  35,846 개
  • 현재 접속자 :  99 명