Is there a logic to the directory structure?

All Gurus once were Newbies
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Please stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions prefer the other forums within the support section.
Before you post please read this

Is there a logic to the directory structure?

Postby RJim on Thu Jun 21, 2012 12:24 am

Okay... having installed and uninstalled a few apps now, I am noticing some unexpected behavior; and that is there seems to be none (or very little) reason behind where the apps get installed to.

Examples of what I am referring to is this... I installed a few games, and they get installed in different folders with no logic behind it:

/usr/games/Game1
/usr/share/games/Game2
/usr/local/games/Game3


And it's the same with work-related apps; I never have a clue if they are in:

/usr/bin
/usr/share/bin
/usr/local/bin


So I ask, is there a logic behind the locations that I am missing? Or just don't understand? I like to keep things tidy and organized... and the seemingly random location of apps is hampering my neatness. :mrgreen:

--Jim
RJim
Level 3
Level 3
 
Posts: 109
Joined: Thu May 10, 2012 9:49 pm

Linux Mint is funded by ads and donations.
 

Re: Is there a logic to the directory structure?

Postby Oscar799 on Thu Jun 21, 2012 4:32 am

Image
"Don't fix it if it ain't broken,don't break it if you can't fix it" Husse
Registered Linux User #511789
User avatar
Oscar799
Level 18
Level 18
 
Posts: 8842
Joined: Tue Aug 11, 2009 9:21 am
Location: United Kingdom

Re: Is there a logic to the directory structure?

Postby Garvan on Thu Jun 21, 2012 8:17 am

It is a mess, with no clear standard being adopted. Any guess which version would run if you have a program with the same name in all three bin locations?

/usr/bin
/usr/share/bin
/usr/local/bin

My bet is that local will be used. I will try it to see.

Garvan

PS
The programs were found in this order.

1. /home/bin/
2. /usr/local/bin/
3. /usr/bin/


This directory
/usr/share/bin
Is not used on my system.
Desktop: Dell, Intel Core 2 Duo E7500 @ 2.93Ghz, 2GiB RAM, Linux Mint 13 Maya.
Net-book: SAMSUNG N148-Plus, 2x Intel Atom CPU N450 @1.66Ghz, 1GB RAM, lubuntu 12.04.
User avatar
Garvan
Level 4
Level 4
 
Posts: 273
Joined: Sun May 29, 2011 3:26 am
Location: Cambodia

Re: Is there a logic to the directory structure?

Postby wallaroo on Thu Jun 21, 2012 8:42 am

Garvan wrote:It is a mess, with no clear standard being adopted. Any guess which version would run if you have a program with the same name in all three bin locations?

/usr/bin
/usr/share/bin
/usr/local/bin

My bet is that local will be used. I will try it to see.

Garvan


If the full path is not specified when running a program the system searches locations in the order listed in the local $PATH environment variable.

You can see this list by running 'echo $PATH' on the command line.
wallaroo
Level 1
Level 1
 
Posts: 33
Joined: Thu Feb 09, 2012 3:42 am

Re: Is there a logic to the directory structure?

Postby Garvan on Thu Jun 21, 2012 10:01 am

wallaroo wrote:
Garvan wrote:It is a mess, with no clear standard being adopted. Any guess which version would run if you have a program with the same name in all three bin locations?

/usr/bin
/usr/share/bin
/usr/local/bin

My bet is that local will be used. I will try it to see.

Garvan


If the full path is not specified when running a program the system searches locations in the order listed in the local $PATH environment variable.

You can see this list by running 'echo $PATH' on the command line.


Thank you, it should have been obvious, but I did not think of checking the path.

Garvan
Desktop: Dell, Intel Core 2 Duo E7500 @ 2.93Ghz, 2GiB RAM, Linux Mint 13 Maya.
Net-book: SAMSUNG N148-Plus, 2x Intel Atom CPU N450 @1.66Ghz, 1GB RAM, lubuntu 12.04.
User avatar
Garvan
Level 4
Level 4
 
Posts: 273
Joined: Sun May 29, 2011 3:26 am
Location: Cambodia

Re: Is there a logic to the directory structure?

Postby RJim on Thu Jun 21, 2012 2:21 pm

