LoginSignup
2
6

More than 5 years have passed since last update.

lsのオプション

Last updated at Posted at 2017-08-30

今まで何となく使っていた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オプションでディレクトリが見やすくなるのも結構いいなと思いました。

2
6
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
2
6