How can we specify the unzip or 7za command in linux to extract multiple zip files into one folder while keeping all duplicates? - linux

I currently have about 10 zip files I would like to extract into one folder. Each zip file contains around 1000 images. As a result, lots of the names of the images are duplicated. For example, in the first zip file, we have things like Img.jpg, Img(1).jpg, Img(2).jpg. I know that to extract multiple zip files into a single folder, I would do something like:
unzip '*.zip'
However, when it tries to put a file from the first zip file that has the same name as a file in the second zip file, it starts to ask:
replace duplicatefile.mp4? [y]es, [n]o, [A]ll, [N]one, [r]ename:
At this point, what do I do if I want to keep ALL files, including the duplicates, and possibly have them named to image(1).jpg instead?
In short, is there a way to call the unzip command on all the zip files, have them extracted into a single folder, without losing any files due to same names?
Thanks.

Invoke unzip --help for details.
But it appears unzip *.zip -n should do the trick?
(Make sure it does what you expect before going ahead!)

Related

unziping files in linux folder

in Python I have the following command executed unzip '{dir}ATTOM_RECORDER/*.zip' -d {dir}ATTOM_RECORDER/ as a bash command. The python call works perfectly. my question is about the unzip command itself.
for some reason when unzip is called to expand any relevent zip files in the folder specified, not all the files WITHIN the zip is extracted. There's usually a rpt and a txt file. However, sometimes the txt file is not coming out and I do not have an error command.
How can I ensure the txt file is guaranteed to be extracted before moving on?
Thanks
While you want to unzip your specific zip file. There are many option to decompress any file from zip files. Easiest way is the ā€˜-lā€™ option with unzip command is used to list the contents of a zip file after extracting it.
Syntax: unzip -l [file_name.zip]

Error while using zip with -R# options and file-list; "Invalid command arguments (nothing to select from)"

I am trying to deploy different groups of files (of many different types) to different environments using Bitbucket Pipelines and AWS CodeDeploy. In Pipelines, I use the zip command (from apt-get) to package up all the files for the specific environment and upload them to CodeDeploy (using the CodeDeploy pipe, which seems to expect a zip file).
A recent change has made it unwieldy to use a single line command to feed the all the necessary files to zip, so I instead would like to use a file list. The problem is that I have several sub-folders where I need to recursively grab all files, while in others I need to grab specific files. I also need to preserve the folder structure.
I also don't want to have to add every single path by hand if possible, as there are a lot of files in these sub-directories, and I also want to reduce the amount of cases where we forget to add new files to these lists. I also don't want to require the developer running a script locally, but I am okay with creating a script for use in Pipelines.
I tried to use the -R# option with zip, but it gives the error zip error: Invalid command arguments (nothing to select from).
Example folder structure:
file1.txt
ziplist.txt
folder1/file2.js
folder1/file3.txt
folder1/folder2/file4.png
folder1/folder2/file5.jpg
folder1/folder3/file6.tsx
folder1/folder3/file7.mp3
The contents of ziplist.txt:
file1.txt
folder1/file2.js
folder1/folder2/file5.jpg
folder1/folder3/*
Using the command cat ziplist.txt | zip -R# application.zip, I'd expect to have a zip with the following files inside:
file1.txt
folder1/file2.js
folder1/folder2/file5.jpg
folder1/folder3/file6.tsx
folder1/folder3/file7.mp3
Appreciate any help.
I was able to make it work by removing the /* for the folder path in the zip list, and then use xargs to convert the list to command line parameters, like so:
cat ziplist.txt | xargs zip -r application.zip

unzip a list of archives

I need to Unzipped a list of zip archives. These archives are not empty, in each one there are a lot of file. In my directory I have a lot of file zip archive and all have the the name in the same format: batch-download-ccd-1610959358275.zip but change only the numeric part. I can extract each archive with unzip command but if I try to extract all the archives together with this command unzip *.zip I get this message (For simplicity I report only the example where I try to extract two archives):
Archive: batch-download-ccd-1610959358275.zip
caution: filename not matched: batch-download-ccd-1610959397790.zip
Could someone help me please?
unzip takes only one archive as an argument, the remaining arguments are understood as files inside the archive.
Use a shell loop:
for zip in batch-download-ccd-*.zip ; do
unzip "$zip"
done

Can we add files to a zip archive with modified file names

I want to create a zip archive for some files in folder hierarchy.
for example:
abc.php_0973_890
newone.text_2344_870
I want to have:
abc.phpnewone.txt in my zip archive. Is there any way for doing this?
We can not do that as zip doesnot suuport anything like that, we can use tar for such things as it as options like: --transform which can be used to transform the output filename

Unzip archive to an existing directory structure

I'm looking at bring the content of one WP blog over to another as I will be using WPML to server regional content instead of multiple sites. So not strictly a WP question, more command line.
This may seem an obvious or stupid question, but if I bring over the other 'uploads' folder as a zip and unzip to the wp-content folder, will the contents merge into the existing folders or overwrite what is already there.
If it's the latter, is there a switch I can append to ensure files are merged?
Thanks in advance,
Tom
When unzip finds a file that already exists in the destination, it will ask you if you want to overwrite it. You can then type y to overwrite it, A to overwrite all files, N if you don't want to overwrite any of them etc.
Example:
$ unzip archive.zip
Archive: archive.zip
replace foo? [y]es, [n]o, [A]ll, [N]one, [r]ename:
Try using
unzip -o <filepath/zipfile.zip> -d <path where you want files>
Best use: unzip --help

Resources