にタイムスタンプを追加し、私はどのように解凍temp.zip、名前で追加のタイムスタンプと、 結果構造バッシュの解凍ファイルと名前
temp.zip - file.csv - readme.txt - license.txt
とzipファイルを持っている:-l
を使用して
file.142345687.csv readme.142345687.txt license.142345687.txt
にタイムスタンプを追加し、私はどのように解凍temp.zip、名前で追加のタイムスタンプと、 結果構造バッシュの解凍ファイルと名前
temp.zip - file.csv - readme.txt - license.txt
とzipファイルを持っている:-l
を使用して
file.142345687.csv readme.142345687.txt license.142345687.txt
リストファイルオプションを使用して、-p
オプションを使用して1つずつ抽出します。
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以来。
#!/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