본문 바로가기

개발/shell

tail 명령어

서버 관리자라면 로그를 계속 들여다 봐야 할 상황이 있는데 이럴때는 tail 명령어로 휙휙 사용하면 실시간으로 발생 되는 로그를 계속 해서 볼수도 있습니다.

tail 이 하는 주요 기능은 파일의 마지막 내용을 출력 해줍니다. (로그파일을 볼때 주로 사용 합니다.)
[root@ruo91 ~]# tail [옵션] [파일]

위와 같이 아무 옵션 없이 기본값으로 쓰게 되면 파일의 내용 중 마지막 10번째 줄을 출력 해주게 됩니다.
아래와 같이 말이죠.
[root@ruo91 ~]# tail /var/log/boot.log
Oct 31 02:20:27 ruo91 dhcpd: Internet Systems Consortium DHCP Server 4.0.2b3
Oct 31 02:20:27 ruo91 dhcpd: Copyright 2004-2009 Internet Systems Consortium.
Oct 31 02:20:27 ruo91 dhcpd: All rights reserved.
Oct 31 02:20:27 ruo91 dhcpd: For info, please visit https://www.isc.org/software/dhcp/
Oct 31 02:20:27 ruo91 dhcpd: Wrote 0 deleted host decls to leases file.
Oct 31 02:20:27 ruo91 dhcpd: Wrote 0 new dynamic host decls to leases file.
Oct 31 02:20:27 ruo91 dhcpd: Wrote 0 leases to leases file.
Oct 31 02:20:27 ruo91 dhcpd: Listening on LPF/eth1/00:0c:29:aa:dd:c4/192.168.2.0/24
Oct 31 02:20:27 ruo91 dhcpd: Sending on   LPF/eth1/00:0c:29:aa:dd:c4/192.168.2.0/24
Oct 31 02:20:27 ruo91 dhcpd: Sending on   Socket/fallback/fallback-net
몇가지 옵션을 보자면...
--bytes=N : Nbyte 만큼 출력 해줍니다.
-f
파일의 10줄을 출력 해주고 파일의 내용을 실시간으로 계속해서 출력 해줍니다.
-n N
n 개수 만큼 라인을 출력 해줍니다.

바로 옵션들을 써보죠..
300bytes 만큼 출력
[root@ruo91 ~]# tail --bytes=300 /var/log/boot.log

Oct 31 02:20:27 ruo91 dhcpd: Wrote 0 leases to leases file.
Oct 31 02:20:27 ruo91 dhcpd: Listening on LPF/eth1/00:0c:29:aa:dd:c4/192.168.2.0/24
Oct 31 02:20:27 ruo91 dhcpd: Sending on   LPF/eth1/00:0c:29:aa:dd:c4/192.168.2.0/24
Oct 31 02:20:27 ruo91 dhcpd: Sending on   Socket/fallback/fallback-net
-f 옵션은 아파치 로그 같은 것을 수시로 확인 해야 할때 보시면 되겠습니다.

-n 옵션을 사용하여 2, 5, 10 개씩 출력
[root@ruo91 ~]# tail -n 2 /var/log/boot.log
Oct 31 02:20:27 ruo91 dhcpd: Sending on   LPF/eth1/00:0c:29:aa:dd:c4/192.168.2.0/24
Oct 31 02:20:27 ruo91 dhcpd: Sending on   Socket/fallback/fallback-net
[root@ruo91 ~]# tail -n 5 /var/log/boot.log
Oct 31 02:20:27 ruo91 dhcpd: Wrote 0 new dynamic host decls to leases file.
Oct 31 02:20:27 ruo91 dhcpd: Wrote 0 leases to leases file.
Oct 31 02:20:27 ruo91 dhcpd: Listening on LPF/eth1/00:0c:29:aa:dd:c4/192.168.2.0/24
Oct 31 02:20:27 ruo91 dhcpd: Sending on   LPF/eth1/00:0c:29:aa:dd:c4/192.168.2.0/24
Oct 31 02:20:27 ruo91 dhcpd: Sending on   Socket/fallback/fallback-net
[root@ruo91 ~]# tail -n 10 /var/log/boot.log
Oct 31 02:20:27 ruo91 dhcpd: Internet Systems Consortium DHCP Server 4.0.2b3
Oct 31 02:20:27 ruo91 dhcpd: Copyright 2004-2009 Internet Systems Consortium.
Oct 31 02:20:27 ruo91 dhcpd: All rights reserved.
Oct 31 02:20:27 ruo91 dhcpd: For info, please visit https://www.isc.org/software/dhcp/
Oct 31 02:20:27 ruo91 dhcpd: Wrote 0 deleted host decls to leases file.
Oct 31 02:20:27 ruo91 dhcpd: Wrote 0 new dynamic host decls to leases file.
Oct 31 02:20:27 ruo91 dhcpd: Wrote 0 leases to leases file.
Oct 31 02:20:27 ruo91 dhcpd: Listening on LPF/eth1/00:0c:29:aa:dd:c4/192.168.2.0/24
Oct 31 02:20:27 ruo91 dhcpd: Sending on   LPF/eth1/00:0c:29:aa:dd:c4/192.168.2.0/24
Oct 31 02:20:27 ruo91 dhcpd: Sending on   Socket/fallback/fallback-net

'개발 > shell' 카테고리의 다른 글

리눅스 버전,cpu, memory, disk 확인하기  (0) 2012.02.05
PATH 설정  (0) 2012.02.05
chmod 권한에 대해서  (0) 2012.02.05
find 명령어  (0) 2012.02.05
부팅시 자동실행 스크립트  (0) 2012.02.05