Usr bin directory in linux

/usr/bin vs /usr/local/bin on Linux

And on my office box, I do not have write permissions to some of these.

What type of binary goes into which of these bin s?

There are fewer places nowadays, since /bin was merged with /usr/bin and /sbin was merged with /usr/sbin – see The Case for the /usr Merge.

@Pacerier ~/bin is for the current user only. For example in multiuser Linux servers where you are not an admin that’s the only way to «install» stuff for yourself.

5 Answers 5

  1. /bin (and /sbin ) were intended for programs that needed to be on a small / partition before the larger /usr , etc. partitions were mounted. These days, it mostly serves as a standard location for key programs like /bin/sh , although the original intent may still be relevant for e.g. installations on small embedded devices.
  2. /sbin , as distinct from /bin , is for system management programs (not normally used by ordinary users) needed before /usr is mounted.
  3. /usr/bin is for distribution-managed normal user programs.
  4. There is a /usr/sbin with the same relationship to /usr/bin as /sbin has to /bin .
  5. /usr/local/bin is for normal user programs not managed by the distribution package manager, e.g. locally compiled packages. You should not install them into /usr/bin because future distribution upgrades may modify or delete them without warning.
  6. /usr/local/sbin , as you can probably guess at this point, is to /usr/local/bin as /usr/sbin to /usr/bin .

In addition, there is also /opt which is for monolithic non-distribution packages, although before they were properly integrated various distributions put Gnome and KDE there. Generally you should reserve it for large, poorly behaved third party packages such as Oracle.

I think this answer does a great job of clarifying a common set of conventions, but this post from Rob Landley is a really great read if you want insight into the nonsense. lists.busybox.net/pipermail/busybox/2010-December/074114.html

refspecs.linuxfoundation.org/fhs.shtml for the canonical current reference. The link by @kojiro is outdated and doesn’t have the new spec.

Where do I put a bin I downloaded from the internet? From your description it sounds like it should go in /usr/local/bin or /usr/bin. Is /usr/bin something I should never manually touch, and let only the package manager play with?

@DidierA. put it in ~/bin and add that directory to your PATH as a user. Thanks for the note, I deleted my seriously outdated comment.

I found the answer to the first part of my question here: superuser.com/a/238993/425838. Precedence is based on order in the system PATH variable, and echo $PATH for me shows /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games , which means that executables in /usr/local/bin take precedence over the ones in /usr/bin which take precedence over the ones in /bin .

Читайте также:  Kali linux удалить пакет

I recommend taking a look at the file system hierarchy man page:

which is also available online, for instance: http://linux.die.net/man/7/hier. Relevant portions have been copied below. Depending on your system, it may say something different.

Name

Description

    A typical Linux system has, among others, the following directories:

    This directory contains executable programs which are needed in single user mode and to bring the system up or repair it.
    Like /bin , this directory holds commands needed to boot the system, but which are usually not executed by normal users.
    This is the primary directory for executable programs. Most programs executed by normal users which are not needed for booting or for repairing the system and which are not installed locally should be placed in this directory.
    Binaries for programs local to the site.
    Locally installed programs for system administration.
    This directory contains program binaries for system administration which are not essential for the boot process, for mounting /usr , or for system repair.

The man page does contain an entry for each of the bin directories, explaining what goes into them, which was one of the questions.

@BillyONeal Probably a better answer than others because it does answer the question, moreover gives a quick reference command as well.

The Filesystem Hierarchy Standard entry in Wikipedia helped me answer the same question when I had it, plus it has a very explanatory table.

/bin Essential command binaries that need to be available in single user mode; for all users, e.g., cat, ls, cp. /usr/bin Non-essential command binaries (not needed in single user mode); for all users. /usr/local Tertiary hierarchy for local data, specific to this host. Typically has further subdirectories, e.g., bin, lib, share /usr/sbin Non-essential system binaries, e.g., daemons for various network-services. /sbin Essential system binaries, e.g., fsck, init, route. 

1 Retrieved on June 19, 2019; permalink.

The sbin directories contains programs which are generally system administration only. Programs for regular users should never go in them.

A few programs are needed during startup, and end up in /bin/ or /sbin/ . These must be available before file systems are mounted. Things like mount , and fsck that are required to check and mount files systems must be there.

Most packaged programs end up in /usr/bin/ and /usr/sbin/ . These may be on a file system other than the root file system. In some cases they may be on a network mounted drive.

Local programs and scripts belong in /usr/local/bin/ and /usr/local/sbin/ . This identifies them as clearly non-standard, and possibly only available on site.

Читайте также:  Запустить сервер майнкрафт linux

