Why do some some files in /etc have a numeric prefix?

For example look in /etc/apt/apt.conf.d/ all files have a numeric prefix. What is the reason? I have seen this many times and always wonder. Is it just for the sake of ordering?


Solution 1:

Yes it is for ordering and usually anything not starting with a number is ignored.

The files then get read and executed in order.

So for example in /etc/grub.d/

$ ls /etc/grub.d/
00_header    10_linux      20_memtest86+  30_uefi-firmware  41_custom
05_debian_theme  20_linux_xen  30_os-prober   40_custom     README

The grub script to create the boot entries (like update-grub, that by default writes them in /boot/grub/grub.cfg) will first read the 00_header and create the header, then look for Linux systems, then the memtest, then UEFI, and so on.

When you look at the output

cat /boot/grub/grub.cfg

you will see that the entries are exactly in that order.

$ cat /boot/grub/grub.cfg
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
[...]
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/05_debian_theme ###
[...]
### END /etc/grub.d/05_debian_theme ###

### BEGIN /etc/grub.d/10_linux ###
function gfxmode {
[...]    
### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/20_linux_xen ###

### END /etc/grub.d/20_linux_xen ###

### BEGIN /etc/grub.d/20_memtest86+ ###
menuentry 'Memory test (memtest86+)' {
[...]
### END /etc/grub.d/20_memtest86+ ###


[...]