How to remove first n digits in bash with string substitution

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the bash category.

Last Updated: 2024-11-23

How do you remove the first N characters of a string in bash?

e.g. the 9_ prefixes here:

9_066345000001.jpg
9_066345002001.jpg
...

The trick is to put the string in a variable then use the following construct:

${var:N}

To do this in a loop, you might have something like this:

for file in *.jpg; do echo "${file:2}"; done
066345001101.jpg
066345002101.jpg