tail -f
지정된 폴더의 로그인 파일을 추적하는 데 사용하려고 합니다 . 간단한 명령으로 이 작업을 수행할 수 있지만 tail -f [path to file]
폴더에서 가장 최근/마지막으로 수정된 파일을 실행하고 추적하는 명령을 가질 수 있는 방법이 있습니까? 이 분야의 전문가는 아니므로 도움을 주시면 감사하겠습니다.
답변1
명령을 실행 ls -tp | sort | grep -v / | tail -n 1
하고 이를 통해 실행할 수 있습니다.for
그런 다음 tail -F
최신 파일에 대해서만 명령을 실행하여 내용 변경 사항을 모니터링합니다. 대신 명령을 고려할 수도 있습니다 ls -tpr | grep -v / | tail -n 1
.
for VAR in $(ls -tp | sort | grep -v / | tail -n 1); do tail -F $VAR; done
또는
for VAR in $(ls -tpr | grep -v / | tail -n 1); do tail -F $VAR; done
추가 리소스
-
-t sort by modification time, newest first -p, --indicator-style=slash append / indicator to directories -r, --reverse reverse order while sorting
-
-v, --invert-match Invert the sense of matching, to select non-matching lines. (-v is specified by POSIX .)
-
-n, --lines=[+]NUM output the last NUM lines, instead of the last 10; or use -n +NUM to output starting with line NUM
답변2
당신은 사용할 수 있습니다 멀티테일, 많은 배포판에서 표준 패키지로 제공됩니다.
예시 1 : 두 개의 로그 파일을 하나의 창에 서로 다른 색상으로 병합
multitail -ci green /var/log/yum.log -ci yellow -I /var/log/mysqld.log
예시 2 : 5개의 로그 파일을 표시하고 두 개를 하나의 열에 병합
multitail -s 2 -sn 1,3 /var/log/mysqld.log -I /var/log/xferlog /var/log/monitorix /var/log/ajenti.log /var/log/yum.log