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

cat (파일의 내용확인및 간단한 파일생성)

작성자 정보

  • 웹관리자 작성
  • 작성일

컨텐츠 정보

본문

cat

cat은 파일의 내용을 확인하거나 간단한 파일을 생성하고자 할 경우에 사용한다.
파일의 내용을 보는 명령어로는 cat외에도 pg, head, tail, more, strings등의 명령어가 있으며 DOS명령어로는 type가 같은 명령어이다.

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

그리고 cat명령어는 2개 이상의 파일이름이 지정되면 모든 파일이 연결되어 보여진다.


명령어 사용형식
                 cat [OPTION] [FILE]...

사용예 #1

아래와 같이 간단히 "cat 파일명"이라고 하면 그 파일의 내용을 간단히 보여준다.

[root@host1 commmand]# cat test.txt
Based upon
the NCSA server
configuration files
originally
by Rob McCool.

This is the
main Apache server
configuration file.

It contains
the configuration
directives that give
the server
its instructions.
[root@host1 commmand]#


사용예 #2

그리고 다음과 같이 -b옵션을 사용하면 행번호에 번호를 붙여서 파일의 내용을 출력한다.
이때 빈행에는 행번호를 붙이지 않는다.
다음의 예를 보자.

[root@host1 commmand]# cat -b test.txt
     1  Based upon
     2  the NCSA server
     3  configuration files
     4  originally
     5  by Rob McCool.

     6  This is the
     7  main Apache server
     8  configuration file.

     9  It contains
    10  the configuration
    11  directives that give
    12  the server
    13  its instructions.
[root@host1 commmand]#


사용예 #3

하지만 빈행에도 번호를 붙이고자 한다면 -n옵션을 사용하면 된다.
-n옵션은 빈행에도 행 번호를 붙여서 파일내용을 출력한다.
아래의 예를 보자.

[root@host1 commmand]# cat -n test.txt
     1  Based upon
     2  the NCSA server
     3  configuration files
     4  originally
     5  by Rob McCool.
     6
     7  This is the
     8  main Apache server
     9  configuration file.
    10
    11  It contains
    12  the configuration
    13  directives that give
    14  the server
    15  its instructions.
[root@host1 commmand]#


사용예 #4

-s옵션을 사용하면 파일의 내용중 빈행이 2행이상 연속될 경우에는 한행만을 출력하게 된다.
-s옵션과 -n옵션을 함께 적용하면 2행이상의 빈행이 있을 경우에는 행번호를 1개만 붙이게 된다.
다음의 예를 보자.

[root@host1 commmand]# cat bible.txt
Based upon
the NCSA server
configuration files
originally
by Rob McCool.


This is the
main Apache server
configuration file.
[root@host1 commmand]#
[root@host1 commmand]# cat -s bible.txt
Based upon
the NCSA server
configuration files
originally
by Rob McCool.

This is the
main Apache server
configuration file.
[root@host1 commmand]#
[root@host1 commmand]# cat -sn bible.txt
     1  Based upon
     2  the NCSA server
     3  configuration files
     4  originally
     5  by Rob McCool.
     6
     7  This is the
     8  main Apache server
     9  configuration file.
[root@host1 commmand]#

 

사용예 #5

위의 예에서 보았던 파일의 내용은 많지않으므로 간단히 한 화면에 모두 볼 수가 있었다.
하지만, 파일의 내용이 많아서 한 화면에 모두 볼 수가 없을 경우에는 파일의 내용을 출력할 때 정지하지않고 계속적 출력이된다.
이때 출력되는 화면을 "CTRL+S"키로 일시정지시켰다가 "CTRL+Q"로 재개시킬 수 있다.

하지만, 다음과 같이 하면 한 화면씩 볼 수 있으므로 파일의 내용이 많을 경우에는 다음과 같이 사용하면 된다.

[root@host1 commmand]# cat httpd.conf | more
#
# Based upon the NCSA server configuration files originally by Rob McCoo
l.
#
# This is the main Apache server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs-2.0/> for detailed information a
bout
# the directives.
#
# Do NOT simply read the instructions in here without understanding
# what they do.  They're here only as hints or reminders.  If you are un
sure
# consult the online docs. You have been warned. 
#
--More--


이렇게 하면 한 화면씩 볼 수 있으며 다음 페이지를 보려면 "SpaceBar"를 누르면 된다.

이 명령어는 "more httpd.conf"와 동일한 명령어이다. more명령어편에서 자세히 확인하기 바란다.


저작권 :  수퍼유저코리아 (
www.superuser.co.kr),   무단 재배포및 복사를 금합니다.

 

관련자료

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

공지사항


뉴스광장


  • 현재 회원수 :  60,043 명
  • 현재 강좌수 :  35,853 개
  • 현재 접속자 :  74 명