はじめに
Linuxの標準的なディレクトリ構成について説明したいと思います。
FHS(Filesystem Hierarchy Standard)で規定されているディレクトリからピックアップして紹介しています。
実際にVagrantで作成したCentOS7で対象のディレクトリを確認しながら、それぞれのディレクトリの役割を理解していきます。
FHS
FHS(ファイルシステム階層標準: Filesystem Hierarchy Standard)とは、Linuxにおけるディレクトリ構成の標準を定めているものです。
FHSで規定されている構成はある程度採用されていますが、ディストリビューションごとで固有の構成も一部あります。
/
ルートディレクトリ
ディレクトリ構成の一番上になり、この配下に基本的な構成があります。
CentOSで確認すると以下のようになります。
$ ls /
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv swapfile sys tmp usr vagrant var
/bin
一般ユーザが利用できるコマンドが配置されているディレクトリ
ls
やcd
など基本的なコマンドがあります。
CentOSで確認すると以下のようになります。
$ ls /bin/
VGAuthService factor lexgrog nmcli setkeycodes systemd-sysv-convert
[ fallocate link nmtui setleds systemd-tmpfiles
addr2line false linux-boot-prober nmtui-connect setmetamode systemd-tty-ask-password-agent
alias fc linux32 nmtui-edit setpriv tabs
applydeltarpm fg linux64 nmtui-hostname setsid tac
apropos fgconsole ln nohup setterm tail
ar fgrep loadkeys nproc setup-nsssysinit tailf
arch file loadunimap nroff setup-nsssysinit.sh tar
as find locale nsenter setvtrgb taskset
aulast find-repos-of-install localectl nss-policy-check sexp-conv tbl
aulastlog findmnt localedef numfmt sftp teamd
:
:
:
/boot
LinuxカーネルやGRUBの設定ファイルなどLinuxの起動に必要なファイルが配置されているディレクトリ
CentOSで確認すると以下のようになります。
$ ls /boot/
System.map-3.10.0-1127.el7.x86_64 efi initramfs-3.10.0-1127.el7.x86_64.img vmlinuz-3.10.0-1127.el7.x86_64
config-3.10.0-1127.el7.x86_64 grub2 symvers-3.10.0-1127.el7.x86_64.gz
/dev
デバイスファイルが配置されているディレクトリ
CentOSで確認すると以下のようになります。
$ ls /dev/
autofs crash input network_latency random snd tty12 tty20 tty29 tty37 tty45 tty53 tty61 ttyS3 vcs4 vcsa6
block disk kmsg network_throughput raw stderr tty13 tty21 tty3 tty38 tty46 tty54 tty62 uhid vcs5 vfio
bsg fd log null rtc stdin tty14 tty22 tty30 tty39 tty47 tty55 tty63 uinput vcs6 vga_arbiter
btrfs-control full loop-control nvram rtc0 stdout tty15 tty23 tty31 tty4 tty48 tty56 tty7 urandom vcsa vhci
char fuse mapper oldmem sda tty tty16 tty24 tty32 tty40 tty49 tty57 tty8 usbmon0 vcsa1 vhost-net
console hpet mcelog port sda1 tty0 tty17 tty25 tty33 tty41 tty5 tty58 tty9 vcs vcsa2 zero
core hugepages mem ppp sg0 tty1 tty18 tty26 tty34 tty42 tty50 tty59 ttyS0 vcs1 vcsa3
cpu hwrng mqueue ptmx shm tty10 tty19 tty27 tty35 tty43 tty51 tty6 ttyS1 vcs2 vcsa4
cpu_dma_latency initctl net pts snapshot tty11 tty2 tty28 tty36 tty44 tty52 tty60 ttyS2 vcs3 vcsa5
/etc
設定ファイルが配置されているディレクトリ
hosts
ファイルやnetworks
ファイル、yumの設定ファイルなどがあります。
CentOSで確認すると以下のようになります。
$ ls /etc/
DIR_COLORS chrony.keys ethertypes hosts login.defs opt rc.local sasl2 sysconfig
DIR_COLORS.256color cifs-utils exports hosts.allow logrotate.conf os-release rc0.d securetty sysctl.conf
DIR_COLORS.lightbgcolor cron.d exports.d hosts.deny logrotate.d pam.d rc1.d security sysctl.d
GREP_COLORS cron.daily filesystems idmapd.conf machine-id passwd rc2.d selinux system-release
NetworkManager cron.deny firewalld init.d magic passwd- rc3.d services system-release-cpe
X11 cron.hourly fstab inittab man_db.conf pkcs11 rc4.d sestatus.conf systemd
adjtime cron.monthly fuse.conf inputrc mke2fs.conf pki rc5.d shadow tcsd.conf
aliases cron.weekly gcrypt iproute2 modprobe.d pm rc6.d shadow- terminfo
aliases.db crontab gnupg issue modules-load.d polkit-1 redhat-release shells tmpfiles.d
alternatives crypttab groff issue.net motd popt.d request-key.conf skel tuned
anacrontab csh.cshrc group krb5.conf mtab postfix request-key.d ssh udev
audisp csh.login group- krb5.conf.d my.cnf ppp resolv.conf ssl vconsole.conf
audit dbus-1 grub.d ld.so.cache my.cnf.d prelink.conf.d rpc statetab virc
bash_completion.d default grub2.cfg ld.so.conf netconfig printcap rpm statetab.d vmware-tools
bashrc depmod.d gshadow ld.so.conf.d networks profile rsyncd.conf subgid wpa_supplicant
binfmt.d dhcp gshadow- libaudit.conf nfs.conf profile.d rsyslog.conf subuid xdg
centos-release dracut.conf gss libnl nfsmount.conf protocols rsyslog.d sudo-ldap.conf xinetd.d
centos-release-upstream dracut.conf.d gssproxy libuser.conf nsswitch.conf python rwtab sudo.conf yum
chkconfig.d e2fsck.conf host.conf locale.conf nsswitch.conf.bak qemu-ga rwtab.d sudoers yum.conf
chrony.conf environment hostname localtime openldap rc.d samba sudoers.d yum.repos.d
/home
ユーザのホームディレクトリ
/home/ユーザ名
でユーザごとのホームディレクトリが作成されます。
CentOSで確認すると以下のようになります。
Vagrantで作成した環境なのでvagrantユーザしかいません。
$ ls /home/
vagrant
/lib
共有ライブラリとかカーネルモジュールが配置されるディレクトリ
CentOSで確認すると以下のようになります。
$ ls /lib/
NetworkManager debug firewalld games kbd locale modules os-release python2.7 sendmail sse2 systemd tuned yum-plugins
binfmt.d dracut firmware grub kernel modprobe.d modules-load.d polkit-1 rpm sendmail.postfix sysctl.d tmpfiles.d udev
/mnt
マウントポイントとなるディレクトリ
一時的なファイルシステムのマウントに利用します。
/opt
ソフトウェアパッケージのインストール先となるディレクトリ
/proc
プロセスを操作したり、システム情報を処理するための手段を提供している擬似ファイルシステムとなるディレクトリ
数値のディレクトリは、プロセスIDでディレクトリが作成されており、プロセスの情報が格納されています。ps
やtop
などのプロセスを表示するコマンドで参照されます。
アルファベットは全てファイルとなり、システムの状態を表示するfree
などで参照されます。
$ cat /proc/meminfo | grep MemTotal
MemTotal: 498684 kB
$ free
total used free shared buff/cache available
Mem: 498684 83704 322276 4548 92704 397320
Swap: 2097148 0 2097148
CentOSで確認すると以下のようになります。
$ ls /proc/
1 133 158 165 20 2559 288 35 44 617 9 cmdline execdomains kallsyms locks pagetypeinfo stat uptime
10 135 159 166 21 2560 289 367 45 618 94 consoles fb kcore mdstat partitions swaps version
11 136 16 17 22 2581 3 370 46 620 96 cpuinfo filesystems key-users meminfo sched_debug sys vmallocinfo
124 14 160 18 228 2585 33 4 47 7 acpi crypto fs keys misc schedstat sysrq-trigger vmstat
127 15 161 19 23 26 332 401 48 8 asound devices interrupts kmsg modules scsi sysvipc zoneinfo
129 155 162 1956 24 2605 34 423 5 837 buddyinfo diskstats iomem kpagecount mounts self timer_list
13 156 163 1972 25 264 343 424 6 847 bus dma ioports kpageflags mtrr slabinfo timer_stats
131 157 164 2 2556 283 348 43 61 848 cgroups driver irq loadavg net softirqs tty
/root
rootユーザのホームディレクトリ
CentOSで確認すると以下のようになります。
$ ls /root/
anaconda-ks.cfg original-ks.cfg
/sbin
システム管理者用のコマンドが配置されるディレクトリ
システム管理者用のコマンドは/sbinの他に、/usr/sbin、/usr/local/sbinに保管されます。/sbinには、/binのコマンドとシステムの起動や回復に必要なコマンドが含まれています。
CentOSで確認すると以下のようになります。
$ ls /sbin/
NetworkManager cracklib-check getsebool kpartx nl-pktloc-lookup rpc.rquotad tcpd
accessdb cracklib-format glibc_post_upgrade.x86_64 lchage nl-qdisc-add rpc.statd tcpdmatch
addgnupghome cracklib-packer groupadd ldattach nl-qdisc-delete rpcbind tcsd
addpart cracklib-unpacker groupdel ldconfig nl-qdisc-list rpcdebug telinit
adduser create-cracklib-dict groupmems lgroupadd nologin rpcinfo tracepath
agetty crond groupmod lgroupdel nstat rsyslogd tracepath6
alternatives ctrlaltdel grpck lgroupmod osd_login rtacct try-from
anacron ctstat grpconv lid ownership rtcwake tune2fs
applygnupgdefaults debugfs grpunconv lnewusers packer rtmon tuned
arpd delpart grub2-bios-setup lnstat pam_console_apply rtpr tuned-adm
arping depmod grub2-get-kernel-settings load_policy pam_tally2 rtstat udevadm
audispd devlink grub2-install logrotate pam_timestamp_check runlevel umount.nfs
auditctl dhclient grub2-macbless logsave parted runuser umount.nfs4
auditd dhclient-script grub2-mkconfig losetup partprobe safe_finger unix_chkpwd
augenrules dmfilemapd grub2-ofpathname lpasswd partx sasldblistusers2 unix_update
aureport dmidecode grub2-probe lshw pidof saslpasswd2 update-alternatives
ausearch dmsetup grub2-reboot lsmod ping6 sefcontext_compile update-pciids
authconfig dmstats grub2-rpm-sort lspci pivot_root selabel_digest useradd
:
:
:
/tmp
一時データが配置されるディレクトリ
CentOSで確認すると以下のようになります。
$ ls /tmp/
systemd-private-e66fdbef3115440aa5cb0dfd2d4b1ec6-chronyd.service-MSSEfv
/usr
ユーザで共有するデータを保持するディレクトリ
/usr配下は以下のような構成になります。
/usr
├── /bin
├── /include
├── /lib
├── /local
├── /sbin
└── /share
CentOSで確認すると以下のようになります。
$ ls /usr/
bin etc games include lib lib64 libexec local sbin share src tmp
/usr/bin
一般ユーザの利用するコマンドが格納されているディレクトリ
CentOSで確認すると以下のようになります。
$ ls /usr/bin/
VGAuthService factor lexgrog nmcli setkeycodes systemd-sysv-convert
[ fallocate link nmtui setleds systemd-tmpfiles
addr2line false linux-boot-prober nmtui-connect setmetamode systemd-tty-ask-password-agent
alias fc linux32 nmtui-edit setpriv tabs
applydeltarpm fg linux64 nmtui-hostname setsid tac
apropos fgconsole ln nohup setterm tail
ar fgrep loadkeys nproc setup-nsssysinit tailf
arch file loadunimap nroff setup-nsssysinit.sh tar
as find locale nsenter setvtrgb taskset
aulast find-repos-of-install localectl nss-policy-check sexp-conv tbl
aulastlog findmnt localedef numfmt sftp teamd
ausyscall fipscheck logger objcopy sg teamdctl
auvirt fipshmac login objdump sg_compare_and_write teamnl
awk firewall-cmd loginctl od sg_copy_results tee
base64 firewall-offline-cmd logname oldfind sg_dd test
basename flock look open sg_decode_sense testgdbm
bash fmt ls openssl sg_emc_trespass tic
bashbug fold lsattr openvt sg_format timedatectl
bashbug-64 free lsblk os-prober sg_get_config timeout
bg fusermount lscpu p11-kit sg_get_lba_status tload
bond2team gapplication lsinitrd package-cleanup sg_ident tmon
bootctl gawk lsipc passwd sg_inq toe
bunzip2 gdbus lslocks paste sg_logs top
busctl gencat lslogins pathchk sg_luns touch
bzcat genl-ctrl-list lsmem pchrt sg_map tput
bzcmp geqn lsns pflags sg_map26 tr
:
:
:
/usr/include
Cプログラムにincludeされるヘッダファイルが配置されているディレクトリ
CentOSで確認すると以下のようになります。
$ ls /usr/include
python2.7
/usr/lib
共有ライブラリが配置されているディレクトリ
CentOSで確認すると以下のようになります。
$ ls /usr/lib
NetworkManager debug firewalld games kbd locale modules os-release python2.7 sendmail sse2 systemd tuned yum-plugins
binfmt.d dracut firmware grub kernel modprobe.d modules-load.d polkit-1 rpm sendmail.postfix sysctl.d tmpfiles.d udev
/usr/local
ローカル用ファイルのトップディレクトリ
ソフトウェアをローカルにインストールするときにシステム管理者が使用します。
CentOSで確認すると以下のようになります。
$ ls /usr/local/
bin etc games include lib lib64 libexec sbin share src
/usr/sbin
システム管理者が利用する必須ではないコマンドが配置されているディレクトリ
CentOSで確認すると以下のようになります。
$ ls /usr/sbin/
NetworkManager cracklib-check getsebool kpartx nl-pktloc-lookup rpc.rquotad tcpd
accessdb cracklib-format glibc_post_upgrade.x86_64 lchage nl-qdisc-add rpc.statd tcpdmatch
addgnupghome cracklib-packer groupadd ldattach nl-qdisc-delete rpcbind tcsd
addpart cracklib-unpacker groupdel ldconfig nl-qdisc-list rpcdebug telinit
adduser create-cracklib-dict groupmems lgroupadd nologin rpcinfo tracepath
agetty crond groupmod lgroupdel nstat rsyslogd tracepath6
alternatives ctrlaltdel grpck lgroupmod osd_login rtacct try-from
anacron ctstat grpconv lid ownership rtcwake tune2fs
applygnupgdefaults debugfs grpunconv lnewusers packer rtmon tuned
arpd delpart grub2-bios-setup lnstat pam_console_apply rtpr tuned-adm
arping depmod grub2-get-kernel-settings load_policy pam_tally2 rtstat udevadm
audispd devlink grub2-install logrotate pam_timestamp_check runlevel umount.nfs
auditctl dhclient grub2-macbless logsave parted runuser umount.nfs4
auditd dhclient-script grub2-mkconfig losetup partprobe safe_finger unix_chkpwd
augenrules dmfilemapd grub2-ofpathname lpasswd partx sasldblistusers2 unix_update
aureport dmidecode grub2-probe lshw pidof saslpasswd2 update-alternatives
ausearch dmsetup grub2-reboot lsmod ping6 sefcontext_compile update-pciids
authconfig dmstats grub2-rpm-sort lspci pivot_root selabel_digest useradd
authconfig-tui dracut grub2-set-default luseradd postalias selabel_lookup userdel
autrace dumpe2fs grub2-setpassword luserdel postcat selabel_lookup_best_match usermod
avcstat e2freefrag grub2-sparc64-setup lusermod postconf selabel_partial_match usernetctl
badblocks e2fsck grubby matchpathcon postdrop selinux_restorecon vigr
biosdecode e2image gssproxy mkdict postfix selinuxconlist vipw
:
:
:
/usr/share
アーキテクチャに依存しないデータファイルが配置されているディレクトリ
CentOSで確認すると以下のようになります。
$ ls /usr/share
X11 backgrounds dict gcc-4.8.2 glib-2.0 i18n licenses mime-info p11-kit redhat-release terminfo zoneinfo
aclocal bash-completion doc gcc-4.8.5 gnome icons locale misc pixmaps selinux themes zsh
applications centos-release empty gdb gnupg idl lua mysql pkgconfig sounds tuned
augeas cracklib file gettext groff info magic omf pki systemd xsessions
authconfig dbus-1 firewalld gettext-0.19.8 grub keyutils man open-vm-tools polkit-1 systemtap yum-cli
awk desktop-directories games ghostscript hwdata libdrm mime os-prober qemu-kvm tabset yum-plugins
/var
ログやキャッシュなどの頻繁に書き換えられるデータが配置されているディレクトリ
CentOSで確認すると以下のようになります。
$ ls /var/
adm cache db empty games gopher kerberos lib local lock log mail nis opt preserve run spool tmp yp
/var/cache
キャッシュファイルが配置されているディレクトリ
CentOSで確認すると以下のようになります。
$ ls /var/cache/
ldconfig man yum
/var/log
ログファイルが配置されているディレクトリ
CentOSで確認すると以下のようになります。
$ ls /var/log/
anaconda audit btmp chrony cron dmesg grubby_prune_debug lastlog maillog messages qemu-ga rhsm samba secure spooler tallylog tuned wtmp