You can create a temporary directory hierarchy with the target archive folder name, zip that, and then remove it.
This works for bash
, presupposing there is no directory (or file) already named archive
in the current directory
(
shopt -s extglob
mkdir archive &&
cp -al !(archive) archive &&
zip -r archive.zip archive
rm -rf archive
)
Notice that the new directory hierarchy is linked rather then copied, so (a) it's fast, (b) it doesn't take up any significant extra disk space.
Worked example
# Set up the files in a directory
mkdir secret_name; touch secret_name/file{1,2,3}
cd secret_name/
# Now create the archive
( shopt -s extglob; mkdir archive && cp -al !(archive) archive/ && zip -r archive.zip archive; rm -rf archive )
# List the archive
unzip -l archive.zip
Archive: archive.zip
Length Date Time Name
--------- ---------- ----- ----
0 2020-10-16 19:21 archive/
0 2020-10-16 19:12 archive/file2
0 2020-10-16 19:12 archive/file3
0 2020-10-16 19:12 archive/file1
--------- -------
0 4 files
cd
to the parent directory and see?zip archive.zip file1 file2 file3 [some_more_parameters]
so i have an archive with directory inside, not just files