0

I have a list of files that are in the form foo001.h21.tif that I need to rename. I know how to substitute strip off the end of the filename, but not the beginning. I basically need to strip it so it can be saved as 001.h21.tif. Normally I would use:

for i in *.tif; do mv $i ${i%%.tif}; done

to capture everything preceding .tif. Can someone help me with figuring out how to go the opposite way?

THanks!

4

1 回答 1

1

%and %%are 是 what 的后缀###are 是前缀。在你的情况下,你可以写:

for filename in foo*.tif; do mv "$filename" "${filename#foo}"; done

请参阅Bash 参考手册中的第 3.5.3 节“Shell 参数扩展”

于 2013-03-08T22:23:31.317 回答