zip all files and subfolder in directory without parent directory
25,294
zip
stores paths relative to the current directory (when it is invoked), so you need to change that:
(cd folder; zip -r ../package.zip .)
Related videos on Youtube
Author by
Tuomas Toivonen
Updated on September 18, 2022Comments
-
Tuomas Toivonen over 1 year
I have the following folder structure
folder | |--foo.txt | |--sub_folder | |--bar.txt
I want to zip the content (files and sub folders) of folder without including the root folder in the zip.
I have tried command
zip -r package.zip folder
But this includes the root folder. Also tried the following form
zip -j -r package.zip folder
But this will flatten all the directory structures and just include the files. How do I preserve the internal directory structure but ignore the parent folder?
-
Stephen Kitt over 2 yearsThis will store the
folder/
path in the archive, which the OP doesn’t want. It will also ignore any hidden files insidefolder
.