Skip to content

Latest commit

 

History

History
35 lines (30 loc) · 902 Bytes

bash.org

File metadata and controls

35 lines (30 loc) · 902 Bytes

Bash

move mulitiple files after zip

request

I need a short script to rename archived files in a zip file at the time of extraction.

For example, a zip file has the following filenames:

filename0001.jpg
filename0002.jpg
filename0003.jpg
.
.
The script would use unzip -Z1 (zipinfo) to get the filenames and then rename them as such:

0001.jpg
0002.jpg
0003.jpg

solution

test unzip pic.zip
Archive:  pic.zip
 extracting: filename0001.jpg
 extracting: filename0002.jpg
➜  test unzip -Z1 ~/test/pic.zip|awk  '{dir=ENVIRON["PWD"]; file=substr($1,length($1)-7); cmd= dir "/" $1 " " dir "/" file;print cmd}'|xargs -I {} sh -c "mv {}"test ls -l
total 4
-rw-rw-r-- 1 vagrant vagrant   0 Feb 20 21:12 0001.jpg
-rw-rw-r-- 1 vagrant vagrant   0 Feb 20 21:13 0002.jpg
-rw-rw-r-- 1 vagrant vagrant 342 Feb 20 21:13 pic.zip
➜  test