Monday, April 1, 2013

shell: Rename Multiple Files in a folder

Substitute foo in file names to bar:

for f in *;
do 
  mv $f ${f/foo/bar}
done

Prefix all .jpg files with foo and a counter:

i=1
for f in *.jpg;
do
  mv $f 'foo-'$i'.jpg'
  i=`expr $i + 1`
done

Notice spaces in expr can not be omitted.

Windows: MINGW32

You can start a MINGW32 shell command line from git cmd under Windows.

i=0;for f in *.jpg; do mv $f $i'.jpg'; i=`expr $i + 1`; done

No comments:

Post a Comment