0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ls

Last updated at Posted at 2021-03-11

ディレクトリとファイル一覧が確認できる。

# ls ディレクトリ名

ls -la で、名前が . で始まるファイル・ディレクトリも表示される。

# ls -la ディレクトリ名

ファイルサイズをわかりやすく表示させる時は -h オプションをつける。

# ls -lah
-rw-r--r-- 1 miisuke wheel   202 Jul  5 15:32 apache-playbook.yml
-rw-r--r-- 1 miisuke wheel  8.7M Jul  1 20:46 apache-tomcat-8.0.24.tar.gz
drwxr-xr-x 2 miisuke wheel  4.0K Jul  4 10:20 backup

タイプスタンプ順にソートさせて表示する時は -t オプションをつける。

# ls -laht
-rw------- 1 miisuke miisuke 1.1K Jul 26 10:23 .bash_history
drwx------ 7 miisuke miisuke 4.0K Jul 12 05:53 .
-rw-r--r-- 1 miisuke miisuke    0 Jul 11 14:33 copy

逆順にソートして表示させる時は -r オプションをつける。

# ls -lahtr
-rw-r--r-- 1 miisuke miisuke  124 Mar  4 05:16 .bashrc
-rw-r--r-- 1 miisuke miisuke   18 Mar  4 05:16 .bash_logout
drwxr-xr-x 4 root   root   4.0K Jun 20 15:28 ..

自分がよく使うオプション

更新が古い順に表示させる時は「ls -lahtr」
更新が新しい順に表示させる時は「ls -laht」
単純に一覧を表示させる時は「ls -lah」

あるディレクトリ配下全てのファイル数を数える

# cd <移動先ディレクトリ>
# ls -laR | grep -c '^-'

ls の R オプションで、ディレクトリ内を再帰的に表示させる。
grep の c オプションで、条件にマッチした行数を表示する。
この場合は、頭文字が - のものだけカウントしている。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?