Proper Location for Shared Scripts: /usr/local/bin vs /usr/local/sbin Explained for Linux Admins


3 views

The Filesystem Hierarchy Standard (FHS) defines the purpose of these directories:

/usr/local/bin - Regular user executable programs
/usr/local/sbin - System administration executables

/usr/local/bin is typically included in regular users' PATH by default, while /usr/local/sbin is usually only in root's PATH. This is crucial for your use case:


# Check your PATH
echo $PATH

# Typical PATH settings
/etc/profile (for all users):
PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin"

~/.bashrc (for individual users):
PATH="$PATH:/usr/local/bin"

For your script sharing scenario:

  • Use /usr/local/bin if the script is meant for daily use by normal users
  • Use /usr/local/sbin if it requires root privileges or performs system administration tasks


# For /usr/local/bin (user executables):
chmod 755 /usr/local/bin/your_script
chown root:staff /usr/local/bin/your_script # Allow group write access

# For /usr/local/sbin (admin executables):
chmod 750 /usr/local/sbin/admin_script
chown root:wheel /usr/local/sbin/admin_script

Here's how I deployed a shared backup script in our team environment:


#!/bin/bash
# team_backup.sh - Stores in /usr/local/bin
BACKUP_DIR="/shared/team_backups/$(date +%Y-%m-%d)"
mkdir -p "$BACKUP_DIR"
rsync -avz --progress "$@" "$BACKUP_DIR"

Installation command:


sudo install -o root -g staff -m 755 team_backup.sh /usr/local/bin/

For production environments, consider creating proper packages instead of direct file placement:


# Example debian/control file for a .deb package
Package: team-scripts
Version: 1.0
Section: utils
Priority: optional
Architecture: all
Maintainer: Your Name <you@example.com>
Description: Shared team utility scripts
Depends: bash, rsync

This ensures proper versioning and dependency management.


In Unix-like systems, the distinction between /usr/local/bin and /usr/local/sbin stems from the original Filesystem Hierarchy Standard (FHS). The key difference lies in their intended usage scenarios:

/usr/local/bin     # For normal user executables (no sudo required)
/usr/local/sbin    # For system administration binaries (typically requires root)

When deciding where to place your shared script, consider these factors:

  • User Accessibility: Scripts in bin are automatically in PATH for all users
  • Security Context: sbin typically contains programs needing elevated privileges
  • Package Management: Both directories are safe from system upgrades

Here's how common tools are typically distributed:

# Common /usr/local/bin contents
/usr/local/bin/python3
/usr/local/bin/npm
/usr/local/bin/composer

# Common /usr/local/sbin contents
/usr/local/sbin/nginx
/usr/local/sbin/iptables
/usr/local/sbin/ldconfig

For your shared script, follow this installation pattern:

#!/bin/bash

# Simple example script
echo "Hello team! This script runs as $(whoami)"

# Installation command
sudo install -o root -g wheel -m 755 team_script.sh /usr/local/bin/

Modern systems typically include both in PATH, but check with:

echo $PATH | tr ':' '\n' | grep local

For system-wide scripts requiring no special privileges, /usr/local/bin is the clear recommendation. Reserve sbin for maintenance tools that should only be run by sysadmins.