Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
256 views
in Technique[技术] by (71.8m points)

macos - Command line zip everything within a directory, but do not include any directory as the root

I can't find the answer to this for the life of me. Because I am packaging a zip in a specific way for a build process, I don't want to include a folder at all in the resulting zip at the root. For example, if I have this file path:

MyFolder/
    A.png
    B.txt
    C.mp3

And I use either the command:

zip -r -X "MyFolder.zip" MyFolder/*

or

cd MyFolder; zip -r -X "../MyFolder.zip" *

I end up with a zip file that has the root element of MyFolder. What I want is for when I unzip it is to dump all of it right into the directory, like this:

A.png
B.txt
C.mp3

In other words, I don't want MyFolder or any other folder as the root. I read through the whole manual and have tried numerous options and a lot of Google searching, and zip seems to just really want to have a folder at the root.

Thanks!

question from:https://stackoverflow.com/questions/24543255/command-line-zip-everything-within-a-directory-but-do-not-include-any-directory

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It was Archive Utility's fault (a Mac OS X unzipper app). When I used the unzip command from the command line, it works great.

(cd MyFolder && zip -r -X "../MyFolder.zip" .)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...