For further explanation try running the command man hier which should provide a description of the recommended file system hierarchy for your distribution. You may also want to read about the File System Hierarchy on Wikipedia

«Local programs and scripts belong in /usr/local/bin/ and /usr/local/sbin/» — You mean local programs as in «not at all part of the OS, but I decided to install them and want to use them»?

In the 1970s, UNIX had all official executables in /bin and /usr/bin was a location beneath the users home directories (e.g. /usr/dmr ) that was available for any user to store own binaries that might have been of interest for others as well.

The result of this open /usr/bin was a junk yard of undocumented software and so Stephen Bourne wrote a cron script that checked for new binaries every night and removed all binaries that did not have a documentation or that have been updated without updating their documentation as well.

In the late 1970s, /usr/bin was integrated into the OS base distribution and people started to use /usr/local/bin for the purpose of the previous open /usr/bin .

After a while, sysadmins used /usr/local/bin to store non-local software that was imported from the network (e.g. the USENET) and as UNIX companies did not like to repeat the same mistake as with /usr/bin again, there was a file system hierarchy conference around 1987 where all UNIX companies agreed to give up /usr/local/bin and to use /opt//bin instead.

Unfortunately, Linux distros did not follow this decision.

Источник

Differences between /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, /usr/local/sbin

Your own scripts should go into ~/.local/bin , according to systemd and XDG. See the answers here and here for more.

2 Answers 2

  • /bin : For binaries usable before the /usr partition is mounted. This is used for trivial binaries used in the very early boot stage or ones that you need to have available in booting single-user mode. Think of binaries like cat , ls , etc.
  • /sbin : Same, but for binaries with superuser (root) privileges required.
  • /usr/bin : Same as first, but for general system-wide binaries.
  • /usr/sbin : Same as above, but for binaries with superuser (root) privileges required.

if I’m writing my own scripts, where should I add these?

None of the above. You should use /usr/local/bin or /usr/local/sbin for system-wide available scripts. The local path means it’s not managed by the system packages (this is an error for Debian/Ubuntu packages).

For user-scoped scripts, use ~/bin (a personal bin folder in your home directory).

The FHS says for /usr/local :

Tertiary hierarchy for local data, specific to this host. Typically has further subdirectories, e.g., bin/ , lib/ , share/ .

Does placing scripts in /bin cause any problems? I have moved my scripts according to your answer but I am still curious

Читайте также:  Консольный менеджер загрузок linux

@RumeshSudhaharan you should not do that, because it’s managed by the package management. If any other package also wants to use that path, it will overwrite your file. Files in packages can never overlap (at least for official repositories), so you are more safe when installing in the local path. Also, it’s just for your own convenience and safety. In a local path you can’t mess up the system in such a bad way and you can’t accidentally replace a system binary.

I have put some files in /usr/local/bin and I can execute them, however I cannot edit them, ls -la shows nothing

FWIW, sbin has nothing to do with scripts. It stores binaries — even the links provided note that.

I had a similar question myself a year+ ago: Best directory to place my bash scripts?

System directories for binaries

man hier (hierarchy) lists all the directories. To get the ones just for binaries use:

$ man hier | grep -E 'bin$|sbin$|^.(/bin)|^.(/sbin)' -A2 /bin This directory contains executable programs which are needed in single user mode and to bring the system up or repair it. -- /sbin Like /bin, this directory holds commands needed to boot the system, but which are usually not executed by normal users. -- /usr/X11R6/bin Binaries which belong to the X-Window system; often, there is a symbolic link from the more traditional /usr/bin/X11 to here. -- /usr/bin This is the primary directory for executable programs. Most programs exe‐ cuted by normal users which are not needed for booting or for repairing the -- /usr/local/bin Binaries for programs local to the site. -- /usr/local/sbin Locally installed programs for system administration. -- /usr/sbin This directory contains program binaries for system administration which are not essential for the boot process, for mounting /usr, or for system 

Where to put your own scripts?

For all users to access your scripts you can put them in /usr/local/bin . Keep in mind you need sudo access to add / change files here. See: Is there a standard place for placing custom Linux scripts?

For your own user ID scripts put them in /home/YOUR_NAME/bin . Keep in mind you have to create this directory first and relaunch the terminal to get the path automatically setup by ~/.profile . See: How to add /home/username/bin to $PATH?

What I know I don’t know

I’m contemplating taking some of my more complex bash scripts in Ask Ubuntu and setting them up with install scripts on github . Here are few examples:

I think the scripts should be installed in /usr/bin which is in the $PATH, but I’m not sure on the appropriate place yet.

Источник

Оцените статью
Adblock
detector