- Linux directory structure:/etc explained
- The history of /etc folder in Linux/Unix
- /etc folder content can be divided into following groups
- Table files (The ***TAB) in /etc folder in Linux
- Running Configuration files(rc) in /etc folder
- Config files in /etc folder
- Deny/Allow files in /etc folder
- Directories in /etc folder
- Ok that’s enough, How many folders and files I should learn like this?
- Other files in /etc folder
- Linux Directory Structure Explained for Beginners
- Linux directory structure
- / – The root directory
- /bin – Binaries
- /dev – Device files
- /etc – Configuration files
- /usr – User binaries and program data
- /home – User personal data
- /lib – Shared libraries
- /sbin – System binaries
- /tmp – Temporary files
- /var – Variable data files
- /boot – Boot files
- /proc – Process and kernel files
- /opt – Optional software
- /root – The home directory of the root
- /media – Mount point for removable media
- /mnt – Mount directory
- /srv – Service data
Linux directory structure:/etc explained
ETC is a folder which contain all your system configuration files in it. Then why the etc name?
“etc” is an English word which means etcetera i.e in layman words it is “and so on”. The naming convention of this folder is having some interesting history.
The history of /etc folder in Linux/Unix
In initial days of UNIX OS development there is a folder for each type of data like /bin folder for all your executable binaries
/boot folder for all booting related information.
/dev folder for all hardware devices attached to machine.
But people encountered a situation to keep some files which can be a config file or a data file or a socket file or some other files. So they implemented a folder to keep all these files in it and they named it as /etc(As said earlier etcetera). As time passed the meaning of this folder has changed but not the name “etc”. Now /etc folder means a central location for all your configuration files are located and this can be treated as nerve centre of your Linux/Unix machine.
Coming back to our /etc folder explanation, one post on this is not sufficient and the number files/folder in this directory will depend on the applications you install in it. Below are some list of files/folders commonly installed in most of Linux/Unix machines. I thought of posting this long time back almost three years back along with /bin, /boot, /dev but did not find a good way to approach this folder as number of files/folders are huge in number. Today I come up with a solution which I felt it’s bit easy for people who are new to Linux can understand without much fuss.
/etc folder content can be divided into following groups
Please note that this is a special post which I will modify continuously based on readers inputs.
Table files (The ***TAB) in /etc folder in Linux
These are the files which end with tab or start with tab(which is short form of table) such as crontab, fstab, inittab etc. These files main intention is to keep a table of content for their corresponding settings. Below are some of the files which fall under this category.
/etc/crontab –For doing scheduling
/etc/inittab –Contains what are the run-levels, what system have to do at each run-level and default run-level info.
/etc/fstab –Contains file system mounting information and we can edit this file to mount file system permanently and delete mount points.
/etc/mtab –Contains all mounted device status like what devices are mounted, where they mounted and properties of mount points.
/etc/quotatab –Quota related table for mentioning different qutos
/etc/rwtab –When your computer comes back up, the root and any other system partitions will be mounted read-only. All the files and directories listed in /etc/rwtab will be mounted read-write on a tmpfs file system. You can add additional files and directories to rwtab to make them writeable after reboot.
Some other table files are as below.
Running Configuration files(rc) in /etc folder
These are again a type of config files which will force a service to start/stop, for a user to use specific environment etc.
/etc/bash.bashrc –System wide bash shell running configuration file.
/etc/inputrc — Global inputrc for libreadline
/etc/nanorc –Nano editor running configurations
rc0.d, rc1.d, rc2.d, rc3.d, rc4.d, rc5.d, rc6.d, rcS.d –running configurations like what services has to start and stop for each run level from zero to six. If you observe rcS.d this folder is same as rc1.d folder which means Single run level.
/etc/rc.local –This file contains commands which need to be executed after completing booting. we can edit this file and keep the commands which we want to execute at the time of booting.
vimrc –VIEW Improved editor system level configuration is stored here.
wgetrc –wget related running configurations.
Other RC files:
Config files in /etc folder
These are the main configuration files for many applications installed in your machine. These files are text files which can be edited with editors like VI editor so that applications works according to your requirement.
/etc/asound.conf –Configuration file for your speakers and audio devices.
/etc/dnsmasq.conf –DNS client related configuration file
/etc/exports –NFS share configuration file. In this file we will share our local folder to a specific IP address or network with different.
/etc/grub.conf –Main configuration file for grub boot loader
/etc/shadow –User login password hashes are stored here.
/etc/group –User groups information such as which user belongs to which group, what is GID etc.
/etc/passwd –User configurations such as user login name, shell, UID and GID are stored here.
/etc/my.cnf –Mysql configuration file.
/etc/mdadm.conf –Raid configuration file.
/etc/hosts –Hosts to IP address mapping file, This is mother of all name to IP matching files.
/etc/resolv.conf –DNS and domain client configuration file. With out proper DNS server in this file, we can not access internet.
/etc/rsyslog.conf –Remote syslog server configuration file.
/etc/securetty –Root login control file.
/etc/sestatus.conf –SELinux configuration file.
Other configuration files are as below
Deny/Allow files in /etc folder
These are the files which contain what users are allowed/denied for particular service, what IP address are allowed/denied to access our services etc.
/etc/at.deny –Keep users in this file to deny at jobs execution.
/etc/at.allow –Keep users in this file to allow at jobs execution.
/etc/hosts.allow –TCP wrapper files for allowing services for a particular host/network.
/etc/hosts.deny –TCP wrapper files for allowing services for a particular host/network.
Directories in /etc folder
abrt/ -Useful for automatic bug reporting tool used by your vendor for reporting bugs.
acpi/ -The Advanced Configuration and Power Interface (ACPI) specification provides an open standard for device configuration and power management. This folder contain configuration files related to ACPI
alsa/ -The Advanced Linux Sound Architecture (ALSA) provides audio and MIDI functionality to the Linux operating system.
alternatives/ –A required folder/command to change default applications. Suppose you want to use emacs editor instead of vi editor then this folder contain those details.
cron.d/, cron.daily/, cron.deny, cron.hourly/, cron.monthly/, crontab, cron.weekly/ –Crontab related files and folders for effective management for scheduling in Linux.
default/ –Some of the common configuration files are located here.
Ok that’s enough, How many folders and files I should learn like this?
I want easiest and detailed way to learn this stuff. Is there any way to do that?
Yes, man pages will come for your rescue. Suppose you want to know more about passwd file then execute following command
aliases and aliases.db — Files which are related to Sendmail and postfix mail servers to mention alias
Other folders:
Other files in /etc folder
/etc/issue –This is the file which is displayed at every login session.
/etc/motd –Message of the day file which is shown after you login to any machine.
/etc/services –Available services and their corresponding port information is stored here
/etc/protocols –Available network protocols such as IGP, ISIS etc.
/etc/redhat-release –If yu find this file, that indicates you are working on Redhat based machines and it contain OS version and release details.
/etc/debian_version –If yu find this file, that indicates you are working on Debian based machines and it contain OS version and release details.
/etc/shells –All available/installed shells in your machine.
/etc/sudoers –Main sudo configuration file.
In our next post we will see /home directory.
Источник
Linux Directory Structure Explained for Beginners
If you are even faintly acquainted with Linux, you might have heard the terms root, lib, bin etc. These are various directories that you’ll find in all Linux distributions.
In fact, the Linux Foundation maintains a Filesystem Hierarchy Standard (FHS). This FHS defines the directory structure and the content/purpose of the directories in Linux distributions. Thanks to this FHS, you’ll find the same directory structure in (almost) all the Linux distributions.
Let’s see the Linux directory structure in detail.
Linux directory structure
Linux is based on UNIX and hence it borrows its filesystem hierarchy from UNIX. You’ll fine a similar directory structure in UNIX-like operating systems such as BSD and macOS. I’ll be using the term Linux hereafter instead of UNIX though.
/ – The root directory
Everything, all the files and directories, in Linux are located under ‘root’ represented by ‘/’. If you look at the directory structure, you’ll realize that it is similar to a plant’s root.
Linux Directory Structure
Since all other directories or files are descended from root, the absolute path of any file is traversed through root. For example, if you have a file in /home/user/documents, you can guess that the directory structure goes from root->home->user->documents.
The cruel rm -rf / joke
You may have come across some jokes on internet that mentions “rm -rf /” . rm command is used for removing files and directories in Linux.
With rm -rf /, you ask your system to forcefully and recursively delete the contents of the root directory. Since root directory has everything underneath, you end up deleting everything and your Linux system just vanishes (theoretically).
Most Linux distribution won’t run this command unless you provide –no-preserve-root. In any case, don’t be curious to run this command. Curiosity killed the cat, after all.
/bin – Binaries
The ‘/bin’ directly contains the executable files of many basic shell commands like ls, cp, cd etc. Mostly the programs are in binary format here and accessible by all the users in the Linux system.
/dev – Device files
This directory only contains special files, including those relating to the devices. These are virtual files, not physically on the disk.
Some interesting examples of these files are:
- /dev/null: can be sent to destroy any file or string
- /dev/zero: contains an infinite sequence of 0
- /dev/random: contains an infinite sequence of random values
/etc – Configuration files
The /etc directory contains the core configuration files of the system, use primarily by the administrator and services, such as the password file and networking files.
If you need to make changes in system configuration (for example changing the hostname), this is where you’ll find the respective files.
/usr – User binaries and program data
in ‘/usr’ go all the executable files, libraries, source of most of the system programs. For this reason, most of the files contained therein is readonly (for the normal user)
- ‘/usr/bin’ contains basic user commands
- ‘/usr/sbin’ contains additional commands for the administrator
- ‘/usr/lib’ contains the system libraries
- ‘/usr/share’ contains documentation or common to all libraries, for example ‘/usr/share/man’ contains the text of the manpage
/home – User personal data
Home directory contains personal directories for the users. The home directory contains the user data and user-specific configuration files. As a user, you’ll put your personal files, notes, programs etc in your home directory.
When you create a user on your Linux system, it’s a general practice to create a home directory for the user. Suppose your Linux system has two users, Alice and Bob. They’ll have a home directory of their own at locations /home/alice and /home/bob.
Do note that Bob won’t have access to /home/alice and vice versa. That makes sense because only the user should have access to his/her home. You may read about file permissions in Linux to know more on this topic.
/lib – Shared libraries
Libraries are basically codes that can be used by the executable binaries. The /lib directory holds the libraries needed by the binaries in /bin and /sbin directories.
Libraries needed by the binaries in the /usr/bin and /usr/sbin are located in the directory /usr/lib.
/sbin – System binaries
This is similar to the /bin directory. The only difference is that is contains the binaries that can only be run by root or a sudo user. You can think of the ‘s’ in ‘sbin’ as super or sudo.
/tmp – Temporary files
As the name suggests, this directory holds temporary files. Many applications use this directory to store temporary files. Even you can use directory to store temporary files.
But do note that the contains of the /tmp directories are deleted when your system restarts. Some Linux system also delete files old files automatically so don’ store anything important here.
/var – Variable data files
Var, short for variable, is where programs store runtime information like system logging, user tracking, caches, and other files that system programs create and manage.
The files stored here are NOT cleaned automatically and hence it provides a good place for system administrators to look for information about their system behavior. For example, if you want to check the login history in your Linux system, just check the content of the file in /var/log/wtmp.
/boot – Boot files
The ‘/boot’ directory contains the files of the kernel and boot image, in addition to LILO and Grub. It is often advisable that the directory resides in a partition at the beginning of the disc.
/proc – Process and kernel files
The ‘/proc’ directory contains the information about currently running processes and kernel parameters. The content of the proc directory is used by a number of tools to get runtime system information.
For example, if you want to check processor information in Linux, you can simply refer to the file /proc/cpuinfo. You want to check memory usage of your Linux system, just look at the content of /proc/meminfo file.
/opt – Optional software
Traditionally, the /opt directory is used for installing/storing the files of third-party applications that are not available from the distribution’s repository.
The normal practice is to keep the software code in opt and then link the binary file in the /bin directory so that all the users can run it.
/root – The home directory of the root
There is /root directory as well and it works as the home directory of the root user. So instead of /home/root, the home of root is located at /root. Do not confuse it with the root directory (/).
/media – Mount point for removable media
When you connect a removable media such as USB disk, SD card or DVD, a directory is automatically created under the /media directory for them. You can access the content of the removable media from this directory.
/mnt – Mount directory
This is similar to the /media directory but instead of automatically mounting the removable media, mnt is used by system administrators to manually mount a filesystem.
/srv – Service data
The /srv directory contains data for services provided by the system. For example, if you run a HTTP server, it’s a good practice to store the website data in the /srv directory.
I think this much information is enough for you to understand the Linux directory structure and its usage.
In the end, if you want, you can download and save this image for quick reference to the directory structure in Linux systems.
Linux System Directories
Источник