file_contexts.subs_dist - Linux


file_contexts.subs_dist generates a new file_contexts file by merging and ordering the provided SELinux file context files. It is commonly used in the SELinux policy packaging and development process to create or update the final file context mappings for a given policy. By combining multiple context files, it allows for modular policy development and easier updates.


file_contexts.subs_dist [-hvV] [-b base_contexts] [-s header_file] file_contexts.subs...


  • -h, –help: Displays a help message.
  • -v, –verbose: Enables verbose output, providing additional details about the merging process.
  • -V, –version: Prints the version of file_contexts.subs_dist.
  • -b, –base_contexts: Specifies a base file_contexts file to use as a starting point. This file should contain common or default file context mappings.
  • -s, –header_file: Generates a header file containing declarations for the file context structure. This header file can be included in other code or scripts.


Simple example:

file_contexts.subs_dist file_contexts.subs

This command merges the file contexts defined in file_contexts.subs into a new file_contexts file.

Complex example:

file_contexts.subs_dist -v -s header.h file_contexts.base file_contexts.local.subs file_contexts.optional.subs

This command generates a verbose output and header file while merging the contexts from file_contexts.base, file_contexts.local.subs, and file_contexts.optional.subs into a new file_contexts file.

Common Issues

  • Duplicate file contexts: If multiple file context files define the same file context, the last occurrence will be used.
  • Missing file contexts: If a file path is not found in any of the provided file context files, it will be assigned the default context specified in the base file_contexts file (or the default context if no base file is provided).
  • Incorrect file permissions: Ensure that the file_contexts files have the correct permissions (typically 640 or 644) to be read by the file_contexts.subs_dist command.


SELinux policy development: file_contexts.subs_dist is an essential part of the workflow when developing or updating SELinux policies.
It enables the merging of multiple context files, allowing modular policy development and easier maintenance.

Related Commands

  • sepolicy – The primary SELinux policy management tool.
  • selinux-genfs – Generates a SELinux file context file based on a filesystem snapshot.
  • getfilecon – Gets the SELinux file context for a given path.