0

I need to rename 3028 files' names at once. Do you have any help?

0001____z1.0.tif    -->  0001.tif
0002____z2.0.tif    -->  0002.tif
   .
   .
   .

3028____z3028.0.tif --> 3028.tif

Can i rename whtout "____z2.0.tif" all files at once using the "rename" option for linux? or other way....? Please let me know if you have any idea. It would be grateful...

Romeo Ninov
  • 17,484

2 Answers2

0

Using perl rename or prename:

rename 's/_.*/.tif/' *.tif
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
pLumo
  • 22,565
0

Even though there is already an answer, I believe this task can be accomplished with just the shell.

Bash:

The expressions between the curly brackets are called brace expansions.

for fn in {1..3028}; do
    mv "$(printf "%04d\n" "${i}")____z${i}.0.tif" "${i}.tif"
done

POSIX:

i=0

while [ "${i}" -le 3028 ]; do mv "$(printf "%04d\n" "${i}")____z${i}.0.tif" "${i}.tif" i=$((i + i)) done

You may need to change into the directory where the files are or add its pathname to the arguments of the mv command. For example, if the files are in /tmp:

mv "/tmp/$(printf "%04d\n" "${i}")____z${i}.0.tif" "/tmp/${i}.tif"
qqqq
  • 48