리눅스 head 명령어 & tail 명령어

리눅스 head 명령어는 파일의 처음 10줄을 보여주는 명령어이며, tail 명령어는 파일의 마지막 10줄을 보여주는 명령어입니다. 옵션 없이 사용할 경우 각각의 머리와 꼬리 부분을 보여주는 것을 알 수 있습니다.
head와 tail 명령어는 보통 서버의 access_log를 볼 때 주로 많이 사용됩니다. 두 명령어의 사용법과 테스트 서버에서 access_log를 각각의 명령어를 통해 확인 해 보겠습니다.
✅ 리눅스 head 명령어 사용법
기본 사용 방법은 다음과 같습니다.
head -[옵션] [파일명]access_log를 출력한 결과입니다.

1. head 명령어 옵션
2. 사용 예시
head -50 access_log✅ 리눅스 tail 명령어 사용법
tail 명령어는 [-f] 옵션으로 서버의 access_log 및 error_log의 실시간 로그를 볼 때 특히 많이 사용하게 되는 명령어입니다.
tail -[옵션] [파일명]1. tail 명령어 옵션
2. 사용 예시
tail -n 15 -f access_log
192.36.109.115 - - [13/Feb/2024:00:47:34 +0000] "GET /robots.txt HTTP/1.1" 404 196 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36"
192.36.109.127 - - [13/Feb/2024:00:47:35 +0000] "GET /humans.txt HTTP/1.1" 404 196 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36"
192.36.109.90 - - [13/Feb/2024:00:47:35 +0000] "GET /ads.txt HTTP/1.1" 404 196 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36"
192.36.109.91 - - [13/Feb/2024:00:47:46 +0000] "GET / HTTP/1.1" 403 7620 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36"
191.101.130.24 - - [13/Feb/2024:01:28:02 +0000] "GET /.env HTTP/1.1" 404 196 "-" "Mozilla/5.0 (Linux; U; Android 4.4.2; en-US; HM NOTE 1W Build/KOT49H) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 UCBrowser/11.0.5.850 U3/0.8.0 Mobile Safari/534.30"
---- 생략 ----tail -n 15 -f access_log | grep 403
192.36.109.91 - - [13/Feb/2024:00:47:46 +0000] "GET / HTTP/1.1" 403 7620 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36"
186.176.7.162 - - [13/Feb/2024:01:42:57 +0000] "GET / HTTP/1.1" 403 7620 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36"
162.216.150.252 - - [13/Feb/2024:02:06:26 +0000] "GET / HTTP/1.1" 403 7620 "-" "Expanse, a Palo Alto Networks company, searches across the global IPv4 space multiple times per day to identify customers' presences on the Internet. If you would like to be excluded from our scans, please send IP addresses/domains to: scaninfo@paloaltonetworks.com"
146.19.24.28 - - [13/Feb/2024:02:27:04 +0000] "GET / HTTP/1.1" 403 7620 "-" "-"ℹ️ 제휴 안내
본 사이트의 콘텐츠에는 제휴 링크가 포함되어 있습니다. 방문자가 이 링크를 통해 상품 또는 서비스를 구매하면 본 사이트는 판매처로부터 수수료를 지급받습니다. 이 과정에서 구매자가 지불하는 금액(이벤트 할인 시 금액이 내려갑니다↓)은 오르지 않습니다. 게시된 가격·할인·재고 정보는 작성 시점 기준이며 실제와 다를 수 있으므로, 구매 전 판매처에서 최종 확인하시기 바랍니다. 상품 선정과 평가는 자체 기준에 따라 작성되며, 수수료 지급 여부가 소개 순서나 평가 내용에 영향을 주지 않습니다.