Linux 「ls」コマンドで更新日時でソートして表示する

  • 作成日 2022.01.26
  • 更新日 2022.10.15
  • linux
Linux 「ls」コマンドで更新日時でソートして表示する

Linuxで、「ls」コマンドで更新日時でソートして表示する手順を記述してます。

環境

  • OS Rocky Linux release 8.4 (Green Obsidian)

更新日時でソート

「ls」コマンド実行時に、更新日時でソートしてから表示するには「-t」を使用します。
※更新日時を表示する場合は「-l」も使用します。

$ ls -tl

<出力結果>
drwxr-xr-x.  4 root  lp        4096  8月 28 11:53 cups
-rw-r--r--   1 root  root       879  8月 27 10:27 mongod.conf
-rw-r--r--   1 root  root     50515  8月 27 09:10 ld.so.cache
----------   1 root  root      1544  8月 27 09:09 shadow
-rw-r--r--   1 root  root      3113  8月 27 09:09 passwd
----------   1 root  root       989  8月 27 09:09 gshadow
-rw-r--r--   1 root  root      1220  8月 27 09:09 group
drwxr-xr-x.  2 root  root      4096  8月 27 09:07 yum.repos.d
drwxr-xr-x   2 root  root        23  8月 26 14:56 caddy
-rw-r--r--.  1 root  root      3063  8月 26 14:56 passwd-
----------.  1 root  root      1522  8月 26 14:56 shadow-
-rw-r--r--.  1 root  root      1206  8月 26 14:56 group-
----------.  1 root  root       978  8月 26 14:56 gshadow-
drwxr-xr-x.  4 root  root        68  8月 26 13:16 udev

逆順で表示したい場合は「-r」を使用します。

$ ls -tlr

<出力結果>
-rw-r--r--.  1 root  root      2391  7月 24  2015 libuser.conf
-rw-r--r--.  1 root  root       642 12月 10  2016 xattr.conf
-rw-r--r--.  1 root  root     60352  5月 11  2017 mime.types
-rw-r--r--.  1 root  root       272  5月 11  2017 mailcap
-rw-r--r--.  1 root  root       438  2月 19  2018 logrotate.conf
-rw-r--r--.  1 root  root      1634  8月  1  2018 rpc
-rw-r--r--.  1 root  root         0  9月 10  2018 subuid-
-rw-r--r--.  1 root  root         0  9月 10  2018 subgid-
-rw-r--r--.  1 root  root        44  9月 10  2018 shells
-rw-r--r--.  1 root  root      6568  9月 10  2018 protocols
-rw-r--r--.  1 root  root       233  9月 10  2018 printcap
-rw-r--r--.  1 root  root        58  9月 10  2018 networks
-rw-r--r--.  1 root  root         0  9月 10  2018 motd
-rw-r--r--.  1 root  root       942  9月 10  2018 inputrc
-rw-r--r--.  1 root  root       158  9月 10  2018 hosts
-rw-r--r--.  1 root  root         9  9月 10  2018 host.conf
-rw-r--r--.  1 root  root        66  9月 10  2018 filesystems
-rw-r--r--.  1 root  root         0  9月 10  2018 exports
-rw-r--r--.  1 root  root      1362  9月 10  2018 ethertypes
-rw-r-----.  1 root  chrony     540  5月 10  2019 chrony.keys
-rw-r--r--.  1 root  root      1078  5月 10  2019 chrony.conf
-rw-r-----.  1 root  root       191 11月  5  2019 libaudit.conf