S
S
Sergey Karbivnichy2020-10-31 12:58:05
linux
Sergey Karbivnichy, 2020-10-31 12:58:05

How to create a zip archive in Linux with hidden files and directories?

I sketched a simple script to backup some files and folders in the home folder. But I noticed in time that hidden files and directories (starting with a dot) are not added to the archive by default.

zip -r -9 backup-`date +"%d-%m-%Y_%H.%M"`.zip /home/sergey/* \
  -x "/home/sergey/.cache/*" \
  -x "/home/sergey/VM/*" \
  -x "/home/sergey/SeleniumProfile/*" \

Of course, I looked at the help, googled - in the articles someone says that you need to put a dot with an asterisk, someone just put a dot in the parameters - nothing works.
I copy examples from Google - zip gives me:
zip error: Zip file structure invalid (.)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2020-10-31
@hottabxp

Try like this:

zip -r -9 backup-`date +"%d-%m-%Y_%H.%M"`.zip /home/sergey/.

V
Valdemar Smorman, 2020-10-31
@smorman

Example
Initial data:
- we have a test
folder in it, a hidden folder .test and hidden files: .bash_history and .bash_test
Task: - make a .zip
archive with files located in the test folder : .bash_history , .bash_test and a hidden folder .test Execution:

$ cd test
:~/test$ ls -a
:~/test$ .  ..  .bash_history  .bash_test  .test
:~/test$ zip test . -9 -r
  adding: .bash_test (stored 0%)
  adding: .bash_history (stored 0%)
  adding: .test/ (stored 0%)
:~/test$ ls
test.zip

Checking the archive:
:~/test$ unzip -l test.zip | awk -F'/' 'NF<3 && !$2'
Archive:  test.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
       11  2020-10-31 14:05   .bash_test
       11  2020-10-31 14:05   .bash_history
        0  2020-10-31 14:08   .test/
---------                     -------
       22                     3 files

Notice!
Point - . the code zip test . -9 -r
just has an operand for archiving hidden files and directories...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question