I'm trying to create backups of my USB key. For that, I'd need to zip the content of my USB key (/Volumes/<USB KEY NAME>/
). I have this code for the momentzip -r /Volumes/<USB KEY NAME>/*
That seems to work, except the fact that when I extract my archive, I get :
(For simplfication purpose (and laziness), <USB KEY NAME>+(<DATE>).zip
is Archive.zip
)
Archive.zip
-> Volumes
-> <USB KEY NAME>
-> <USB KEY CONTENT>
-> ...
How to get just :
Archive.zip
-> <USB KEY NAME>
-> <USB KEY CONTENT>
-> ...
I know it's something about absolute/relative paths but that's all I know. How could I do this ?
PS : I'm on MacOS
Try using the -j
option.
It stores just the name of the saved files (junk the path), and does not store directory names. By default, zip
will store the full path (relative to the current path).
As man zip
tell us,
-j --junk-paths Store just the name of a saved file (junk the path), and do not store directory names. By default, zip will store the full path (relative to the current directory).
However, -j
will discard all path information, which caused all files be put in same package without any path information.
Method 1
Change current directory(cd
)
cd /Volumes; zip -rq $(OLDPWD)/Archive.zip <USB_Key_Name>; cd -
Method 2 Symlink will help
ln -s /Volumes/<USB_Key_Name> . # create symlink to avoid cd
zip -rq Archive.zip <USB_Key_Name>
rm <USB_Key_Name> # remove symlink
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With