Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to zip or tar all the files and subdirectories in current directory and save it to the file I am zipping. The problem is that -x shitch does not work - files are being zipped and saved to a random-named file.

zip -r backup.zip ./* -x backup.zip

This is what I tried but the code did not work properly.

Is there any way to do this without saving the archive .. directory and then moving it back to the ./ dir?

Thanks in advance.

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

Zip will not attempt to zip it's own out file so you don't need to use -x. Assuming backup.zip already exists in the current directory and we try to update the zip:

# zip -r backup.zip ./*
updating: libproxychains4.so (deflated 61%)
updating: README (deflated 55%)
updating: TODO (deflated 17%)
updating: COPYING (deflated 62%)
updating: src/ (stored 0%)
updating: src/proxychains (deflated 65%)
updating: src/core.c (deflated 70%)
updating: src/common.o (deflated 68%)
updating: src/core.o (deflated 66%)
updating: src/main.c (deflated 58%)
updating: src/core.h (deflated 66%)
updating: src/libproxychains.c (deflated 69%)
updating: src/proxyresolv (deflated 30%)
updating: src/main.o (deflated 67%)
updating: src/libproxychains.o (deflated 70%)
updating: src/common.h (deflated 55%)
updating: src/proxychains.conf (deflated 57%)
updating: src/common.c (deflated 62%)
updating: proxychains.lsm (deflated 28%)
updating: configure (deflated 65%)
updating: AUTHORS (deflated 45%)
updating: dist/ (stored 0%)
updating: dist/config.mak (deflated 43%)
updating: ChangeLog (deflated 66%)
updating: config.mak (deflated 37%)
updating: proxychains4 (deflated 62%)
updating: tests/ (stored 0%)
updating: tests/test_getaddrinfo.c (deflated 51%)
updating: Makefile (deflated 58%)

Use -x if you really need to exclude a file from your backup.

share|improve this answer
add comment

./* is expanded by the shell before being sent to the command, so the only way zip will try to include backup.zip is if it exists before running the command.

tar can do it:

$ cd -- "$(mktemp -d)" 
$ touch -- $'--$`!*@\a\b\E\f\r\t\v\\\'"\360\240\202\211 \n'
$ tar -czf test.tar.gz ./*
$ ls
--$`!*@???????\'"𠂉 ?  test.tar.gz
$ tar -tvf test.tar.gz 
-rw-rw-r-- user/group      0 2013-06-26 14:38 ./--$`!*@\a\b\033\f\r\t\v\\'"𠂉 \n
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.