Thanks for the replies.

@Garvan

Thanks, that test was actually quite fascinating... I do have several copies of some programs (different versions) and now I know which one gets executed. :)


@Oscar799

That link was helpful, but I am still kind of wondering:

It says /bin is for "User Binaries" and /usr is for "User Programs"... now maybe I'm just out of the tech loop here but what exactly is the difference between the two?
And /usr/local/ makes no sense to me... isn't every program installed on my machine a "local" program, or am I not understanding the context of the word in this case?
That page also states that /usr/bin is for "Second-level programs" but what does that mean? If it's programs installed afterwards, then what is the use for /opt ? :?:

Sorry, but this is the Newbie area for my newbie questions after all. :mrgreen:

--Jim
RJim
Level 3
Level 3
 
Posts: 109
Joined: Thu May 10, 2012 9:49 pm

Re: Is there a logic to the directory structure?

Postby RJim on Fri Jun 22, 2012 11:35 am

Guess I'm not the only one who isn't sure about these things. :lol:
I can't seem to find any definitive answer on Google, beyond the link that Oscar799 posted. They all seem to copy and paste the same bit of info and that's it.
RJim
Level 3
Level 3
 
Posts: 109
Joined: Thu May 10, 2012 9:49 pm

Re: Is there a logic to the directory structure?

Postby DrHu on Fri Jun 22, 2012 2:21 pm

RJim wrote:And /usr/local/ makes no sense to me... isn't every program installed on my machine a "local" program, or am I not understanding the context of the word in this case?


I don't think it can be explained any more deeply, than there is a standard (FHS) and it varies a bit between some Linux distributions; that is how well they adhere to the FHS specifications..

That directory (folder) is in a few Linux distributions as their standard, and for the reasons below is included
    /usr/local Tertiary hierarchy for local data, specific to this host. Typically has further subdirectories, e.g., bin/, lib/, share/.[29]
Also remember that Linux is a multiuser, multitasking OS, and so does consider remote directories etc in considering its file system design..
    https://www.redhat.com/archives/fedora-list/2005-September/msg01914.html

There isn't an absolute standard, because various Linux distributors have historically used some locations that were included into the FHS (File Hierarchy Standard) for compatibility's sake!
https://en.wikipedia.org/wiki/Filesyste ... y_Standard
--see the references section for various Linux distribution differences..
    RedHat (Fedora) and Debian or Debian derivations Ubuntu:Mint..

The reason it is slow to change, if it would ever be done is this compliance need to match/keep older customers of a particular Linux distributor's versions.
--and for their sake, and until end-of-life attribution to a Linux release, it is unlikely to be that much changed
    Nevertheless, it is via that standards approach FHS, mostly compliant..
User avatar
DrHu
Level 16
Level 16
 
Posts: 6714
Joined: Wed Jun 17, 2009 8:20 pm

Re: Is there a logic to the directory structure?

Postby MALsPa on Fri Jun 22, 2012 3:50 pm

Using some of the tools available right there in Linux can help a person get used to the directory structure and kinda make some sense of it. Seeing the location of application files, you start getting a feeling for where certain types of files are gonna be located. This is kinda going at things from the reverse direction, but it was helpful to me for understanding the Linux file system.

I'm writing from Fedora 16, where I've installed the Geany text editor. Some commands that give me some info:

Code: Select all
$ which geany
/usr/bin/geany


Code: Select all
$ whereis geany
geany: /usr/bin/geany /usr/lib/geany /usr/share/geany /usr/share/man/man1/geany.1.gz


Also:

Code: Select all
$ locate geany
/home/steve/.config/geany
/home/steve/.config/geany/colorschemes
/home/steve/.config/geany/filedefs
/home/steve/.config/geany/geany.conf
/home/steve/.config/geany/tags
/home/steve/.config/geany/templates
/home/steve/.config/geany/ui_toolbar.xml
/home/steve/.config/geany/filedefs/filetypes.README
/home/steve/.config/geany/templates/files
/home/steve/.config/geany/templates/templates.README
/usr/bin/geany
/usr/lib/geany
...


