我在Linux目录中有一些文件,如下所示。
email_Tracking_export_2018_08_26.zip
email_Tracking_export_2018_08_27.zip
email_Tracking_export_2018_08_28.zip
email_Tracking_export_2018_08_29.zip
email_Tracking_export_2018_09_03.zip
email_Tracking_export_history_Novemeber.zip
email_Tracking_export_history_December.zip
email_Tracking_export_history_january.zip
email_Tracking_export_history_february.zip
email_Tracking_export_history_march.zip
email_Tracking_export_history_April.zip
现在,我想将文件名更改为如下所示。
email_Tracking_export_2018_08_26.zip
email_Tracking_export_2018_08_27.zip
email_Tracking_export_2018_08_28.zip
email_Tracking_export_2018_08_29.zip
email_Tracking_export_2018_09_03.zip
email_Tracking_export_2017_11_01.zip
email_Tracking_export_2017_12_01.zip
email_Tracking_export_2018_01_01.zip
email_Tracking_export_2018_02_01.zip
email_Tracking_export_2018_03_01.zip
email_Tracking_export_2018_04_01.zip
条件:
我如何在bash/Linux
中实现这一目标
答案 0 :(得分:1)
for f in email_Tracking_export_*.zip; do
case "$f" in
email_Tracking_export_????_??_??.zip) : ignore ;;
*) date=$(stat -c %Y "$f") # mod time in seconds
fmtdate=$(date --date="@$date" +%Y_%m_%d) # formatted
mv "$f" email_Tracking_export_$fmtdate.zip
;;
esac
done
答案 1 :(得分:0)
mv
命令以新名称重命名文件。