LLI Wiki — My Digital Knowledge Base

Linux directory structure and bash startup files

Role of the main Linux directories, common configuration files and the order in which bash reads its startup files.

The role of the main Linux directories, the most common configuration files, and the order in which bash reads its startup files.

Main directories

Directory Contents
/bin Basic commands available even before all file systems are mounted (cat, df, tar...)
/boot Boot files, including the kernel (vmlinuz)
/dev Device files (disks, terminals, /dev/null...)
/etc Configuration files of applications and startup scripts
/home Home directories of users
/lib Shared libraries and kernel modules needed at boot
/media Mount points for removable media (USB key, CD)
/mnt Temporary mount point
/opt Third-party software
/proc Virtual file system describing processes and the kernel
/root Home directory of the root user
/run Runtime data created since boot
/sbin System administration commands (fdisk, reboot...)
/srv Data of the services hosted on the system
/sys Virtual file system describing devices
/tmp Temporary files, accessible to all users
/usr User programs, libraries and documentation
/var Variable data: logs, spools, mail queues, caches

Common configuration files

File Purpose
/etc/fstab File systems mounted at boot
/etc/hosts Mapping between local host names and IP addresses
/etc/resolv.conf DNS servers in use
/etc/passwd User accounts
/etc/shadow Encrypted passwords of the accounts
/etc/group Groups
/etc/profile bash configuration shared by login shells
/etc/bashrc Default bash settings and aliases (depends on the distribution)

Order of bash startup files

For a login shell, bash reads /etc/profile, then the first file found among ~/.bash_profile, ~/.bash_login and ~/.profile. On exit, ~/.bash_logout is read.

For an interactive non-login shell (for example a terminal opened in a graphical session), bash reads ~/.bashrc. Login files often source ~/.bashrc as well.

Useful commands:

echo $0          # current shell
cat /etc/shells  # available shells

Personal scripts

Personal scripts can be placed in ~/.local/bin (user) or /usr/local/bin (system-wide). For the user directory to be found, add it to PATH in ~/.bashrc:

export PATH="$HOME/.local/bin:$PATH"

For more detail on the bash startup order, see The Geek Stuff.

Mastodon LLIMastodon SocialFosstodon