user1340531
user1340531

Reputation: 740

Wrap zip files in a folder

When zipping a bunch of files, is there a way to wrap them in a folder in the process?

zip -r archive.zip \
    file1.txt \
    file2.txt \
    things/*/*.txt

I'd like the zip to contain a folder that contains the file1.txt, file2.txt and things folder.

Is there a way to do it with zip without having to copy all these files to a folder and then zipping the folder instead?

Upvotes: 4

Views: 883

Answers (2)

user1340531
user1340531

Reputation: 740

I ended up unzipping the zip to a folder and then zipping that folder.

zip -r archive.zip \
    file1.txt \
    file2.txt \
    things/*/*.txt

unzip archive.zip -d archive

rm archive.zip

zip -r archive.zip archive

rm -rf ./archive

Upvotes: 1

AlphaBeta
AlphaBeta

Reputation: 65

Have a trick for you to make this work using a soft link.

  1. cd to a directory that does not hold your files
  2. create a soft link to the folder that holds your files ln -s /folderWithMyStuff containingFolder
  3. zip the soft link zip -r archive.zip containingFolder

Your files will now be saved in archive.zip under a folder called containingFolder

Upvotes: 2

Related Questions