管理人Kのひとりごと

デジモノレビューやプログラミングや写真など

lsの結果を更新時間でソートする

自分用の備忘録。

検証環境

hoge@localhost:~$ ls --version
ls (GNU coreutils) 8.28
Copyright (C) 2017 Free Software Foundation, Inc.
ライセンス GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

作者 Richard M. Stallman および David MacKenzie。

lsの結果を更新時間でソートする

「-t」を付ける
※デフォルトだと降順(新しいほど上にくる)ので、昇順に並べるには「r」を付けて
「-tr」(または、「-rt」)とする

実行例

# 指定なし(「l」がないと正しくソートされているのかわからないのでつけています)
hoge@localhost:/etc/profile.d$ ls -l
合計 24
-rw-r--r-- 1 root root   96  820  2018 01-locale-fix.sh
-rw-r--r-- 1 root root 1557 124  2017 Z97-byobu.sh
-rwxr-xr-x 1 root root 3417  312  2019 Z99-cloud-locale-test.sh
-rwxr-xr-x 1 root root  873  312  2019 Z99-cloudinit-warnings.sh
-rw-r--r-- 1 root root  825  321 18:55 apps-bin-path.sh
-rw-r--r-- 1 root root  664  42  2018 bash_completion.sh
-rw-r--r-- 1 root root 1003 1229  2015 cedilla-portuguese.sh
lrwxrwxrwx 1 root root   34  715 20:32 wsl-integration.sh -> /usr/share/wslu/wsl-integration.sh

# 更新日付の降順にソート
hoge@localhost:/etc/profile.d$ ls -lt
合計 24
lrwxrwxrwx 1 root root   34  715 20:32 wsl-integration.sh -> /usr/share/wslu/wsl-integration.sh
-rw-r--r-- 1 root root  825  321 18:55 apps-bin-path.sh
-rwxr-xr-x 1 root root 3417  312  2019 Z99-cloud-locale-test.sh
-rwxr-xr-x 1 root root  873  312  2019 Z99-cloudinit-warnings.sh
-rw-r--r-- 1 root root   96  820  2018 01-locale-fix.sh
-rw-r--r-- 1 root root  664  42  2018 bash_completion.sh
-rw-r--r-- 1 root root 1557 124  2017 Z97-byobu.sh
-rw-r--r-- 1 root root 1003 1229  2015 cedilla-portuguese.sh

# 更新日付の昇順にソート
hoge@localhost:/etc/profile.d$ ls -ltr
合計 24
-rw-r--r-- 1 root root 1003 1229  2015 cedilla-portuguese.sh
-rw-r--r-- 1 root root 1557 124  2017 Z97-byobu.sh
-rw-r--r-- 1 root root  664  42  2018 bash_completion.sh
-rw-r--r-- 1 root root   96  820  2018 01-locale-fix.sh
-rwxr-xr-x 1 root root  873  312  2019 Z99-cloudinit-warnings.sh
-rwxr-xr-x 1 root root 3417  312  2019 Z99-cloud-locale-test.sh
-rw-r--r-- 1 root root  825  321 18:55 apps-bin-path.sh
lrwxrwxrwx 1 root root   34  715 20:32 wsl-integration.sh -> /usr/share/wslu/wsl-integration.sh