I’m trying to add each file, specified one per line, into a file named files.zip. The directory structure of each file specified should remain as is. After the file listed in files.txt is added to files.zip it should be deleted, but never the directories.
The structure of the text file is one file per line:
/file2.png /data/example.png /data2/more.png /music/test.ogg
I have files.txt in the /
directory I’m running the zip command from.
Background Information: I’m running Debian with the package zip installed. I can only get manually specified filesfolders to zip (ex: $ zip -r /files.zip /), but not by specifying an external list from a txt file.
Advertisement
Answer
mapfile -t files <files.txt && zip /files.zip "${files[@]}" && rm -f -- "${files[@]}"