RUN-PARTS(8)

๐Ÿ’– NAME ๐Ÿ’–

run-parts โ€” runs the scripts or programs chillin' in a directory, no cap ๐ŸŒธ


๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

run-parts [--test] [--verbose] [--debug] [--report] [--lsbsysinit]
[--regex=RE] [--umask=umask] [--arg=argument] [--after=PROG]
[--before=PROG] [--exit-on-error] [--help] [--version] [--list]
[--reverse] [--] DIRECTORY [DIRECTORY ...]
run-parts -V

โœจ DESCRIPTION โœจ

okay so basically, run-parts goes through directory and runs all the executable files that match the rules we're about to spill below. Any other file? Any directory? silently ignored. Not a word. Not a peep. It's giving "not my business" energy ๐Ÿ’…

So here's the vibe check on which filenames get to be picked, depending on which flag you use:

  • If you give it neither --lsbsysinit nor --regex, then the names have to be made up entirely of ASCII upper- and lower-case letters, ASCII digits, ASCII underscores, and ASCII minus-hyphens. That's it. That's the whole guest list.
  • If you pass --lsbsysinit, then the names must not end in .dpkg-old or .dpkg-dist or .dpkg-new or .dpkg-tmp, and they have to belong to one or more of these namespaces:
    1. the LANANA-assigned namespace (^[a-z0-9]+$)
    2. the LSB hierarchical and reserved namespaces (^_?([a-z0-9_.]+-)+[a-z0-9]+$)
    3. the Debian cron script namespace (^[a-zA-Z0-9_-]+$)
  • If you pass --regex, then the names just have to match whatever custom extended regular expression you fed it as that option's argument. Your regex, your rules, main character behavior fr fr.

The files get run sequentially, in the lexical sort order of their names (that's per the C/POSIX locale character collation rules, iykyk) โ€” unless you pass --reverse, in which case bestie runs them in the opposite order. Iconic.

And now the plot twist: if you hand it more than one DIRECTORY, then files with the same name in the earlier directories take precedence over files in directories you listed later. Why does that matter? Because it lets run-parts take directories with scripts in both /usr and /etc, and let the files in /etc override the scripts in /usr when they're named the same ๐Ÿซถ For that to actually happen, the directory under /etc needs to be specified before the path under /usr. Order matters, bestie. Periodt.


๐Ÿ‘‘ OPTIONS ๐Ÿ‘‘

  • --test โ€” prints the names of the scripts that would run, but doesn't actually run them. Window shopping only, no purchasing ๐Ÿ›๏ธ
  • --list โ€” prints the names of all matching files (not just the executables), but doesn't actually run them. > heads up: this option cannot be used with --test. Pick a lane.
  • -v, --verbose โ€” prints the name of each script to stderr before running it.
  • --report โ€” kinda like --verbose, except it only prints the name of scripts which actually produce output. And it prints the script's name to whichever of stdout or stderr the script first produces output on. Sleek, honestly.
  • -d, --debug โ€” prints to stderr which scripts got selected for running and which ones didn't. Full transparency, we love to see it ๐Ÿ”ฅ
  • --reverse โ€” reverses the scripts' execution order. Backwards babe ๐Ÿ’…
  • --exit-on-error โ€” bails out the second a script returns with a non-zero exit code. No patience, and honestly? Valid.
  • --stdin โ€” multiplexes stdin to the scripts being run, using a temporary file.
  • --lsbsysinit โ€” uses the LSB namespaces instead of the classical behavior.
  • --new-session โ€” runs each script in its own separate process session. > โš ๏ธ careful babes: if you use this option, killing run-parts will not kill the currently running script โ€” it'll just run until it finishes. It does not care. It will not be stopped.
  • --regex=RE โ€” validates filenames against the custom extended regular expression RE. There's an example down in the EXAMPLES section, go peek ๐Ÿ‘€
  • -u, --umask=umask โ€” sets the umask to umask before running the scripts. umask should be given in octal. By default the umask is set to 022.
  • -a, --arg=argument โ€” passes argument to the scripts. Use --arg once for each argument you want passed. Stack 'em up ๐ŸŽ€
  • -A, --after=program โ€” runs program after each script runs. The program gets called with three arguments: the script name, the exit status, and the total amount written to the output and error streams. That last argument will always be 0 unless the --report option is also specified. If you use this option multiple times, only the last one takes effect. And if the called program exits with an error code, it won't be called again. One strike, you're out โœ‹
  • -B, --before=program โ€” runs program before running each script. The program gets called with one argument: the script name. If you use this option multiple times, only the last one takes effect. Same deal as above: if the called program exits with an error code, it won't be called again.
  • -- โ€” declares that this is the end of the options. Any filename after -- will not be interpreted as an option, even if it starts with a hyphen. Protection mode: activated ๐Ÿ›ก๏ธ
  • -h, --help โ€” displays usage information and exits.
  • -V, --version โ€” displays version and copyright and exits.

๐ŸŒˆ EXAMPLES ๐ŸŒˆ

Wanna print the names of all files in /etc that start with p and end with d? Say less:

run-parts --list --regex '^p.*d$' /etc

  • Copyright (C) 1994 Ian Jackson.
  • Copyright (C) 1996 Jeff Noxon.
  • Copyright (C) 1996, 1997, 1998 Guy Maor
  • Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Clint Adams

run-parts is free software; see the GNU General Public License version 2 or later for copying conditions. There is no warranty.


and that's the whole page bestie ๐Ÿ’œ this lil' slice of the System Manager's Manual (RUN-PARTS(8)) came from Debian, dated 27 Jun 2012 โ€” go run some scripts responsibly, mwah ๐Ÿ’…โœจ

๐Ÿ“ฆ where this page comes from