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? – Nasir Riley Oct 16 '20 at 10:35pwd
andcd
, but there should be easier way – Zhurik Oct 16 '20 at 10:38zip archive.zip file1 file2 file3 [some_more_parameters]
so i have an archive with directory inside, not just files – Zhurik Oct 16 '20 at 12:07zip -j file.gz path_to_dir/
and you forget that dir, you don't see that again when extracting – thanasisp Oct 16 '20 at 13:06find -type f -name *file*
on the parent directory and see the name of the folder containing the files but that would actually take longer than just changing to the directory to see and you'd have to make sure that there aren't two files with the same exact name in different directories while also exactly where they are in the hierarchy. – Nasir Riley Oct 16 '20 at 17:59