각 디렉토리의 로그 아카이브에 최신 파일을 가져오는 Unix 명령이 있습니까 /app/instance
? 아래 예에는 , , , 5개의 폴더가 있으며
/app/instance
각 as_a
아카이브 폴더 에서 as_b
최신 파일을 가져와야 합니다 .as_c
aunz
naeu
weekend.log
문서:
18790 Nov 15 13:48 /app/instance/as_a/logsarchive/log_20151115_134850/weekend.log
24533 Nov 15 14:20 /app/instance/aunz/logsarchive/log_20151115_141952/weekend.log
69906 Nov 21 08:30 /app/instance/naeu/logsarchive/log_20151121_083000/weekend.log
37923 Nov 21 11:10 /app/instance/as_a/logsarchive/log_20151121_111000/weekend.log
30830 Nov 21 11:15 /app/instance/as_b/logsarchive/log_20151121_111500/weekend.log
16186 Nov 21 11:20 /app/instance/as_c/logsarchive/log_20151121_112000/weekend.log
36365 Nov 21 11:25 /app/instance/as_c/logsarchive/log_20151121_112500/weekend.log
28407 Nov 22 01:23 /app/instance/as_b/logsarchive/log_20151122_012247/weekend.log
28407 Nov 22 10:14 /app/instance/aunz/logsarchive/log_20151122_101339/weekend.log
50945 Nov 28 08:30 /app/instance/naeu/logsarchive/log_20151128_083000/weekend.log
32704 Nov 28 11:10 /app/instance/as_a/logsarchive/log_20151128_111000/weekend.log
30931 Nov 28 11:15 /app/instance/as_b/logsarchive/log_20151128_111500/weekend.log
16186 Nov 28 11:20 /app/instance/as_c/logsarchive/log_20151128_112000/weekend.log
31297 Nov 28 11:25 /app/instance/aunz/logsarchive/log_20151128_112500/weekend.log
24533 Nov 29 10:10 /app/instance/aunz/logsarchive/log_20151129_101033/weekend.log
예상 출력:
32704 Nov 28 11:10 /app/instance/as_a/logsarchive/log_20151128_111000/weekend.log
30931 Nov 28 11:15 /app/instance/as_b/logsarchive/log_20151128_111500/weekend.log
16186 Nov 28 11:20 /app/instance/as_c/logsarchive/log_20151128_112000/weekend.log
50945 Nov 28 08:30 /app/instance/naeu/logsarchive/log_20151128_083000/weekend.log
24533 Nov 29 10:10 /app/instance/aunz/logsarchive/log_20151129_101033/weekend.log
답변1
다음과 같이 시도해 보세요:
for dir in /app/instance/*; do
ls -lcrt "$dir/logsarchive"/*/weekend.log | tail -n 1
done
/app/instance
루프는 하위 디렉터리를 하나씩 반복하며 시간별로 정렬된 tail -n 1
의 마지막 행만 유지합니다 . 귀하가 사용하는 것과 정확히 동일한 형식이 ls
아닐 수도 있지만 ls
이는 귀하가 찾고 있는 것과 비슷할 것입니다.