彩音 - UNIX - 研究室:XION - UNIX -laboratory
ファイルやディレクトリ一覧を表示する ls

lsはカレントディレクトリや、指定されたディレクトリのファイルやディレクトリの一覧を表示するコマンドです。

例:


% ls /
COPYRIGHT boot compat dist etc lib mnt rescue sbin sys usr
bin cdrom dev entropy home libexec proc root stand tmp var
%

lsコマンドにはたくさんのオプションがあります。代表的なオプションを覚えておきましょう。

lsの代表的なオプション

オプション名 内容
-a 「.」で始まるファイルやディレクトリも表示する
-l ファイルの詳細を表示する
-h -lオプションとともに使用した場合に
ファイルやディレクトリのサイズに合わせてB、KB、MB、GB、TB、PB単位で表示する
-F パスの最後にディレクトリ「/」、実行ファイル「*」、シンボリックリンク「@」、
ソケットファイル「=」、FIFO「|」を表示する
-G カラー出力を有効化。環境変数CLICOLORを定義することと同等
-R サブディレクトリを再帰的に表示する
-i i-node番号を表示する

-l と -a は特によく利用します。頻用しますので、FreeBSDなどでは、ls -l のエイリアスとして ll が、ls -a のエイリアスとして la が設定されています。

詳細表示、ls -l の内容は、パーミッション、リンク数、所有者名、所有グループ名、バイト数、最終更新が行われた際の月日時分、ファイルまたはディレクトリ名です。

ls -l (ll)の例:


% ls -l
total 49
-r--r--r-- 1 root wheel 6184 Nov 11 2004 COPYRIGHT
drwxr-xr-x 2 root wheel 1024 Oct 8 2005 bin
drwxr-xr-x 5 root wheel 512 Oct 8 2005 boot
drwxr-xr-x 2 root wheel 512 Oct 8 2005 cdrom
lrwxr-xr-x 1 root wheel 10 Oct 8 2005 compat -> usr/compat
dr-xr-xr-x 4 root wheel 512 Jun 22 02:58 dev
drwxr-xr-x 2 root wheel 512 Oct 8 2005 dist
-rw------- 1 root wheel 4096 Jun 21 17:54 entropy
drwxr-xr-x 17 root wheel 2048 Jun 22 00:05 etc
lrwxrwxrwx 1 root wheel 9 Oct 8 2005 home -> /usr/home
drwxr-xr-x 3 root wheel 1024 Oct 8 2005 lib
drwxr-xr-x 2 root wheel 512 Oct 8 2005 libexec
drwxr-xr-x 2 root wheel 512 Nov 11 2004 mnt
dr-xr-xr-x 2 root wheel 512 Nov 11 2004 proc
drwxr-xr-x 2 root wheel 2560 Oct 8 2005 rescue
drwxr-xr-x 2 root wheel 512 Jun 25 00:32 root
drwxr-xr-x 2 root wheel 2560 Oct 8 2005 sbin
drwxr-xr-x 4 root wheel 1024 Oct 8 2005 stand
lrwxrwxrwx 1 root wheel 11 Oct 8 2005 sys -> usr/src/sys
drwxrwxrwt 3 root wheel 512 Jun 25 01:24 tmp
drwxr-xr-x 17 root wheel 512 Oct 8 2005 usr
drwxr-xr-x 24 root wheel 512 Jun 22 04:26 var

ホームディレクトリに置かれる設定ファイルや設定ファイルをまとめたディレクトリは、名前が「.」から始まります。ls コマンドは「.」から始まるファイルやディレクトリは表示しません。-a を指定すると、「.」から始まるファイルやディレクトリも表示されます。

ls -a (la)の例:


% cd /root/
% ls -a
. .cshrc .k5login .profile
.. .history .login
%

オプションは組み合わせて指定することも出来ます。たとえば -l と -a を同時に指定すると、「.」から始まるファイルやディレクトリも含めて詳細表示が行われるようになります。指定方法は -a -l でも -al でもどちらでも利用出来ます。


% ls -al /
total 65
drwxr-xr-x 20 root wheel 512 Jun 21 17:54 .
drwxr-xr-x 20 root wheel 512 Jun 21 17:54 ..
-rw-r--r-- 2 root wheel 801 Nov 11 2004 .cshrc
-rw-r--r-- 2 root wheel 251 Nov 11 2004 .profile
drwxrwxr-x 2 root operator 512 Oct 8 2005 .snap
-rw-r--r-- 2 root wheel 4735 Nov 11 2004 .tcshrc
-r--r--r-- 1 root wheel 6184 Nov 11 2004 COPYRIGHT
drwxr-xr-x 2 root wheel 1024 Oct 8 2005 bin
drwxr-xr-x 5 root wheel 512 Oct 8 2005 boot
drwxr-xr-x 2 root wheel 512 Oct 8 2005 cdrom
lrwxr-xr-x 1 root wheel 10 Oct 8 2005 compat -> usr/compat
dr-xr-xr-x 4 root wheel 512 Jun 22 02:58 dev
drwxr-xr-x 2 root wheel 512 Oct 8 2005 dist
-rw------- 1 root wheel 4096 Jun 21 17:54 entropy
drwxr-xr-x 17 root wheel 2048 Jun 22 00:05 etc
lrwxrwxrwx 1 root wheel 9 Oct 8 2005 home -> /usr/home
drwxr-xr-x 3 root wheel 1024 Oct 8 2005 lib
drwxr-xr-x 2 root wheel 512 Oct 8 2005 libexec
drwxr-xr-x 2 root wheel 512 Nov 11 2004 mnt
dr-xr-xr-x 2 root wheel 512 Nov 11 2004 proc
drwxr-xr-x 2 root wheel 2560 Oct 8 2005 rescue
drwxr-xr-x 2 root wheel 512 Jun 25 00:32 root
drwxr-xr-x 2 root wheel 2560 Oct 8 2005 sbin
drwxr-xr-x 4 root wheel 1024 Oct 8 2005 stand
lrwxrwxrwx 1 root wheel 11 Oct 8 2005 sys -> usr/src/sys
drwxrwxrwt 3 root wheel 512 Jun 25 01:42 tmp
drwxr-xr-x 17 root wheel 512 Oct 8 2005 usr
drwxr-xr-x 24 root wheel 512 Jun 22 04:26 var