lsコマンドタイプスタンプで並び替え

2021-06-21

lsコマンドでファイルのタイプスタンプで、「新しい順番」、「古い順番」にソートする方法
新しい順番は、 ls -lt
古い順番は、ls -ltr

コマンドのオプションの意味は下記の通り
-l ファイルの詳細も同時に表示する
-t タイムスタンプ順にソートして表示する
-r 逆順にソートして表示する

詳細に表示する

]
$ sudo ls -l /var/log/httpd/ | head
合計 3164
-rw-r--r-- 1 root root 392482 11月 11 15:27 access_log
-rw-r--r-- 1 root root 590935 10月 18 04:02 access_log-20151018
-rw-r--r-- 1 root root 685662 10月 25 04:02 access_log-20151025
-rw-r--r-- 1 root root 744889 11月 2 03:47 access_log-20151102
-rw-r--r-- 1 root root 627121 11月 8 04:02 access_log-20151108
-rw-r--r-- 1 root root 6722 11月 11 11:02 error_log
-rw-r--r-- 1 root root 14130 10月 18 04:02 error_log-20151018
-rw-r--r-- 1 root root 12413 10月 25 04:02 error_log-20151025
-rw-r--r-- 1 root root 14697 11月 2 04:02 error_log-20151102

タイプスタンプで新しい順番にソート

$ sudo ls -lt /var/log/httpd/ | head
合計 3164
-rw-r--r-- 1 root root 392482 11月 11 15:27 access_log
-rw-r--r-- 1 root root 2365 11月 11 13:52 ssl_access_log
-rw-r--r-- 1 root root 4289 11月 11 13:52 ssl_error_log
-rw-r--r-- 1 root root 2589 11月 11 13:52 ssl_request_log
-rw-r--r-- 1 root root 6722 11月 11 11:02 error_log
-rw-r--r-- 1 root root 627121 11月 8 04:02 access_log-20151108
-rw-r--r-- 1 root root 14576 11月 8 04:02 error_log-20151108
-rw-r--r-- 1 root root 3265 11月 7 19:58 ssl_access_log-20151108
-rw-r--r-- 1 root root 4218 11月 7 19:58 ssl_request_log-20151108

タイプスタンプで古い順にソート

$ sudo ls -ltr /var/log/httpd/ | head
合計 3164
-rw-r--r-- 1 root root 8065 10月 17 11:02 ssl_error_log-20151018
-rw-r--r-- 1 root root 3270 10月 17 11:14 ssl_request_log-20151018
-rw-r--r-- 1 root root 2620 10月 17 11:14 ssl_access_log-20151018
-rw-r--r-- 1 root root 14130 10月 18 04:02 error_log-20151018
-rw-r--r-- 1 root root 590935 10月 18 04:02 access_log-20151018
-rw-r--r-- 1 root root 8395 10月 24 22:10 ssl_error_log-20151025
-rw-r--r-- 1 root root 3450 10月 25 01:05 ssl_request_log-20151025
-rw-r--r-- 1 root root 2693 10月 25 01:05 ssl_access_log-20151025
-rw-r--r-- 1 root root 12413 10月 25 04:02 error_log-20151025

スポンサーリンク

0
0

LinuxCentOS 6,CentOS 7,CentOS 8

Posted by admin