我有以下文件
AU.GIRL..BHZ_2016-08-01T07_54_45.882_2016-08-01T08_18_05.882.sac
AU.GIRL..BHZ_2016-08-01T08_02_26.314_2016-08-01T08_25_46.314.sac
AU.GIRL..BHZ_2016-08-01T10_32_05.204_2016-08-01T10_55_25.204.sac
AU.GIRL..BHZ_2016-08-02T12_43_06.165_2016-08-02T13_06_26.165.sac
我想输出文件名应该是
AU.GIRL..BHZ_2016-08-01T07_54_45.882
AU.GIRL..BHZ_2016-08-01T08_02_26.314
AU.GIRL..BHZ_2016-08-01T10_32_05.204
AU.GIRL..BHZ_2016-08-02T12_43_06.165
答案 0 :(得分:0)
要从文件名中删除最后28个字符,可以使用参数扩展:
#! /bin/bash
for file in * ; do
new=${file::-28}
if [[ -e "$new" ]] ; then
echo "File already exists ($old, $new)." >&2
else
mv "$file" "$new"
fi
done