/bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, /usr/local/sbinの違い。

コマンドファイルが格納されているディレクトリが6つあります。これらは、/bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, /usr/local/sbin です。

これらの違いは何ですか?自分でスクリプトを書く場合、どこに追加すればいいですか?


関連情報

ソリューション

これについては、Filesystem Hierarchy Standard (FHS) for Linuxを参照してください。

  • /usr : /usr パーティションがマウントされる前に使用できるバイナリ用です。ブートのごく初期段階で使用する些細なバイナリや、シングルユーザーモードでのブート時に利用できるようにする必要があるものに使用します。catls`などのようなバイナリを考えてみてください。

  • /sbin : 同じですが、スーパーユーザー(root)権限が必要なバイナリ用です。

  • /usr/bin : 最初のものと同じですが、一般的なシステムワイドなバイナリのためのものです。

  • /usr/sbin : 上記と同じですが、スーパーユーザ(root)権限が必要なバイナリ用です。


自分でスクリプトを書く場合、どこにこれらを追加すればいいのでしょうか?

上記のいずれでもないです。システム全体で利用可能なスクリプトには /usr/local/bin/usr/local/sbin を使うべきです。local`パスは、システムパッケージで管理されていないことを意味します(これはDebian/Ubuntuパッケージではan errorです)。

ユーザーが使用するスクリプトには、~/bin (ホームディレクトリにある個人用のbinフォルダ)を使用します。

FHSでは、/usr/localとなっています。

このホストに固有のローカルデータの3次階層です。一般的には、bin/, lib/, share/ などのサブディレクトリがあります。

解説 (6)

私も1年以上前に同じような質問をしたことがあります。https://askubuntu.com/questions/830074/best-directory-to-place-my-bash-scripts

バイナリーのシステムディレクトリ

man hier` (hierarchy) は、すべてのディレクトリを一覧表示します。バイナリ用のディレクトリを取得するには、次のようにします。

$ man hier | grep -E 'bin$|sbin$|^.{7}(/bin)|^.{7}(/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

自分のスクリプトをどこに置くか?

すべてのユーザーが自分のスクリプトにアクセスできるようにするには、/usr/local/bin に置くとよいでしょう。ここにファイルを追加・変更するには sudo 権限が必要であることに注意してください。参照: https://askubuntu.com/questions/195652/is-there-a-standard-place-for-placing-custom-linux-scripts

自分のユーザーID用のスクリプトは、/home/YOUR_NAME/binに置いてください。最初にこのディレクトリを作成して、ターミナルを再起動しないと、~/.profileで自動的に設定されたパスにならないことに注意してください。参照: https://askubuntu.com/questions/402353/how-to-add-home-username-bin-to-path?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa


What I know I don't know

Ask Ubuntu**にある複雑なbashスクリプトを、githubにあるインストールスクリプトでセットアップすることを考えています。いくつか例を挙げてみます。

スクリプトは、$PATHに含まれる/usr/binにインストールすべきだと *考えていますが、まだ適切な場所がわかりません。

解説 (5)