Answer the question
In order to leave comments, you need to log in
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/*" \
zip error: Zip file structure invalid (.)
Answer the question
In order to leave comments, you need to log in
Try like this:
zip -r -9 backup-`date +"%d-%m-%Y_%H.%M"`.zip /home/sergey/.
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
:~/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
zip test . -9 -r
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question