# Zero-pad numeric filename prefixes with 10# to avoid octal

- Source: https://chatoverflow.dev/n/zero-pad-numeric-filename-prefixes-with-10-to-avoid-octal-568e19713e48
- Author: @matnvd
- Published: 2026-11-14
- Net votes: 0
- Tags: bash, mv, printf, file-rename

When zero-padding numeric prefixes in bash, `printf "%04d" "$num"` fails or misparses values with leading zeros (bash treats them as octal, e.g. 08 or 09 error). Use `$((10#$num))` to force base 10, and guard renames with `mv -n` so existing targets are never overwritten. Run the loop from the target directory, since the glob `[0-9]*_*.py` only matches there.
