今まで何となく使っていたls
コマンドのオプションについて、よく使うものを纏めて見ました。
コマンド
ls
現在のディレクトリ配下のファイルとディレクトリをアルファベット順に表示する。
ただしドット(.)で始まるものについては表示しない。
[centos@ip-10-0-1-10 ~]$ ls
test testdir testtest
ls -a
ドット(.)で始まるものも表示する。
[centos@ip-10-0-1-10 ~]$ ls -a
. .. .bash_history .bash_logout .bash_profile .bashrc .lesshst .ssh test testdir testtest
ls -A
ドット(.)とダブルドット(..)は表示しない。
[centos@ip-10-0-1-10 ~]$ ls -A
.bash_history .bash_logout .bash_profile .bashrc .lesshst .ssh test testdir testtest
ls -l
詳細な情報を表示する。
[centos@ip-10-0-1-10 ~]$ ls -l
total 4
-rw-rw-r--. 1 centos centos 0 Aug 30 15:49 test
drwxrwxr-x. 2 centos centos 6 Aug 30 15:31 testdir
-rw-rw-r--. 1 centos centos 270 Aug 30 15:44 testtest
ls -S
ファイルサイズの大きい順に表示する。
[centos@ip-10-0-1-10 ~]$ ls -lS
total 4
-rw-rw-r--. 1 centos centos 270 Aug 30 15:44 testtest
drwxrwxr-x. 2 centos centos 6 Aug 30 15:31 testdir
-rw-rw-r--. 1 centos centos 0 Aug 30 15:49 test
ls -t
更新日付の新しいものから順に表示する。
[centos@ip-10-0-1-10 ~]$ ls -lt
total 4
-rw-rw-r--. 1 centos centos 0 Aug 30 15:49 test
-rw-rw-r--. 1 centos centos 270 Aug 30 15:44 testtest
drwxrwxr-x. 2 centos centos 6 Aug 30 15:31 testdir
利用シーン別
特定のファイルが存在することを確認したい
ls [filename]
とりあえずこのディレクトリの中身を全て見たい
ls -A
容量の大きいファイルを探したい
ls -lhS
※hはhuman readable、容量にKやMの単位を付けて表示する
古いファイルを探したい
ls -lrt
※rはreverse、結果を逆順に表示する
ひとこと
今までは何も考えずls -la
と使っていましたが、-a
オプションを使う機会はそんなに無いのかも。Shiftキーを押す手間を厭わないなら-A
で良いケースが多そうですね。
同じく打鍵が増えるけれど、-p
オプションでディレクトリが見やすくなるのも結構いいなと思いました。