計劃
- 用繩子
- 使用DD文件名查找偏移覆蓋新名稱(注意只使用相同的文件名長度的工作)。否則還必須找到並覆蓋 的filenamelength場..
備份您的壓縮文件嘗試這一
zip_rename.sh
#!/bin/bash
strings -t d test.zip | \
grep '^\s\+[[:digit:]]\+\sAAAAA-\w\+\.txt' | \
sed 's/^\s\+\([[:digit:]]\+\)\s\(AAAAA\)\(-\w\+\.txt\).*$/\1 \2\3 BBBBB\3/g' | \
while read -a line; do
line_nbr=${line[0]};
fname=${line[1]};
new_name=${line[2]};
len=${#fname};
# printf "line: "$line_nbr"\nfile: "$fname"\nnew_name: "$new_name"\nlen: "$len"\n";
dd if=<(printf $new_name"\n") of=test.zip bs=1 seek=$line_nbr count=$len conv=notrunc
done;
輸出
前
$ ls
AAAAA-apple.txt AAAAA-orange.txt zip_rename.sh
$ zip test.zip AAAAA-apple.txt AAAAA-orange.txt
adding: AAAAA-apple.txt (stored 0%)
adding: AAAAA-orange.txt (stored 0%)
$ ls
AAAAA-apple.txt AAAAA-orange.txt test.zip zip_rename.sh
$ ./zip_rename.sh
15+0 records in
15+0 records out
15 bytes (15 B) copied, 0.000107971 s, 139 kB/s
16+0 records in
16+0 records out
16 bytes (16 B) copied, 0.000109581 s, 146 kB/s
15+0 records in
15+0 records out
15 bytes (15 B) copied, 0.000150529 s, 99.6 kB/s
16+0 records in
16+0 records out
16 bytes (16 B) copied, 0.000101685 s, 157 kB/s
$ unzip test.zip
Archive: test.zip
extracting: BBBBB-apple.txt
extracting: BBBBB-orange.txt
$ ls
AAAAA-apple.txt BBBBB-apple.txt test.zip
AAAAA-orange.txt BBBBB-orange.txt zip_rename.sh
$ diff -qs AAAAA-apple.txt BBBBB-apple.txt
Files AAAAA-apple.txt and BBBBB-apple.txt are identical
$ diff -qs AAAAA-orange.txt BBBBB-orange.txt
Files AAAAA-orange.txt and BBBBB-orange.txt are identical
使用zipnote的重命名功能? http://www.computerhope.com/unix/zipnote.htm – bishop
我沒有權限在需要執行此@bishop的機器上安裝軟件。 – Topo
好吧,在舊名稱和新名稱之間創建映射,然後遍歷該映射。如果存檔中存在舊名稱,請將其從存檔提取到磁盤,在磁盤上重命名,將新重命名添加到存檔。如果成功,請從存檔中刪除舊名稱。可以在bash中完成,但是我發現bash數組很麻煩,所以我可能會使用P *語言。 – bishop