Ubuntu – Use case where script filenames have leading numbers to determine execution order

bashcommand linefilesystemscripts

I'm looking for documentation or a use case where in Linux there is a directory with shell scripts where each filename is led with a number, and the files are run in that particular order. What is this convention called, and where is it used?

For example:

0001-motd.sh
0002-proxy.sh
0300-ssh.sh

I know I have seen this before, just not sure where or what it is called.

Best Answer

It sounds like you are referring to run-parts

NAME
       run-parts - run scripts or programs in a directory

SYNOPSIS
       run-parts  [--test]  [--verbose] [--report] [--lsbsysinit] [--regex=RE]
       [--umask=umask] [--arg=argument] [--exit-on-error] [--help] [--version]
       [--list] [--reverse] [--] DIRECTORY

       run-parts -V

DESCRIPTION
       run-parts  runs  all  the  executable  files  named  within constraints
       described below, found in directory directory.  Other files and  direcā€
       tories are silently ignored.

       If neither the --lsbsysinit option nor the --regex option is given then
       the names must consist entirely of ASCII upper- and lower-case letters,
       ASCII digits, ASCII underscores, and ASCII minus-hyphens.

       If  the  --lsbsysinit  option  is given, then the names must not end in
       .dpkg-old  or .dpkg-dist or .dpkg-new or .dpkg-tmp, and must belong  to
       one  or more of the following namespaces: the LANANA-assigned namespace
       (^[a-z0-9]+$);   the   LSB   hierarchical   and   reserved   namespaces
       (^_?([a-z0-9_.]+-)+[a-z0-9]+$);  and  the  Debian cron script namespace
       (^[a-zA-Z0-9_-]+$).

       If the --regex option  is  given,  the  names  must  match  the  custom
       extended regular expression specified as that option's argument.

       Files  are  run  in  the  lexical  sort order (according to the C/POSIX
       locale character collation rules) of their names unless  the  --reverse
       option is given, in which case they are run in the opposite order.