我有拉链结构击解压缩文件,并添加时间戳名
temp.zip - file.csv - readme.txt - license.txt
如何解压temp.zip,在名称添加时间戳, 结果:使用-l
file.142345687.csv readme.142345687.txt license.142345687.txt
我有拉链结构击解压缩文件,并添加时间戳名
temp.zip - file.csv - readme.txt - license.txt
如何解压temp.zip,在名称添加时间戳, 结果:使用-l
file.142345687.csv readme.142345687.txt license.142345687.txt
列出文件选项,然后使用-p
选项一个接一个地提取它们:
unzip -l -q -q temp.zip | awk '{print $NF}' | while read file
do
unzip -p temp.zip "${file}" > "${file%.*}.$(date +%s).${file##*.}"
done
其中
-q -q
选项要求一个无声输出(在易于解析列);awk
的$NF
指向最后一列;${file%.*}
从文件名后面删除.*
的最短匹配项;${file##*.}
从文件名的前面删除*.
的最长匹配项;$(date +%s)
输出秒自1970-01-01 00:00:00 UTC,你可以尝试这样的事情;
#!/bin/bash
unzip temp.zip
for n in $(unzip -Z -1 "temp.zip"); do
e=${n#*.}
fn="${n%.*}"
DATE=`date +%s`
newFileName="$filename.$DATE.$e"
mv "$n" "$newFileName"
done
非常感谢你! – ConorHolt
非常感谢你! – ConorHolt