Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Before today, I've used Terminal to a limited extent of moving in and out of directories, changing the dates of files using the touch command, but had realised the full extent of Terminal after installing a fun script in Mac and having to chmod 755 the file to make it executable afterwards.

I'd like to know what is /usr/local/bin though. /usr/, I assume is the user of the computer. I'm not sure why /local/ is there though. It obviously stands for the local computer, but since it's on the computer (Or a server), would it really be necessary? Wouldn't /usr/bin be fine?

And what is /bin? Why is this area usually used for installing scripts into Terminal?

share|improve this question

7 Answers 7

up vote 30 down vote accepted

/usr/local/bin is for programs that a normal user may run.

  • The /usr/local hierarchy is for use by the system administrator when installing software locally.
  • It needs to be safe from being overwritten when the system software is updated.
  • It may be used for programs and data that are shareable amongst a group of hosts, but not found in /usr.
  • Locally installed software must be placed within /usr/local rather than /usr unless it is being installed to replace or upgrade software in /usr.

Source: Filesystem Hierarchy Standard

To understand the filesystem hierarchy better, visit: http://www.pathname.com/fhs/

You might find this article interesting: Use and Abuse of /usr/local/bin

share|improve this answer

/usr/, I assume is the user of the computer.

Originally, yes, it did refer to the system's users. Before AT&T changed the default location for user folders to /home in System V Release 4 (SVR4), the default was /usr. That is to say, your $HOME might have been /usr/jfw on a System III box. (Other schemes also existed in the past.) /usr also contained, then as now, /usr/bin, /usr/lib, etc. Experience showed that segregating the home directories was good system management practice, so the default was changed, leaving behind everything we now think of as belonging in /usr.

The best reason for /usr to still be called that is that it contains "user files", which is to say things that don't need to be available until the system has booted up far enough to support normal use by users.

There's a clear dividing line: a Unix box is supposed to be able to boot up into single-user mode without needing any file under /usr. You can try it on your Mac, if you like: hold Cmd-S while it boots, and you will land in single-user mode. It's like running under the Terminal, but it takes over the whole screen because the GUI hasn't started yet, and you're running as root. (Type "exit" at the single-user root prompt to leave single-user mode and continue booting into multi-user mode.)

Unix systems are organized in this fashion because Unix dates from the days of 5 MB hard disks the size of washing machines. It was common for a big Unix system to have multiple physical hard disks, and for /usr to be off on a separate disk from the system's boot volume. If the /usr volume wouldn't mount for some reason, you could still get a Unix box to boot up into single-user mode to fix it.

.../local/...obviously stands for the local computer...

Yes. It refers to the fact that files under /usr/local are supposed to be particular to that single system. Files that are in any way generic are supposed to live elsewhere.

This also has roots in the way Unix systems were commonly used decades ago when all this was standardized. In this case, it's again because hard disks were bulky, really expensive, and stored little by today's standards. To save money and space on disks, a computer lab full of Unix boxes would often share most of /usr over NFS or some other network file sharing protocol, so each box didn't have to have its own redundant copy. (This is also where we get /usr/share: it segregates files that could be shared even between Unix boxes with different processor types. Typically, text files: man pages, the dictionary, etc.) Files specific to a single box would go under /usr/local, which would be a separate volume from /usr.

This historical heritage is why it's still the default for most third-party Unix software to install into /usr/local when installed by hand. Most such software will let you install the package somewhere else, but by making a non-choice, you get the safe default, which doesn't interfere with other common install locations with more specific purposes.

There are good reasons to make software install somewhere else instead. Apple's OS X team does this when they build, say, grep from the GNU grep source code. They use /usr as the installation prefix, overriding the /usr/local default. Another common prefix is /usr/X11R6.

And what is /bin?

It's short for "binary", a generic term that can refer to many different things, depending on context.

In the context of Unix directories, it refers to that fact that the files in that directory are compiled executable programs, as opposed to text files, which live elsewhere. Some Unix people call executables "binaries" for the same reason.

On a modern system, it's common to find the occasional script file in a bin directory. That bends the original meaning behind the purpose of this directory, since scripts are text files, but it's not a problem in practice. The original Unix systems were carefully enough scoped that this didn't happen, at least not with the OS as originally delivered. Scripts that came with the OS lived elsewhere, like /etc.

share|improve this answer
    
thanks, I learned a lot from your answer –  phunehehe Nov 19 '10 at 15:54
1  
This is the best description of the UNIX filesystem I've ever read. And I've read quite a few! –  Groky Aug 6 '11 at 2:54
1  
very cool explanation, thank you. –  clime Feb 22 '13 at 9:39

I would recommend referring to Wikipedia for structure related questions in general, it will cover the basics.

To answer your question directly, however:

  • /usr is, loosely, non-critical system libraries and executables
  • /usr/local is, again loosely, for non-system libraries and executables

This is why you tend to find similar structure between the two; /usr/{,local/}{bin,sbin,lib}. Being new to the shell, that bit with the {}'s is a shell expansion. Try executing

ls -ld /usr/{,local/}{bin,sbin,lib}

from your local shell to see how it works.

share|improve this answer

/usr/local/bin shows the UNIX-esque roots of the latest Mac OS (its BSD based under there).

usr stands for UNIX System Resources. This is the location that system programs and libraries are stored.

local represents resources that were not shipped with the standard distribution and, usually, compiled and maintained on a per site basis.

bin represents binary compiled executables.

This has morphed since the early implementations of UNIX to Linux and BSD, but the convention has stayed. Now, /usr/bin would be for "main" or core programs and libraries where /usr/local/bin would be for add-on and non-critical programs and libraries.

share|improve this answer
5  
I've been using Unix since shortly after the Berlin Wall fell, and I'd never heard the "Unix System Resources" expansion for "usr" until today; it is a backronym. "usr" got its name because it's where the user home directories were originally located. That is, if you had a login on an old System III box, your initial working directory would be /usr/nzwulfin by default. Another common scheme. before the SVR4 /home scheme took over, was /u. One system I used early on had so many users they needed multiple physical disks for user file storage, so they had things like /u/d5/tangent. –  Warren Young Nov 18 '10 at 17:54
    
@Warren I hadn't heard it either and poked around Google for a while; it sounds like there are quite a few backronyms –  Michael Mrozek Nov 19 '10 at 23:35

/usr/local/bin is the most popular default location executable, especially for open source ones. This is however arguably a poor choice as, on Unix systems, /usr has been standardized in the early nineties to contain a hierarchy of files that belong to the operating system and thus can be shared by multiple systems using that OS. As these files are static, the /usr file system can be mounted read-only. /usr/local is defeating this standard as it is by design local thus non shared, need to be read-write to allow local compilation and isn't part of the operation system. Too bad something like /opt/local wasn't chosen instead ...

share|improve this answer

I recommend you use /usr/local for commercial programs you might install such as Mathematica. Place it in its own partition when you set up. When you upgrade your OS, this partition won't be disturbed and you won't have to reinstall its contents. So use it for stuff you want to keep between OS upgrades.

Separately, make sure you give /home its own partition for this reason too.

share|improve this answer

On a Mac, while you can only write to /usr as root so Terminal, there is the way to go there in Finder. Use the "Go To Folder..."command under the "Go" menu.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.