macOS – Learning About Noteworthy Folders in Apple’s Operating System

macos

I just got my first Mac (a MacBook Pro) last Sunday and I am LOVING everything about it so far! But, I am a little confused about the folders in OS X.

Please go through the folders I should know about, and the folders I shouldn't worry about (or should stay away from). I have a little Linux knowledge to go off of, but things are still different enough that I'm disoriented.

I'm running the latest, at this time of writing, version of OS X 10.6.5 Snow Leopard. But if any folders have changed over the past few versions, please note them! 🙂

Best Answer

I’m going to resume them by memory, so future edits will probably fix all the mess I might type now. :)

The file structure of OS X resembles a typical Unix/Linux operating system (which in fact is the root of it all), albeit with some “Apple” differences. Some of those differences have aliases to keep the “unix” heart happy, but some are simply modified to be used as such.

In short here are the major “folders” in your file system:

  1. /Applications : This one is self explanatory, all your Mac’s apps should go there (unless you have an app that you want to be visible for only one user…). Normal users can read, “admins” can also drop things in there.
  2. /Developer : if you install Xcode and the developer libraries, this folder will magically bring the unicorns for developing awesome Cocoa apps, iOS apps and dashboard widgets among other things. Otherwise the folder doesn’t even exist.
  3. /Library : Shared libraries, and files necessary for OS X to actually function. Preferences, settings, app stuff, browser plug-ins (or more specifically, how to get rid of Adobe’s Flash) ;) You usually don’t tamper around here, but it’s normal if you want to clear some Apps settings, fix something, remove or install browser plugins, extensions, etc. Sometimes you will venture into /Library. Handle with care and always backup before breaking stuff here. It would be hard to destroy an OS X install by tampering /Library, but it’s possible…
  4. /Network : All network libraries, servers, devices, etc. You shouldn’t be here unless you know what you’re doing and want to bypass GUI utilities. In almost 7 years of OS X, I’ve never touched this directory.
  5. /System : Everything that OS X needs to properly function is here. I’d say that you shouldn’t touch anything or problems will arise.
  6. /Users : This is the equivalent to Unix and Linux's /home directory. And here you will have sub directories for each of your users: /Users/John, /Users/Doe, etc. Inside your home folder you will have a “similar” structure. See later for more /Users’ love.
  7. /Volumes: Mounted stuff/devices and volumes, real or virtual (think of CDs, DMGs, samba shares, etc), get their own “directory” here. So if you mount a smb share called MyShare, you can ‘cd /Volumes/MyShare’ to access it from the Command Line. The Finder will happily hide this from you (unless you set it to show invisible files I think).
  8. /bin : What else can be said about bin that you don’t know already from your Linux knowledge. Same thing. If you install ‘git’ for example, it will go to /usr/local/git… so you get the idea. Obviously all the essential common binaries are here too. Think the command ‘ls’… it’s there, in all its glory.
  9. /etc : Oh the great “etcetera”… Just like any other Unix, local system configs and… etcetera. It’s “similar” to any other unix, with some Apples. But the purpose is the same and some of the files (rc.local for example) exist. Go ahead and take a look, but if you break it, you have to pay for it. (OS X uses ‘launchd’ to launch stuff, so google for that if you want to -for example- start a subversion daemon at startup, forget all you knew about runlevels). Otherwise, get insurance between tweaking too much in there, because it’s not covered by Apple Stack’s Exchange damaging policy ;)
  10. /dev : honoring it’s “unix” background, the device files representing peripherals are here. Who touches this anyway…
  11. /usr : I googled for a good description of this and came up with a clever one:

"Second major hierarchy, includes subdirectories that contain information, configuration files, and other essentials used by the operating system”

  1. /sbin : Also coming from the Unix nature of OS X, the system binaries, and administration utilities. These are not the droids you’re looking for, move along, move along.
  2. /tmp : The one and only temp directory! Batteries not included. Note that this is not the “trash”. This is the real Unix temp. Unless you like being around waste, you shouldn’t have to wander around there. Cron jobs will keep it clean (tho it doesn’t hurt to restart your OS X every now and then).
  3. /var : Var is for variable data. Logs, and stuff that will “vary” during the operating system operation. You rarely walk through these rapidly changing places, but sometimes you have to hunt for logs or errors. Bring and umbrella there, it changes very often…

Ok and what’s with this /Users thing?

The Users folder contains your ‘home’. You have easy to identify folders (i.e.: if you can’t identify what Music, Documents, Movies, Downloads, Desktop and Pictures are for, then the problem might lie elsewhere), but at the same time, there are notable “duplicates”. What? Yes. You have a Library and an Applications folder here too!

I believe you’re already guessing what is all this about. Yes, all application settings that are for the user only will go in here (to ~/Library). That means that, although OS X will first look at /Library, if you install a (for example) browser plug-in in your ~/Library (instead of /Library), it will be found, but only by you. My ~/Applications folder is barely empty, it contains some Steam (games) in there, apparently they go there and not /Applications. (I just checked, i didn’t know that, so go figure how often I use my home’s App folder).

update: Apparently this Application folder in your home directory doesn’t exist by default, but you can always create it and drop applications you want to keep for yourself. If you have no permissions to install stuff in /Applications, you can always use a private copy of an app in your ~/Applications folder.

Things not mentioned above that you might have

  1. /opt : (tional). As its name implies, it’s sometimes used by daemons as a place to store suff (but it’s usually optional, so you can put those things elsewhere). I remember that when running Subversion daemons, I had that directory and the repos would go to /opt/svn/repositories, but that was just me… never trust me.
  2. /private : The best way to understand why we have this strange directory here, is to simply go ahead and read it from an expert (or read it directly from the question in Apple SE.):

…and I quote:

"AIUI it's a holdover from NextStep (which OS X is based on), and NextStep did it to support NetBooting. The idea was that you could boot from a network-hosted volume (probably read-only, and certainly shared with other computers), and early in the boot process mount a local (writable) volume on /private; as g mentioned, this allowed runtime-modification of /var and /tmp, as well as per-computer settings in /etc.

This isn't needed anymore, as Apple's current NetBoot system uses a shadow disk image to store changes anywhere on the boot volume. But some programs/docs/etc now assume the files live under /private, so it'd be too much trouble to switch them back…”

So there it is, this is more or less the OS X’s file hierarchy. Don’t drink and drive around it, it’s more fragile than what it looks.