텍스트 파일 내용을 표준 출력으로 보여준다.
[CODE]사용법 : cat [옵션] [파일]... -A, --show-all : -vET 와 같다. -b, --number-nonblank : 공백을 제외한 파일 내용의 줄의 맨 앞에 1부터 시작하는 줄 수를 보여준다. -e : -vE 와 같다. -E, --show-ends : 각 줄의 끝에 $로 끝줄을 나타낸다. -n, --number : 모든 줄의 앞에 1부터 시작하는 줄 수를 보여준다. -s, --squeeze-blank : 공백의 줄 수를 하나이상 보여주지 않는다. -t : -vT 과 같다. -T, --show-tabs : 탭 문자를 ^|로 보여준다. -v, --show-nonprinting : 개행 문자와 탭 문자를 제외한 ^|와 M 표시를 보여준다. --help : 도움말을 보여준다. --version : 버전 정보를 보여준다. [/CODE]
cat은 파일의 내용을 출력하여 보여주는 대표적인 명령어이다. cat은 파일 내용을 한번 보여주기만 할 뿐 많은 줄의 내용은 제대로 살펴 볼 수 없다. 이 때는 보통 more 명령이나 less, tail 명령을 사용하거나, 출력 내용을 파이프를 통해 다른 프로그램과 조합하여 사용해야 할 것이다.
다음의 query 파일을 보자. 한 줄이 길어 한 줄인지 구별이 가지 않는다.
[CODE]# cat query select date_format(uregdate,'%Y%m') date,count(uid) from cst_users u, cst_productregs p, cst_productregdetail d where u.uno=p.preguno and p.pregno=d.preggno group by date [/CODE]
-n 옵션은 줄 앞에 줄 번호를 붙여 주는 역할을 한다. 이 파일은 총 4줄임을 알 수 있다.
[CODE]1 select date_format(uregdate,'%Y%m') date,count(uid) from cst_users u, cst_productregs p, cst_productregdetail d 2 where u.uno=p.preguno 3 and p.pregno=d.preggno 4 group by date [/CODE]
줄 수가 많은 경우 파이프로 more 명령을 실행하여 한 페이지씩 살펴 볼 수 있다. 다음 페이지를 보려면 스페이스 키를 입력하고, 한 줄씩 내려가려면 엔터 키를 입력한다.
물론 more만 실행하더라도 같은 결과를 볼 수는 있다.
[CODE]# cat /etc/httpd/conf/httpd.conf | more # # 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. # See <URL:http://www.apache.org/docs/> for detailed information about # 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 unsure # consult the online docs. You have been warned. # # After this file is processed, the server will look for and process # /etc/httpd/conf/srm.conf and then /etc/httpd/conf/access.conf # unless you have overridden these with ResourceConfig and/or # AccessConfig directives here. # # The configuration directives are grouped into three basic sections: # 1. Directives that control the operation of the Apache server process as a # whole (the 'global environment'). # 2. Directives that define the parameters of the 'main' or 'default' server, # which responds to requests that aren't handled by a virtual host. --More-- [/CODE]
마지막으로 cat은, 간단한 라인 편집기의 역할을 할 수 있다. 라인 편집기란 현재 입력 하고 있는 행은 수정할 수 있지만 이미 지나 온 행은 수정할 수 없는 것으로, 지금은 거의 쓰이지 않는 것이지만, 나우누리나 하이텔 등의 PC 통신을 사용하는 사람이라면 한번쯤 사용해 보았을 것이다. 사용 방법은 다음과 같다.
[CODE]# cat > [파일 이름] [/CODE]
그러면 실제로 파일을 만들어 저장해 보자. 파일을 다 쓰고 나서는 Ctrl+D를 눌러 cat 명령을 종료한다.
[CODE]# cat > boa.txt You Still my No.1, 날 차지 말아 줘, 나의 슬픔 가려 줘, 저 구름 뒤에 너를 숨겨 빛을 닫아 줘. Ctrl+D [/CODE]
노래 가사를 입력해 보았다. 그러면 제대로 저장이 되었는지, 새로 만들어진 boa.txt 파일을 읽어보자
[CODE]# cat boa.txt You Still my No.1, 날 차지 말아 줘, 나의 슬픔 가려 줘, 저 구름 뒤에 너를 숨겨 빛을 닫아 줘. [/CODE]
잘 저장된 것을 알 수 있다. 그러나 이 경우에 한 가지 주의할 점이 있다. 다음 내용을 살펴 보자. 다음과 같이 사용하면 100m.txt 파일의 내용을 화면에 출력하는 대신 boa.txt 파일에 입력하여 저장한다.
[CODE]# cat 100m.txt > bat.txt # cat boa.txt 저기 보이는 노란 찻집 오늘은 그녀를 세번째 만나는 날 [/CODE]
앞서 작성한 boa.txt의 내용이 사라지고 100m.txt의 내용이 저장되어 있다. 그렇다면 먼저 저장된 내용의 뒤에 새 내용을 저장하려면 어떻게 해야 할까? 이 때에는 > 를 두개 사용하여 문제를 해결할 수 있다.
[CODE]# cat sarah.txt >> boa.txt [/CODE]
[관련 명령어]
more 한 페이지씩 파일을 볼 수 있다.
tail 파일의 끝 부분부터 지정한 라인 수만큼 보여준다.
less more와 같은 기능을 하지만, 좀 더 추가적인 기능들이 있다.
[CODE]사용법 : cat [옵션] [파일]... -A, --show-all : -vET 와 같다. -b, --number-nonblank : 공백을 제외한 파일 내용의 줄의 맨 앞에 1부터 시작하는 줄 수를 보여준다. -e : -vE 와 같다. -E, --show-ends : 각 줄의 끝에 $로 끝줄을 나타낸다. -n, --number : 모든 줄의 앞에 1부터 시작하는 줄 수를 보여준다. -s, --squeeze-blank : 공백의 줄 수를 하나이상 보여주지 않는다. -t : -vT 과 같다. -T, --show-tabs : 탭 문자를 ^|로 보여준다. -v, --show-nonprinting : 개행 문자와 탭 문자를 제외한 ^|와 M 표시를 보여준다. --help : 도움말을 보여준다. --version : 버전 정보를 보여준다. [/CODE]
cat은 파일의 내용을 출력하여 보여주는 대표적인 명령어이다. cat은 파일 내용을 한번 보여주기만 할 뿐 많은 줄의 내용은 제대로 살펴 볼 수 없다. 이 때는 보통 more 명령이나 less, tail 명령을 사용하거나, 출력 내용을 파이프를 통해 다른 프로그램과 조합하여 사용해야 할 것이다.
다음의 query 파일을 보자. 한 줄이 길어 한 줄인지 구별이 가지 않는다.
[CODE]# cat query select date_format(uregdate,'%Y%m') date,count(uid) from cst_users u, cst_productregs p, cst_productregdetail d where u.uno=p.preguno and p.pregno=d.preggno group by date [/CODE]
-n 옵션은 줄 앞에 줄 번호를 붙여 주는 역할을 한다. 이 파일은 총 4줄임을 알 수 있다.
[CODE]1 select date_format(uregdate,'%Y%m') date,count(uid) from cst_users u, cst_productregs p, cst_productregdetail d 2 where u.uno=p.preguno 3 and p.pregno=d.preggno 4 group by date [/CODE]
줄 수가 많은 경우 파이프로 more 명령을 실행하여 한 페이지씩 살펴 볼 수 있다. 다음 페이지를 보려면 스페이스 키를 입력하고, 한 줄씩 내려가려면 엔터 키를 입력한다.
물론 more만 실행하더라도 같은 결과를 볼 수는 있다.
[CODE]# cat /etc/httpd/conf/httpd.conf | more # # 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. # See <URL:http://www.apache.org/docs/> for detailed information about # 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 unsure # consult the online docs. You have been warned. # # After this file is processed, the server will look for and process # /etc/httpd/conf/srm.conf and then /etc/httpd/conf/access.conf # unless you have overridden these with ResourceConfig and/or # AccessConfig directives here. # # The configuration directives are grouped into three basic sections: # 1. Directives that control the operation of the Apache server process as a # whole (the 'global environment'). # 2. Directives that define the parameters of the 'main' or 'default' server, # which responds to requests that aren't handled by a virtual host. --More-- [/CODE]
마지막으로 cat은, 간단한 라인 편집기의 역할을 할 수 있다. 라인 편집기란 현재 입력 하고 있는 행은 수정할 수 있지만 이미 지나 온 행은 수정할 수 없는 것으로, 지금은 거의 쓰이지 않는 것이지만, 나우누리나 하이텔 등의 PC 통신을 사용하는 사람이라면 한번쯤 사용해 보았을 것이다. 사용 방법은 다음과 같다.
[CODE]# cat > [파일 이름] [/CODE]
그러면 실제로 파일을 만들어 저장해 보자. 파일을 다 쓰고 나서는 Ctrl+D를 눌러 cat 명령을 종료한다.
[CODE]# cat > boa.txt You Still my No.1, 날 차지 말아 줘, 나의 슬픔 가려 줘, 저 구름 뒤에 너를 숨겨 빛을 닫아 줘. Ctrl+D [/CODE]
노래 가사를 입력해 보았다. 그러면 제대로 저장이 되었는지, 새로 만들어진 boa.txt 파일을 읽어보자
[CODE]# cat boa.txt You Still my No.1, 날 차지 말아 줘, 나의 슬픔 가려 줘, 저 구름 뒤에 너를 숨겨 빛을 닫아 줘. [/CODE]
잘 저장된 것을 알 수 있다. 그러나 이 경우에 한 가지 주의할 점이 있다. 다음 내용을 살펴 보자. 다음과 같이 사용하면 100m.txt 파일의 내용을 화면에 출력하는 대신 boa.txt 파일에 입력하여 저장한다.
[CODE]# cat 100m.txt > bat.txt # cat boa.txt 저기 보이는 노란 찻집 오늘은 그녀를 세번째 만나는 날 [/CODE]
앞서 작성한 boa.txt의 내용이 사라지고 100m.txt의 내용이 저장되어 있다. 그렇다면 먼저 저장된 내용의 뒤에 새 내용을 저장하려면 어떻게 해야 할까? 이 때에는 > 를 두개 사용하여 문제를 해결할 수 있다.
[CODE]# cat sarah.txt >> boa.txt [/CODE]
[관련 명령어]
more 한 페이지씩 파일을 볼 수 있다.
tail 파일의 끝 부분부터 지정한 라인 수만큼 보여준다.
less more와 같은 기능을 하지만, 좀 더 추가적인 기능들이 있다.