Linux/Unixでのファイル・ディレクトリのサイズ・権限・更新日時を確認するコマンドである、
「ls」コマンドについて備忘録を兼ねて記事します。
目次
lsコマンドとは?
lsコマンドと「list segments」の意味で、ファイルやディレクトリの情報を表示するコマンドです。
CUIで操作するために必須のコマンドですので必ず使いこなせるようになりましょう。
なおlsコマンドはUnix/Linux・MacOSでも使用できるコマンドになります。
ですがlsコマンドのオプションに違いがありますので注意してください。
lsコマンドの使用方法
ls [オプション] [ファイル名 or ディレクトリ名]
lsコマンドのオプション
[table id=58 column_widths=20%|80% /]
lsコマンドの使用例
カレントディレクトリ内のファイル・ディレクトリを確認。
$ ls
test001 test002 test003 test004
ディレクト内のファイル・ディレクトリの詳細情報を確認します。
$ ls -l test001
total 3776
-rw-rw-r-- 1 test001 test001 3856854 Feb 17 21:37 test005
-rw-rw-r-- 1 test001 test001 1225 Feb 17 21:37 test006
カレントディレクト内のファイル・ディレクトリの詳細情報を確認します。
$ ls -l
total 3784
drwxrwxr-x 2 test001 test001 4096 Feb 17 21:37 test001
-rw-rw-r-- 1 test001 test001 3856854 Feb 17 21:35 test002
-rw-rw-r-- 1 test001 test001 1225 Feb 17 21:36 test003
drwxrwxr-x 2 test001 test001 4096 Feb 17 21:35 test004
カレントディレクト内のファイル・ディレクトリの詳細情報を更新が古い順に表示して確認します。
$ ls -ltr
total 3784
drwxrwxr-x 2 test001 test001 4096 Feb 17 21:35 test004
-rw-rw-r-- 1 test001 test001 3856854 Feb 17 21:35 test002
-rw-rw-r-- 1 test001 test001 1225 Feb 17 21:36 test003
drwxrwxr-x 2 test001 test001 4096 Feb 17 21:37 test001
カレントディレクト内のファイル・ディレクトリの詳細情報をサイズが見やすい表示形式で確認。
$ ls -ltr
total 3784
drwxrwxr-x 2 test001 test001 4096 Feb 17 21:35 test004
-rw-rw-r-- 1 test001 test001 3856854 Feb 17 21:35 test002
-rw-rw-r-- 1 test001 test001 1225 Feb 17 21:36 test003
drwxrwxr-x 2 test001 test001 4096 Feb 17 21:37 test001
カレントディレクト内のファイル・ディレクトリの詳細情報を確認します。
その際にディレクトを再帰的に確認する。
$ ls -lR
.:
total 3784
drwxrwxr-x 2 test001 test001 4096 Feb 17 21:37 test001
-rw-rw-r-- 1 test001 test001 3856854 Feb 17 21:35 test002
-rw-rw-r-- 1 test001 test001 1225 Feb 17 21:36 test003
drwxrwxr-x 2 test001 test001 4096 Feb 17 21:35 test004
./test001:
total 3776
-rw-rw-r-- 1 test001 test001 3856854 Feb 17 21:37 test005
-rw-rw-r-- 1 test001 test001 1225 Feb 17 21:37 test006
./test004:
total 0

[改訂第3版]Linuxコマンドポケットリファレンスposted with ヨメレバ
沓名 亮典 技術評論社 2015-06-05