I have a number of png
and jpg
files whose names are numbers, e.g.0100.png
, in a directory,
-
How can I add
1
to their names, for example, to get0002.png
and0003.png
from0001.png
and0002.png
respectively, without overwriting? -
How can I subtract
2
from their names, so that0100.png
will not become098.png
but0098.png
instead?
Related https://stackoverflow.com/questions/26770060/subtracting-a-number-from-the-names-of-all-the-files-in-a-directory, but more difficult here.
Best Answer
I would probably end up using temporary directory in this case:
The important part is
10#N
which forces bash to interpret000N
as justN
, otherwise leading zeros denotes octal numbers.For example: