서버/Linux I 2015. 12. 23. 15:21
Linux I - 05. 리눅스 기본 명령어 (파일 내용 확인 명령어)
[root@CentOS ~]# echo $PS1
[\u@\h \W]\$
[root@CentOS ~]# PS1="[\u@\h \$PWD]# "
[root@CentOS /root]# cd ..
[root@CentOS /]#
1. 'cat' 명령어
Ex1) 파일 내용 출력
[root@CentOS /]# mkdir test
[root@CentOS /]# cd test
[root@CentOS /test]# cat /etc/passwd
[root@CentOS /test]# cat -n /etc/passwd
[root@CentOS /test]# cat -n /etc/passwd | grep root
Ex2) 두개의 파일을 하나의 파일로 합치기
[root@CentOS /test]# echo ABC > file1
[root@CentOS /test]# echo DEF > file2
[root@CentOS /test]# cat file1 file2
ABC
DEF
[root@CentOS /test]# cat file1 file2 > file3
[root@CentOS /test]# cat file3
ABC
DEF
[root@CentOS /test]# ls
file1 file2 file3
[root@CentOS /test]# cat file3
ABC
DEF
2. 'more' 명령어
Ex1) 'cat' 명령어와 차이점 확인
[root@CentOS /test]# cat /etc/services
[root@CentOS /test]# more /etc/services
Ex2) '명령어 | more'
[root@CentOS /test]# cat /etc/services | more
3. 'less' 명령어 확인
Ex1) 'more' 명령어와 차이점 확인
[root@CentOS /test]# more /etc/passwd
[root@CentOS /test]# less /etc/passwd
[root@CentOS /test]# less -2 /etc/passwd (첫 화면은 다 출력되고, 이후 2줄씩 출력됨)
Ex2) 두개 파일 동시에 열기
[root@CentOS /test]# less /etc/passwd /etc/shadow
/etc/passwd (file 1 of 2) <--------- :n 실시 (다음 페이지 이동)
/etc/shadow (file 2 of 2) <--------- :e 실시 (확인할 새로운 파일 추가)
Examine: /etc/hosts <------------- : 입력 (확인할 파일 입력)
/etc/hosts (file 3 of 3) (END) <----- :p 실시 (이전 페이지 이동)
/etc/shadow (file 2 of 3) <--------- : q 실시 (나가기)
4. 'nl' 명령어
Ex1) 'nl' 명령어 확인 (= cat -n)
[root@CentOS /test]# nl /etc/passwd
[root@CentOS /test]# nl /etc/passwd /etc/shadow
Ex2) 두개의 파일을 한개 파일로 생성하여 확인
[root@CentOS /test]# nl /etc/passwd /etc/shadow > passwd_shadow
[root@CentOS /test]# ls
file1 file2 file3 passwd_shadow
[root@CentOS /test]# cat passwd_shadow
5. 'head' 명령어
Ex1) 'head -n' 옵션 명령어 (라인수 만큼 출력)
[root@CentOS /test]# head /etc/passwd (기본적으로 10번째줄까지 출력함)
[root@CentOS /test]# head -n 5 /etc/passwd
Ex2) 'head -c' 옵션 명령어 (문자수 만큼 출력)
[root@CentOS /test]# head -c 10 /etc/passwd
root:x:0:0
[root@CentOS /test]# head -c 20 /etc/passwd
root:x:0:0:root:/roo
Ex3) 'head'를 이용한 프로세스 정보 확인
[root@CentOS /test]# ps -ef
[root@CentOS /test]# ps -ef | more
[root@CentOS /test]# ps -ef | grep inetd
root 24373 16641 1 11:42 pts/1 00:00:00 grep inetd
[root@CentOS /test]# ps -ef | head -1
UID PID PPID C STIME TTY TIME CMD
[root@CentOS /test]# ps -ef | head -2
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Dec21 ? 00:00:03 /sbin/init
[root@CentOS /test]# ps -ef | head -1 ; ps -ef | grep inetd
UID PID PPID C STIME TTY TIME CMD
root 24391 16641 0 11:43 pts/1 00:00:00 grep inetd
Ex4) 'alias'와 'head'를 이용한 프로세스 정보 확인
[root@CentOS /test]# alias pps='ps -ef | head -1 ; ps -ef | grep $1'
[root@CentOS /test]# pps inetd
UID PID PPID C STIME TTY TIME CMD
root 24417 16641 0 11:45 pts/1 00:00:00 grep inetd
[root@CentOS /test]# pps syslogd
UID PID PPID C STIME TTY TIME CMD
root 1805 1 0 Dec21 ? 00:00:01 /sbin/rsyslogd -i /var/run/syslogd.pid -c 5
root 24423 16641 0 11:45 pts/1 00:00:00 grep syslogd
6. 'tail' 명령어
Ex1) 'tail -n' 옵션 명령어 (라인수 만큼 출력)
[root@CentOS /test]# tail /etc/passwd (기본적으로 10번째줄까지 출력함)
[root@CentOS /test]# tail -n 5 /etc/passwd
Ex2) 'tail -c' 옵션 명령어 (문자수 만큼 출력)
[root@CentOS /test]# tail -c 10 /etc/passwd
/bin/bash
[root@CentOS /test]# tail -c 20 /etc/passwd
/testuser:/bin/bash
Ex3) 'head' 명령어와 같이 사용하는 방법
[root@CentOS /test]# cp /etc/passwd /test/filename
[root@CentOS /test]# ls
file1 file2 file3 filename passwd_shadow
[root@CentOS /test]# head -20 filename | tail -10
[root@CentOS /test]# nl filename
[root@CentOS /test]# nl filename | head -20
1 root:x:0:0:root:/root:/bin/bash
2 bin:x:1:1:bin:/bin:/sbin/nologin
3 daemon:x:2:2:daemon:/sbin:/sbin/nologin
4 adm:x:3:4:adm:/var/adm:/sbin/nologin
5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
6 sync:x:5:0:sync:/sbin:/bin/sync
7 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
8 halt:x:7:0:halt:/sbin:/sbin/halt
9 mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
10 uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
11 operator:x:11:0:operator:/root:/sbin/nologin
12 games:x:12:100:games:/usr/games:/sbin/nologin
13 gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
14 ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
15 nobody:x:99:99:Nobody:/:/sbin/nologin
16 dbus:x:81:81:System message bus:/:/sbin/nologin
17 usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
18 vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
19 rpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologin
20 rtkit:x:499:497:RealtimeKit:/proc:/sbin/nologin
[root@CentOS /test]# nl filename | head -20 | tail -10
11 operator:x:11:0:operator:/root:/sbin/nologin
12 games:x:12:100:games:/usr/games:/sbin/nologin
13 gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
14 ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
15 nobody:x:99:99:Nobody:/:/sbin/nologin
16 dbus:x:81:81:System message bus:/:/sbin/nologin
17 usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
18 vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
19 rpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologin
20 rtkit:x:499:497:RealtimeKit:/proc:/sbin/nologin
[root@CentOS /test]# cd ..
[root@CentOS /]# rm -rf test
'서버 > Linux I' 카테고리의 다른 글
Linux I - 07. 리눅스 기본 명령어 (메타 케릭터/리다이렉션/파이프) (0) | 2015.12.23 |
---|---|
Linux I - 06. 리눅스 기본 명령어 (기타 관리 및 검색 명령어) (0) | 2015.12.23 |
Linux I - 04. 리눅스 기본 명령어 (파일 관리 명령어) (0) | 2015.12.23 |
Linux I - 03. 리눅스 기본 명령어 (디렉토리 관리 명령어) (0) | 2015.12.23 |
Linux I - 02. 리눅스 기본 명령어 (디렉토리 이동 관련 명령어) (0) | 2015.12.23 |