I have a folder that contains multiple files
folder
- artifact1.app
- artifact2.ext2
- artifact3.ext3
- …
My goal is to zip the file from outside this folder (so without using cd
command) without including the folder dir.
zip -r ./folder/artifact.zip ./folder/artifact1.app
This command includes the folder dir in the final zip. Any hints?
Related question: Zip the contents of a folder without including the folder itself
Best Answer
If you want to store all the files in
folder
under their name without a directory indication, you can use the-j
option.or
If you have files in subdirectories, they won't have any directory component in the archive either, e.g.
folder/subdir/foo
will be stored in the archive asfoo
.But it would probably be easier to change to the directory. It's almost exactly the same amount of typing as the brace method aboe. If you do that, if you include files in subdirectories, they'll have their relative path from the directory you changed into, e.g.
folder/subdir/foo
will be stored assubdir/foo
.For interactive use, you lose shell completion this way, because the shell doesn't realize that you'll be in a different directory when you run the
zip
command. To remedy that, issue thecd
command separately. To easily go back to the previous directory, you can usepushd
andpopd
.If you want full control over the paths stored in a zip file, you can create a forest of symbolic links. Unless instructed otherwise,
zip
doesn't store symbolic links.