Often, I'll go to the package manager to get a list of installed files for a particular application. For Debian-based distros, I like to use Synaptic for this, but the following also works from the command line (again for Geany):

Code: Select all
$ dpkg -L geany


In Fedora, I'll use Yumex to find the filelist, or else run a command like this:

Code: Select all
$ rpm -q -l geany


If you do this type of thing often enough, things become a bit clearer, and these tools are also helpful for when different distros differ in where they put things, because you can take a look at the output of some of these commands and then know right away where to find what, for any particular app.
User avatar
MALsPa
Level 8
Level 8
 
Posts: 2030
Joined: Mon Nov 19, 2007 10:17 pm
Location: albuquerque

Re: Is there a logic to the directory structure?

Postby MALsPa on Fri Jun 22, 2012 4:04 pm

Here's a paragraph that seems kinda helpful:

For files that come pre-installed on your Linux distribution, here are the file locations. The Linux binary system programs are stored in the /bin folder (directory). The /boot folder contains the Linux kernel and the boot loader. The folder /etc contals the system-wide configuration files. These are configuration files for the linux system itself. Shared libraries are stored in /lib. Libraries correspond roughly with Windows .dll files. The /opt folder holds "optional" applications, generally commercial software products and the like. This is where applications like Firefox, Teamviewer, Adobe Air and proprietary printer applications typically go. The /usr folder contains a /bin, a /share and other folders for the programs that you install yourself. Some commercial programs like Skype go in here as well, but almost all of the Free and Open Source applications you find in your Linux distribution's software repositories will go here. Very predictable.


http://www.goinglinux.com/articles/Inst ... tions.html
User avatar
MALsPa
Level 8
Level 8
 
Posts: 2030
Joined: Mon Nov 19, 2007 10:17 pm
Location: albuquerque

Re: Is there a logic to the directory structure?

Postby RJim on Sat Jun 23, 2012 12:27 am

Thanks everyone, I know I'm a bit dense but this is really helping me understand the Linux way of arranging files.
Let me make sure I understand this: (please correct any mistakes I may have)

/bin is for system commands like ls, top, grep, that are common among all Linux systems

/usr/bin is for user commands that are distro specific... I notice that all the Mint commands are in here

/usr/local/bin is for programs specific to my system. I notice the few programs I compiled from source are the only things in this folder...
and "apt" for some reason is also in here.

/opt I really have no idea... I have my lcd-console-display driver in here, as well as firefox, and my printer driver. Seems to be a mix of stuff.


From what I can tell not many packages seem to obey these standards... For example, in /usr/bin, I also have commands in here too such as "less" and "zip" and "link". Shouldn't these be in /bin since they are not really distro specific? Or have I still missed it?


Thanks for your help guys, just want to get to know my system a bit better! :D
RJim
Level 3
Level 3
 
Posts: 109
Joined: Thu May 10, 2012 9:49 pm

Re: Is there a logic to the directory structure?

Postby perduta on Fri Feb 01, 2013 9:13 pm

I totally empathise with these sentiments and I think the unix style directory structure is long over-due for rationalization and simplification as it is designed for corporate networks with dumb terminals and not applicable to personal devices... and it's just confusing and inconvenient. I like the software packages to be installed as self contained enitities and not spread all over the place. :(

p.s. if you want to get a feel for the how things are organized try the command

Code: Select all
tree /


My reaction was :roll:
perduta
Level 2
Level 2
 
Posts: 69
Joined: Mon Jan 21, 2013 12:55 pm

Re: Is there a logic to the directory structure?

Postby bjornmu on Sat Feb 02, 2013 3:45 am

I don't know if this is "standard" but at my job where most of us have Solaris or Linux desktops, /bin and /usr/bin are local to each box while /usr/local/bin (and other dirs under /usr/local) are NFS mounted from a server that holds binaries for various variants of the OSes. So it's *not* local despite the name. This is to ease administration of upgrades etc.
User avatar
bjornmu
Level 3
Level 3
 
Posts: 156
Joined: Wed Dec 19, 2012 2:50 am
Location: Trondheim, Norway

Linux Mint is funded by ads and donations.
 

Return to Newbie Questions

Who is online

Users browsing this forum: DTJ, Google Adsense [Bot] and 34 guests