Thursday, April 7, 2011

Linux Rename Multiple Files At a Shell Prompt

rename file

from:
3207020003001_0%.pdf
3207020005010_0%.pdf
3207020007002_0%.pdf
3207060003014_0%.pdf
3207080007004_0%.pdf

to

3207020003001_0.pdf
3207020005010_0.pdf
3207020007002_0.pdf
3207060003014_0.pdf
3207080007004_0.pdf

command:  for i in *.pdf; do mv $i `echo $i |cut -c1-15,17-20` ; done


3207080007001_50%.pdf
3207080007003_50%.pdf
3207080007005_50%.pdf
3207080007002_50%.pdf


to


3207080007001_50.pdf  
3207080007003_50.pdf  
3207080007005_50.pdf
3207080007002_50.pdf



commad: for i in *.pdf; do mv $i `echo $i |cut -c1-16,18-21` ; done


3207080007001_100%.pdf
3207080007004_100%.pdf
3207080007002_100%.pdf
3207080007005_100%.pdf

to

3207080007001_100.pdf  
3207080007004_100.pdf  
3207080007002_100.pdf  
3207080007005_100.pdf


for i in *.pdf; do mv $i `echo $i |cut -c1-17,19-22` ; done


ref: http://www.cyberciti.biz/tips/renaming-multiple-files-at-a-shell-prompt.html

No comments: