LoginSignup
0
0

More than 5 years have passed since last update.

ls > -c > { with -lt: ctimeで(降順に)ソート | with -t: nameで(昇順に)ソート | otherwise: ctimeで(降順に)ソート(ctimeは表示しない) } | link: explainshell.com > オプション説明の表示

Last updated at Posted at 2018-01-23
動作環境
Xeon E5-2620 v4 (8コア) x 2
32GB RAM
CentOS 6.8 (64bit)
openmpi-1.8.x86_64 とその-devel
mpich.x86_64 3.1-5.el6とその-devel
gcc version 4.4.7 (とgfortran)
NCAR Command Language Version 6.3.0
WRF v3.9を使用。
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) 
Python 3.6.0 on virtualenv
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
date (GNU coreutils) 8.4 
tmux 1.6-3.el6

ls -cのオプションがある。

man lsは以下の通り。


-c with -lt: sort by, and show, ctime (time of last modification of file status information) with -l: show
ctime and sort by name otherwise: sort by ctime

上記には三つのオプションが書かれている (-ltc, -lc, lc)。

sort byのソートが昇順、降順で混在しているようだ。

with -lt (-ltc)

ctimeで「降順」にソートされているようだ (16:09や16:08に注目)。

$ ls -clt FNL\:2017-1* | head -n 3
-rw-rw-r-- 1 7of9 7of9 48783064 Jan 23 16:09 FNL:2017-12-23_00
-rw-rw-r-- 1 7of9 7of9 48783064 Jan 23 16:09 FNL:2017-12-22_18
-rw-rw-r-- 1 7of9 7of9 48783064 Jan 23 16:09 FNL:2017-12-22_12
$ ls -clt FNL\:2017-1* | tail -n 3
-rw-rw-r-- 1 7of9 7of9 48783064 Jan 23 16:08 FNL:2017-11-17_12
-rw-rw-r-- 1 7of9 7of9 48783064 Jan 23 16:08 FNL:2017-11-17_06
-rw-rw-r-- 1 7of9 7of9 48783064 Jan 23 16:08 FNL:2017-11-17_00

with -l (-lc)

nameで「昇順」にソートされているようだ (FNL:2017-11-17_00やFNL:2017-12-23_00に注目)。

$ ls -cl FNL\:2017-1* | head -n 3
-rw-rw-r-- 1 7of9 7of9 48783064 Jan 23 16:08 FNL:2017-11-17_00
-rw-rw-r-- 1 7of9 7of9 48783064 Jan 23 16:08 FNL:2017-11-17_06
-rw-rw-r-- 1 7of9 7of9 48783064 Jan 23 16:08 FNL:2017-11-17_12
$ ls -cl FNL\:2017-1* | tail -n 3
-rw-rw-r-- 1 7of9 7of9 48783064 Jan 23 16:09 FNL:2017-12-22_12
-rw-rw-r-- 1 7of9 7of9 48783064 Jan 23 16:09 FNL:2017-12-22_18
-rw-rw-r-- 1 7of9 7of9 48783064 Jan 23 16:09 FNL:2017-12-23_00

otherwise (-c)

ctimeで「降順」にソートされ、ctimeは表示されない。

$ ls -c FNL\:2017-1* | head -n 3
FNL:2017-12-23_00
FNL:2017-12-22_18
FNL:2017-12-22_12
$ ls -c FNL\:2017-1* | tail -n 3
FNL:2017-11-17_12
FNL:2017-11-17_06
FNL:2017-11-17_00

備考

ls -c-l-tを使用する場合、「昇順」と「降順」のどちらなのか理解をしていないと反対のファイルを処理してしまうかもしれない。

そういうスクリプトを書くと、後々のメンテナンス時に「昇順」と「降順」のどちらなのかを調べる羽目になるだろう。

リンク

list directory contents
...
-t sort by modification time, newest first
...
-c ...

-tのオプション説明を見ると「降順(newest first)」というのが分かる。-cオプションの説明だけではそれは不明瞭だ。

偶然見つけたexplainshell.comのように、関連情報だけがまとまって表示されると分かりやすい。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0