The library folders store settings, resources, and support files. There up to 6 "levels" of them:
- The user library, ~/Library, stores per-user settings etc.
- The local library, /Library, stores computer-wide settings etc. BTW, I call this the "local" library, because in NextStep it was /Local/Library, but you'll see all sorts of other names for it, such as the root library, computer library, ...
- The network library, /Network/Library would store settings shared by all computers in a network domain -- if a network domain admin set one up, which nobody does anymore
- The system library, /System/Library, stores the base settings, resources, etc that come with OS X. In theory, you shouldn't change anything in here.
Sandboxed apps don't have access to most of the user's home folder. They're mostly restricted to their own sandbox "container" (which is itself inside the user library), and as a result they get their own "private" libraries:
- Per-application sandbox libraries, ~/Library/Containers/<application-ID>/Data/Library, which will generally contain a few real folders like Preferences and Saved Application State, and also symbolic links to the regular-user-library versions of other folders (e.g. Fonts).
- Application group sandbox libraries, ~/Library/Group Containers/<application-group-ID>/Library, is used to store shared preferences, application support files, caches, etc between related groups of applications (from the same developer).
Now, as for the files inside the various library folders: Most of them are organized by type (e.g. there's a Preferences folder, a Caches folder, an Application Support folder, etc) with files/subfolders per application (or system component, or whatever). Some resource types are available to many or all programs (e.g. Fonts, Keychains, Services), so there's just a bunch of files there. However, some programs (mostly Apple-authored ones) are, um, egotistical enough to think they need their own top-level folder inside the library, so they go ahead and create one and store things in it.
As for the name "Library", I wouldn't read too much into it. It's basically a place to store things that programs need to get at, but that the user doesn't (generally) need to be explicitly aware of. Basically, things that the user never needs to double-click or use an open/save dialog to access. When you run Mail.app, you don't need to tell it to use the settings in ~/Library/Preferences/com.apple.mail.plist, or the cached mailbox contents in ~/Library/Mail, or the state information in ~/Library/Saved Application State/com.apple.mail.savedState.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…