unziping files in linux folder - linux

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]

Related

Linux unzip command fails to unzip file

I have a zip file named test_kit.zip which contains a shell script deploy.sh inside it. The shell script file has read, write and, execute permission.
I want to unzip this test_kit.zip file
Using jar xf or 7zip
jar xf test_kit.zip
7za x test_kit.zip
These commands unzip the zip file correctly but, the deploy.sh shell script loses the execute permission. Is there any way to unzip using 'jar xf' or '7za x' without losing execute permission for the files and folders inside the zip file?
Using unzip
unzip test_kit.zip
This command gives me an error which is as follows-
warning [test_kit.zip]: 1318507533 extra bytes at beginning or within zipfile
(attempting to process anyway)
error [test_kit.zip]: start of central directory not found;
zipfile corrupt.
(please check that you have transferred or created the zipfile in the
appropriate BINARY mode and that you have compiled UnZip properly)
I want to understand what is going wrong.

How to zip contents of a folder in linux command line

So i have a folder structure like MyFolder/File1, MyFolder/File2 .... MyFolder/FileN
I want to zip all the contents of MyFolder to MyFolder.zip such that on unzipping MyFolder.zip the contents are File1, File2 ... FileN
I want to do this using the linux command line.
I saw a method using the -r option of the zip command but the issue is that it creates a MyFolder.zip that on unzipping gives MyFolder. I do not want the MyFolder in it. I want it to directly give me the contents of MyFolder.
Any help will be appreciated. Thanks
You might enter the directory first before running the zip command (output file should be elsewhere for speed & to avoid warning "file changed during compression" on the zip file itself
zip ../toto.zip . -r
for example

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

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!)

how to extract files from a large (30Gb+) zip file on linux server

1) extract from large zip file
I want to extract files from a large zip file (30Gb+) on the linux server. There is enough free disk space.
I've tried jar xf dataset.zip. However, there's an error that push button is full, and it failed to extract all of the files.
I tried unzip, but zipfile corrupt.
Archive: dataset.zip
warning [dataset.zip]: 35141564204 extra bytes at beginning or within zipfile
(attempting to process anyway)
error [dataset.zip]: start of central directory not found;
zipfile corrupt.
(please check that you have transferred or created the zipfile in the
appropriate BINARY mode and that you have compiled UnZip properly)
I tried zip -FF dataset.zip --out data.zip, and there's an error that entry too big:
zip error: Entry too big to split, read, or write (Poor compression resulted in unexpectedly large entry - try -fz)
Is there anyway I can efficiently extract files from really large zip file?
2) extract certain files from a large zip file
If I only want some certain files from this large zip file, is there anyway I can extract only these files? For example, data1.txt from dataset.zip? It seems that I can't use any zip or unzip command (always have the zipfile corrupt problem).
Thanks!
I've solved the problem. It turns out to be a zip corruption problem. I first fixed the file with:
zip -FF filename1.zip --out filename2.zip -fz
then unzip the fixed zipfile:
unzip filename2.zip
and have successfully extracted all the files!
Many thanks to Fattaneh Talebi for the help!
you can extract specific file from zip
$ unzip -j "zipedfile.zip" "file.txt"
file.txt is the file you want to extract from zipedfile.zip
I had the similar kind of problem and it got solved by unar command.
unar file.zip
try extracting directories to retain control and know where you left off.
eg:
tar tv --wildcards -f siteRF.tar './Movies/*'
I tried all the steps mentioned above to unzip the file, but failed miserably.
My last resort was to copy my zip file (11.1GB) into a hard drive and unzip it using 7 zip on Windows 8 OS.
Worked like a charm :D
I also solved it in similar manner like Irene W did. It was a corrupted zip. I first fixed the file with:
zip -FF original_corrupted.zip --out fixed_file.zip -fz
then unzip the fixed zip file:
unzip fixed_file.zip

How to use command zip in linux that folder have short path?

I used command zip in linux (RedHat), this is my command:
zip -r /home/username/folder/compress/zip.zip /home/username/folder/compressed/*
Then, i open file zip.zip, i see architecture as path folder compress.
I want to in folder zip only consist list file *.txt
Because i used this command in script crontab hence i can't use command cd to path folder before run command zip
Please help me
I skimmed the zip man page and this is what I have found. There is not an option archive files relative to a different directory. The closest I have found is zip -j which removes the entire path and stores the files directly in the zip rather than sub directories. I do not know what happens in the case of file name conflicts such as if /home/username/folder/compressed/a.txt and /home/username/folder/compressed/subdir/a.txt both exist. If this is not a problem for you, you can use this option, but I am concerned because you did specify the -r option indicating that you expect zip to traverse sub folders.
I also thought of the possibility that your script could somehow call zip with a different working directory, but I took a look at this unix stack exchange page and it looks like their options use cd.
I have to admit I do not understand why you cannot use cd and I am very curious about it. You said something about using crontab, but I have never heard of anything wrong with changing directories in a crontab script.
I used option -j in command zip
zip -jr /home/username/folder/compress/zip.zip /home/username/folder/compressed/*
and i was yet settled this problem, thanks

Resources