1

Using bash on OS X 10.10 I'm zipping a folder and saving it elsewhere using this:

_now=$(date +"%Y-%m-%d-%H-%M-%S")
pushd /Users/me/Documents/local-backups/writing
zip -r /Users/me/Documents/local-backups/writing/writing-bak-$_now.zip /Users/me/Dropbox/writing
popd

However my zipped file includes all the annoying directories above "writing" (i.e., from /Users/me/Dropbox/writing).

I saw the question and answer here:

Avoid unwanted path in Zip file

... but I couldn't see how the solution there could apply to my example where directories are far apart.

2
  • Why change directory, since you are using full paths in the zip command? If you change directory to /Users/me/Dropbox/writing you can simply zip the relative directory ., or use * if you don't want the ./ prefix.
    – AFH
    Dec 4, 2014 at 21:40
  • I'm sorry, I don't understand. I've specified two directories because the file to be zipped is in one and the destination for the zip file is in another. What would be your alteration, so that I may understand?
    – GMag
    Dec 4, 2014 at 21:48

1 Answer 1

0

The penny dropped. It should be:

_now=$(date +"%Y-%m-%d-%H-%M-%S")
pushd /Users/me/Dropbox
zip -r /Users/me/Documents/local-backups/writing/writing-bak-$_now.zip ./writing/
popd
1
  • Just so! Sorry if I wasn't clear.
    – AFH
    Dec 5, 2014 at 2:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .