I have a bunch of files x1.jpg, x2.jpg, x3.jpg, etc. that need to be named x001.jpg, x002.jpg, x003.jpg, etc. How can I do this?
Edit: I'm running windows but have cygwin installed.
I have a bunch of files x1.jpg, x2.jpg, x3.jpg, etc. that need to be named x001.jpg, x002.jpg, x003.jpg, etc. How can I do this?
Edit: I'm running windows but have cygwin installed.
For bulk renaming image files on Windows (as well as resizing, cropping, converting etc.) I often use IrfanView (Freeware)
Which OS? *nix has the rename
command line utility which seems to be tailored for exactly this kind of thing.
A more generic approach than rename
(which is not available on all *nix), and potentially allowing quite some creativity:
find . -name 'x*' | while read filename; do mv "$filename" $(echo "$filename" | sed -e 's/x/x00/'); done
Cygwin, sweet.
for NEWNUM in $(seq -w 1 100)
do
OLDNUM=$(echo $NEWNUM | sed -e 's/^0*//')
echo $OLDNUM $NEWNUM
# mv x${OLDNUM}.jpg x${NEWNUM}.jpg
done
This should work. Well other than the commented out mv. The -w flag to seq means 'wide', meaning begin pad with zeros when necessary
Multiple or mass renaming can be called batch renaming.
Total Commander is file manager. It has batch rename feature. You can see tutorial there or there.
Irfan View is image browser/editor. It has batch rename too. You can see tutorial there.
I prefer Total Commander. It has Linux clones and they can probably rename files too.
Both these programs are for Windows. Both should work in Linux too by emulation.
In pure bash:
for a in x?.jpg; do mv "$a" "${a/x/x00}"; done
for a in x??.jpg; do mv "$a" "${a/x/x0}"; done