Zip Files

Daniel Carrera daniel.carrera at zmsl.com
Thu Apr 20 15:59:32 UTC 2006


Charles Malespin wrote:
> Hi all, 
>   I am trying to zip some files in a dir.  that I have in my home
> folder.  I read the man, and I did
>   zip -r /home/malespin/Space\Magnets  

The correct command would be:

zip -r SpaceMagnets.zip /home/malespin/Space\ Magnets

NOTE: "Space\Magnets" is an unlikely directory name. So I assume that it 
really is "Space Magnets", which is more probable. But on the command 
line, if the space is part of the name, you need to precede it by a \, 
so you end up with "Space\ Magnets".

> Plus how can I zip only particular files in the
> folder without zipping all of them?  I thought that 
>   zip -r /home/malespin/Space\Magnets *.pdf 
> would work but it didnt....

zip -r myfiles.zip /home/malespin/Space\ Magnets/*.pdf

Notice:
* "Space\ Magnets" instead of "Space\Magnets".
* "mydirectory *.pdf" is wrong. "mydirectory/*.pdf" is correct.

The "*.pdf" as you correctly guessed means "anything that ends in .pdf", 
but the space is a problem. Zip works like this:

zip myfiles.zip file1 file2 file3

So, the input files are separated by spaces. Now look at the command:

zip -r myfiles.zip dir *.pdf

Here "dir" and "*.pdf" are different arguments because they are 
separated by a space. So technically you are telling zip to grab the 
directory "dir" and also grab all the pdf files in the /current/ 
directory. On the other hand, the pattern "dir/*.pdf" matches any file 
that has the patter "dir/<BlahBlahBlah>.pdf" which corresponds to all 
the pdf files in the directory "dir", which is what you want.

Best,
Daniel.
-- 
      /\/`) http://opendocumentfellowship.org
     /\/_/
    /\/_/   A life? Sounds great!
    \/_/    Do you know where I could download one?
    /




More information about the ubuntu-users mailing list