ls

ファイルとディレクトリ

書き方

ls -la [path]

ディレクトリの中身を一覧します。ドットで始まる名前は -a を付けるまで出てきません。

よく使うオプション

オプション意味
-lOne line per entry with mode, owner, size and time
-aInclude names that begin with a dot
-hSizes as 4.0K instead of 4096, together with -l
-tSort by modification time, newest first
-rReverse whatever order is in effect
-SSort by size, largest first
-RWalk into subdirectories
-dShow the directory itself instead of its contents

ls -lh

Long listing with readable sizes.

ls -lat

Newest first, hidden files included.

ls -d */

Only the directories in this folder.

移したり消したり探したりするものです。聞き返してくれない命令が混ざっているので、-i を付ける癖が手を守ります。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. ls は何をしますか。

ディレクトリの中身を一覧します。ドットで始まる名前は -a を付けるまで出てきません。

Q. どう打ちますか。

ls -la [path] — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは8個です。全部は man ls にあります。このコマンドはファイルとディレクトリの仲間です。

関連するコマンド

man ページ: man ls