tail : 마지막 부분 출력하기, diff: 두 파일의 차이점 출력하기
tail
$ tail -n 5 <file> # 파일의 마지막 5행 출력
$ tail <file> # 파일의 마지막 10행 출력
실시간으로 내용을 출력하여 파일을 모니터링 -> 주로 로그를 모니터링
tail -f <파일 이름>
$ tail -f output.log
diff
diff [옵션] <비교 파일 1> <비교 파일 2>
diff 명령어 테스트
$ diff temp_list.txt temp_listcp.txt
2c2
< lrwxrwxrwx 1 root root 7 Mar 1 02:07 bin -> usr/bin
---
> lrwxrwxrwx 1 root root 7 Mar 1 02:07 bin -> change test
7,10d6
< lrwxrwxrwx 1 root root 7 Mar 1 02:07 lib -> usr/lib
< lrwxrwxrwx 1 root root 9 Mar 1 02:07 lib32 -> usr/lib32
< lrwxrwxrwx 1 root root 9 Mar 1 02:07 lib64 -> usr/lib64
< lrwxrwxrwx 1 root root 10 Mar 1 02:07 libx32 -> usr/libx32
24a21
> ---diff command test
# 첫번째 파일의 2번째 행이 두번째 파일의 2번째 행으로 변경 : 기호 c
2c2
< lrwxrwxrwx 1 root root 7 Mar 1 02:07 bin -> usr/bin
---
> lrwxrwxrwx 1 root root 7 Mar 1 02:07 bin -> change test
# 첫번째 파일의 7~10행이 삭제됨 : 기호 d
7,10d6
< lrwxrwxrwx 1 root root 7 Mar 1 02:07 lib -> usr/lib
< lrwxrwxrwx 1 root root 9 Mar 1 02:07 lib32 -> usr/lib32
< lrwxrwxrwx 1 root root 9 Mar 1 02:07 lib64 -> usr/lib64
< lrwxrwxrwx 1 root root 10 Mar 1 02:07 libx32 -> usr/libx32
# 첫번째 파일의 24행 뒤에 두번째 파일의 21번행에 있는 내용이 추가됨: 기호 a
24a21
> ---diff command test
통일포맷 옵션 -u : 변화를 더 쉽게 확인 하는 방법
$diff -u temp_list.txt temp_listcp.
--- temp_list.txt 2024-03-31 10:01:39.331756376 +0000
+++ tmpe_listcp.txt 2024-04-03 04:33:22.347779185 +0000
@@ -1,13 +1,9 @@
total 64
-lrwxrwxrwx 1 root root 7 Mar 1 02:07 bin -> usr/bin
+lrwxrwxrwx 1 root root 7 Mar 1 02:07 bin -> change test
drwxr-xr-x 4 root root 4096 Mar 27 06:50 boot
drwxr-xr-x 16 root root 3260 Mar 26 17:32 dev
drwxr-xr-x 96 root root 4096 Mar 29 06:15 etc
drwxr-xr-x 3 root root 4096 Mar 15 23:42 home
-lrwxrwxrwx 1 root root 7 Mar 1 02:07 lib -> usr/lib
-lrwxrwxrwx 1 root root 9 Mar 1 02:07 lib32 -> usr/lib32
-lrwxrwxrwx 1 root root 9 Mar 1 02:07 lib64 -> usr/lib64
-lrwxrwxrwx 1 root root 10 Mar 1 02:07 libx32 -> usr/libx32
drwx------ 2 root root 16384 Mar 1 02:10 lost+found
drwxr-xr-x 2 root root 4096 Mar 1 02:07 media
drwxr-xr-x 2 root root 4096 Mar 1 02:07 mnt
@@ -22,3 +18,4 @@
drwxrwxrwt 12 root root 4096 Mar 31 05:26 tmp
drwxr-xr-x 14 root root 4096 Mar 1 02:07 usr
drwxr-xr-x 14 root root 4096 Mar 16 02:30 var
+---diff command test
깃허브에서 보여주는 방식과 유사하게 두 파일의 차이점을 보여준다.
@@ -<첫 번째 파일의 시작 행>,<시작행으로 부터 출력된 행의 수> +<두번째 파일의 시작 행><시작 행으로 부터 출력된 행의 수> @@
@@ -1,13 +1,9 @@
-> 첫 번째 파일의 1 행 부터 시작해서 13 개의 행을 출력
-> 두 번째 파일의 1 행 부터 시작해서 9 개의 행을 출력
'책 > 모두의 리눅스' 카테고리의 다른 글
[ 책 ] [ 모두의 리눅스 ] 13장 메타문자 (0) | 2024.04.04 |
---|---|
[ 책 ] [ 모두의 리눅스 ] 13 장 grep, 정규표현식 (0) | 2024.04.03 |
[ 책 ] [ 모두의 리눅스 ] 12장 cut, tr (0) | 2024.04.02 |
[ 책 ] [ 모두의 리눅스 ] 12장 unique 명령어 (0) | 2024.04.02 |
[ 책 ] [ 모두의 리눅스 ] 12장 텍스트 처리 (0) | 2024.04.01 |