Zip Quote for directory names with spaces

I am having a problem with Zip, using directory names that contain a space such as:
zip -r /Volumes/Mac3Hd2/Backup '/Users/myname/Documents/Test Zip/*'

Terminal does not like the: '/Users/myname/Documents/Test Zip/*'

Where have I gone south?
Thanks

Posted on Oct 23, 2005 10:36 AM

Reply
7 replies

Oct 23, 2005 11:39 AM in response to Larry Gantz

Larry,

In Terminal, because spaces are a delimiter, you will need to escape them with a backslash. So the correct line would read "zip -r /Volumes/Mac3Hd2/Backup/Users/myname/Documents/Test\ Zip/*". If you are pasting the text into Terminal, use the "Paste Escaped Text" command.

As an aside, did you know that you can drag and drop the folder into Terminal and the path will be automatically pasted?

bd

Oct 24, 2005 9:36 AM in response to bdmarsha

db,
I did the "Paste Escaped Text"
Following is from Terminal -

My string: "zip -r /Volumes/Mac3Hd2/Backup/MatoushekWedding /Users/larrygantz/Documents/Test\ Zip/*"

Terminal paste results: \"zip\ -r\ /Volumes/Mac3Hd2/Backup/MatoushekWedding\ /Users/larrygantz/Documents/Test\\\ Zip/\*\"

Execution: "zip -r /Volumes/Mac3Hd2/Backup/MatoushekWedding /Users/larrygantz/Documents/Test\ Zip/*": No such file or directory

Looks like Terminal inserts a \ before each space and notice what it did to "Test Zip"

Still getting "No such file or directory" ?
Thanks

p.s. Yes to drag and drop folder into Terminal

Oct 24, 2005 12:07 PM in response to Larry Gantz

<code>mikey$ zip -f archivename.zip "/Users/myname/Documents/Test Zip/"</code>



You do not need "*" because you're speficying recursion with the <code>-r</code> flag. The quoting removes the need to escape the path further.

Additionally, if you encapsulate the asterisk with quotes, it will be deemed a literal instead of a wildcard. (The shell looks for a file or folder named "*" inside the "Test Zip" folder, instead of interpreting the asterisk as an operator to catch multiple items.) Example:

<code>[thermodynamics:~/Desktop] mikey% ls *.zip
file.zip
[thermodynamics:~/Desktop] mikey% ls "*.zip"
ls: *.zip: No such file or directory</code>



However, you don't have to quote entire path strings; you can quote parts of strings arbitrarily and let your wildcards shine:

<code>[thermodynamics:~/Desktop] mikey% ls *".zip"
file.zip</code>

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Zip Quote for directory names with spaces

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.