run-parts executes all programs and scripts in a directory -- but when do I need it?

What are some common uses for it?

  • You could ask that same question for each individual Unix utility. Do you have an issue using run-parts on your system, or is there some other problem relating to the utility that you are trying to resolve?
    – Kusalananda
    Feb 26 at 5:39
  • @Kusalananda, no I’m just interested in used for it, other than the obvious function. Feb 26 at 6:40

1 Answer 1


If you manage a server farm, or otherwise a number of similar systems, and e.g. have an application that requires a number of environment settings on each system, you could use run-parts to create a drop-in directory to which you could add and remove script snippets as required, so that each file would hold a group of settings associated for a particular servlet or other application component or configuration goal.

Your application start-up script (or equivalent) would then use run-parts to read all the settings from the drop-in directory before executing the actual application.

Managing the settings in the form of a drop-in directory can make it easier to synchronize and update the settings across a number of systems, especially when using tools such as Ansible, Salt or Puppet.

Even when managing just a single instance of a complex application, grouping the individual settings into files by purpose can make it easier to keep track what is going on, especially if the names of the script snippets are chosen descriptively.

When setting up a drop-in directory, it is a well-known practice to prefix the names of the scripts with a two- or three-digit number, to make the desired execution order explicit: run-parts will run scripts or programs in the directory in the "C" locale sort order (i.e. in the same order as LC_ALL=C /bin/ls will list them).

By using run-parts instead of rolling your own loop to execute all scripts in a specified directory, you can easily apply some common drop-in file naming rules (or use your own filename validation regex) to avoid processing editor backup files or other inappropriate files that may have been accidentally left in the drop-in directory.

If your distribution contains directories like /etc/profile.d/ or /etc/X11/Xsession.d/, their contents are most likely executed by using run-parts. The contents of system-wide cron job directories /etc/cron.(hourly|daily|weekly|monthly)/ are normally also executed using run-parts, either directly from /etc/crontab or indirectly via anacron's /etc/anacrontab.

Not the answer you're looking for? Browse other questions tagged .