
Linuxでディレクトリやファイルの一覧を表示します。
記事の目次
ディレクトリとファイルの一覧を表示する!(ls -l)
ファイルの一覧をファイル属性とともに表示する最も一般的な使用方法です。
1 2 3 4 5 6 7 8 9 10 11 12 | $ ls -l /etc total 1324 drwxr-xr-x. 3 root root 28 Nov 3 07:20 accountsservice -rw-r--r--. 1 root root 16 Nov 3 07:28 adjtime -rw-r--r--. 1 root root 1529 Jun 23 2020 aliases drwxr-xr-x. 3 root root 65 Dec 10 12:00 alsa drwxr-xr-x. 2 root root 4096 Nov 3 07:23 alternatives -rw-r--r--. 1 root root 541 Nov 1 04:55 anacrontab -rw-r--r--. 1 root root 769 Aug 29 2021 appstream.conf -rw-r--r--. 1 root root 55 Nov 1 04:44 asound.conf -rw-r--r--. 1 root root 1 Oct 26 11:53 at.deny ... |
隠し属性のディレクトリとファイルの情報も表示する!(ls -la)
「.」から始まるファイルも表示します。
1 2 3 4 5 6 7 8 9 10 | drwxr-xr-x. 132 root root 8192 Jan 12 21:10 . dr-xr-xr-x. 18 root root 235 Nov 3 07:46 .. drwxr-xr-x. 3 root root 28 Nov 3 07:20 accountsservice -rw-r--r--. 1 root root 16 Nov 3 07:28 adjtime -rw-r--r--. 1 root root 1529 Jun 23 2020 aliases drwxr-xr-x. 3 root root 65 Dec 10 12:00 alsa drwxr-xr-x. 2 root root 4096 Nov 3 07:23 alternatives -rw-r--r--. 1 root root 541 Nov 1 04:55 anacrontab -rw-r--r--. 1 root root 769 Aug 29 2021 appstream.conf ... |
ディレクトリの情報を表示する!(ls -ld)
指定したディレクトリの情報のみを表示します。
1 2 | $ ls -ld /etc drwxr-xr-x. 132 root root 8192 Jan 12 21:10 /etc |
再帰的にディレクトリとファイルの一覧を表示する!(ls -lR)
指定したディレクトリ配下のすべてのディレクトリとファイルを表示します。
1 2 3 4 5 6 7 8 9 10 11 12 | $ ls -lR /etc /etc: total 1324 drwxr-xr-x. 3 root root 28 Nov 3 07:20 accountsservice -rw-r--r--. 1 root root 16 Nov 3 07:28 adjtime -rw-r--r--. 1 root root 1529 Jun 23 2020 aliases drwxr-xr-x. 3 root root 65 Dec 10 12:00 alsa drwxr-xr-x. 2 root root 4096 Nov 3 07:23 alternatives -rw-r--r--. 1 root root 541 Nov 1 04:55 anacrontab -rw-r--r--. 1 root root 769 Aug 29 2021 appstream.conf -rw-r--r--. 1 root root 55 Nov 1 04:44 asound.conf ... |
指定したディレクトリ配下のディレクトリのフルパスを表示する!(find -type d)
ディレクトリ名のみでなくフルパスで表示したいときは、findコマンドを使用します。「-maxdepth」オプションで表示する階層を指定できます。
1 2 3 4 5 6 7 8 | $ find /etc -maxdepth 1 -type d /etc /etc/lvm /etc/dnf /etc/fonts /etc/crypto-policies /etc/skel ... |
指定したディレクトリ配下のファイルのフルパスを表示する!!(find -type f)
ファイル名のみでなくフルパスで表示したいときは、findコマンドを使用します。「-maxdepth」オプションで表示する階層を指定できます。
1 2 3 4 5 6 7 | $ find /etc -maxdepth 1 -type f /etc/fstab /etc/crypttab /etc/resolv.conf /etc/fuse.conf /etc/sysctl.conf ... |
おわりに
ディレクトリやファイルの一覧は、lsコマンドあるいはfindコマンドを使用して表示します。
関連記事
関連書籍(Amazon)