View previous topic :: View next topic |
Author |
Message |
eddo n00b
Joined: 03 Mar 2008 Posts: 51
|
Posted: Sun Jan 04, 2009 10:46 am Post subject: Utility to zip many files into separate archives? |
|
|
As above really, I have a whole directory of files which I need in individual zip files. zip doesn't seem to have this feature as standard and find -exec won't work because you can only use the filename once, where as zip takes two arguments "zip archivename filetobezipped", so any ideas? Thanks in advance. |
|
Back to top |
|
|
toralf Developer
Joined: 01 Feb 2004 Posts: 3940 Location: Hamburg
|
Posted: Sun Jan 04, 2009 11:32 am Post subject: |
|
|
Code: | find . -type f -print0 | xargs -0 -I{} -n 1 echo zip {}.zip {}
| Use that command w/o echo to do it really. |
|
Back to top |
|
|
eddo n00b
Joined: 03 Mar 2008 Posts: 51
|
Posted: Sun Jan 04, 2009 12:08 pm Post subject: |
|
|
Thanks a lot, but I don't suppose there's a way of doing it so it removes the file extention for the archive name? E.g. example.exe -> example.zip not example.exe.zip? Many thanks. |
|
Back to top |
|
|
eddo n00b
Joined: 03 Mar 2008 Posts: 51
|
Posted: Sun Jan 04, 2009 1:03 pm Post subject: |
|
|
No worries, I just used
for file in *.exe.zip ; do mv $file `echo $file | sed 's/\(.*\.\)exe.zip/\1zip/'` ; done
Cheers, |
|
Back to top |
|
|
yngwin Retired Dev
Joined: 19 Dec 2002 Posts: 4572 Location: Suzhou, China
|
Posted: Mon Jan 05, 2009 1:01 am Post subject: |
|
|
Even simpler, just using the power of bash:
Code: | for i in * ; do zip ${i/.exe/.zip} $i ; done |
_________________ "Those who deny freedom to others deserve it not for themselves." - Abraham Lincoln
Free Culture | Defective by Design | EFF |
|
Back to top |
|
|
|