Reputation: 31
I need to zip multiple files into one zip file. I need to preserve the directory structure of files in the zip file as well. The files to be zipped will be in a separate text file with full path. I read the file names from the text file into a variable and pass it to the zip command. Here is the command i use.
zip -r $EXP_DIR/Export_files.zip $BASE_DIR -i "$file_name"
It works fine for single file. But when i add multiple files it fails with the below error.
zip error: Nothing to do! (zip file name)
I do not understand what i am missing here. Any suggestion would be greatly appreciated.
Thanks, Guna
Upvotes: 3
Views: 1962
Reputation: 5305
1) myfile.txt
contains filenames delimited by newline
zip out.zip -@ < myfile.txt
2) myfile.txt
contains filenames delimited by whitespace (no whitespace allowed in filenames!)
zip out.zip -@ < <(tr ' ' '\n' < myfile.txt)
From man zip
:
If a file list is specified as
-@
[Not on MacOS], zip takes the list of input files from standard input instead of from the command line.
For example,zip -@ foo
will store the files listed one per line on stdin infoo.zip
Upvotes: 2