Untar *.tar.bz2 using 7-zip on windows command line - windows

I have a function in a powershell script that is supposed to untar my CppUnit.tar.bz2 file. I have installed 7-zip, and in my function I have the following:
Function untar ($targetFile) {
$z ="7z.exe"
$defaultDestinationFolder = 'C:\Program Files\'
$destinationFolder = (Get-Item $defaultDesitantionFolder).fullname
$tarbz2Source = $targetFile
& "$z" x -y $tarbz2Source
$tarSource = (get-item $targetFile).basename
& "$z" x -y $tarSource -o $destinationFolder
Remove-Item $tarSource
}
Running this extracts all the files where I want them, BUT all the files get ",v" as their ending:
...
Extracting cppunit-cvs-repo-archive\cppunit\cppunit\Attic
Extracting cppunit-cvs-repo-archive\cppunit\cppunit\Attic\estring.h,v
Extracting cppunit-cvs-repo-archive\cppunit\cppunit\Attic\TestSuite.h,v
Extracting cppunit-cvs-repo-archive\cppunit\cppunit\Attic\Test.h,v
Extracting cppunit-cvs-repo-archive\cppunit\cppunit\Attic\TestCase.h,v
Extracting cppunit-cvs-repo-archive\cppunit\cppunit\Attic\TextTestResult.h,v
Extracting cppunit-cvs-repo-archive\cppunit\cppunit\Attic\Makefile.am,v
Extracting cppunit-cvs-repo-archive\cppunit\cppunit\Attic\TestSuite.cpp,v
Extracting cppunit-cvs-repo-archive\cppunit\cppunit\Attic\Exception.cpp,v
Extracting cppunit-cvs-repo-archive\cppunit\cppunit\Attic\cppunit.dsw,v
Extracting cppunit-cvs-repo-archive\cppunit\cppunit\Attic\TestFailure.h,v
Extracting cppunit-cvs-repo-archive\cppunit\cppunit\Attic\TestCaller.h,v
Extracting cppunit-cvs-repo-archive\cppunit\cppunit\Attic\TestResult.h,v
Extracting cppunit-cvs-repo-archive\cppunit\cppunit\Attic\TextTestResult.cpp,v
Extracting cppunit-cvs-repo-archive\cppunit\cppunit\Attic\TestRegistry.h,v
Extracting cppunit-cvs-repo-archive\cppunit\cppunit\Attic\TestFailure.cpp,v
Extracting cppunit-cvs-repo-archive\cppunit\cppunit\Attic\Exception.h,v
Extracting cppunit-cvs-repo-archive\cppunit\cppunit\Attic\TestRegistry.cpp,v
Extracting cppunit-cvs-repo-archive\cppunit\cppunit\Attic\cppunit.dsp,v
Extracting cppunit-cvs-repo-archive\cppunit\cppunit\Attic\TestResult.cpp,v
Extracting cppunit-cvs-repo-archive\cppunit\cppunit\Attic\TestCase.cpp,v
Everything is Ok
Folders: 149
Files: 1128
Size: 20671974
Compressed: 21626880
Can anyone tell me how I can fix this?

The ,v suffix indicates that these are not the files themselves, but version history files maintained by CVS - each ,v file contains not only the latest version of the file, but the deltas to reconstruct any previous version of the file. The fact that they're all in an Attic subdirectory indicates that they were all removed via cvs remove at some point. These and the fact that the base directory is cppunit-cvs-repo-archive says you need to treat the unpacked archive as a CVS repository, and use the appropriate tools to check out the files you want to work with, not just "fix" what looks like wrong names...

Related

Want to grep in .tar.gz file in Solaris

i have a file in .tar.gz format in solaris. i want to grep some line from that. i am using zipgrep command but unable to find the line. Below is my sample file and command that i am using.
Sample file:
BD201701.tar.gz
BD201702.tar.gz
BD201703.tar.gz
i am using below command to search a line that contains bangladesh.
zipgrep 'bangladesh' BD2017*
But it;s showing below error.
[BD201701.tar.gz]
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
zipinfo: cannot find zipfile directory in one of BD201701.tar.gz or
BD201701.tar.gz.zip, and cannot find BD201701.tar.gz.ZIP, period.
/usr/bin/zipgrep: test: argument expected
zipgrep has been made for processing PKZIP archive files. In PKZIP archives the compression is applied individually on each contained file, so the process boils down to a sequence of operations like this (not actual code!):
foreach file in archive:
unzip file to tmpfile
grep tmpfile
A compressed tar archive is different. First you pack a large bunch of files into an archive, and then the compression is applied to the whole bunch. So to search inside that the whole archive has to be unpacked first, i.e. something like this (pseudocode again):
make and change to temporary directory
tar -xZf ${archive}
grep -R ${seachstring} ./
However a tar archive itself is just a bunch of files "glued" together, with some information about their filename and size inbetween. So you could simply decompress the archive into a pipe, disregarding file spearation and search through that
zcat file | grep
zgrep does not work on solaris servers. In case the requirement is to find a pattern in a/all file(s) inside a directory given that the files are zipped, the following command can be used.
gzgrep 'pattern' filename
or
gzgrep 'bangladesh' BD2017*
use zgrep:
zgrep 'bangladesh' BD2017*

Extracting specific files with file extension from a .tar.xz archive using MacOS terminal

I have a number of compressed archives with the extension .tar.xz. I am advised that, when decompressed, the total size required is around 2TB.
Within the archives are a number of images that I am solely after.
Is there a method to solely extract files for example with the extensions .jpeg, .jpeg and .gif from the compressed archives without having to extract every file?
Thanks
It's trivial to just extract one of the file types; for example:
tar -xjf archive.tar.xz '*.jpeg'
will extract all files with the .jpeg extension. It's important to quote the *, as otherwise the shell would attempt to expand it, and would only try to match only the files that were found (or fail because there were no files with that name).
You can similarly use other patterns like '*.gif', or both together:
tar -xjf archive.tar.xz '*.jpeg' '*.gif'
Because you tag that you're using OSX, I'll skip the need to use the --wildcards option, which is needed when trying to extract only those files under linux.

Create a .tar.bz2 file given an array of files

In a Bash script, I have an array that contains a list of files (in the form of their complete file paths):
declare -a individual_files=("/path/to/a" "/path/to/b" "/path/to/c")
I want to create a compressed file in tar.bz2 which contains all the files in the array, using tar command.
So far, I have tried
tar rf files.tar "${individual_files[#]}"
tar cjf files.tar.bz2 files.tar
But for some reason, files.tar.bz2 always contains the last file in the array only.
What is the correct command(s) for doing so, preferably without creating the intermediate .tar file?
UPDATED: using #PanRuochen's answer, this is what I see in the verbose info:
+ tar cfvj /Users/skyork/test.tar.bz2 /Users/skyork/.emacs /Users/skyork/.Rprofile /Users/skyork/.aspell.en.pws /Users/skyork/.bash_profile /Users/skyork/.vimrc /Users/skyork/com.googlecode.iterm2.plist
tar: Removing leading '/' from member names
a Users/skyork/.emacs
a Users/skyork/.Rprofile
a Users/skyork/.aspell.en.pws
a Users/skyork/.bash_profile
a Users/skyork/.vimrc
a Users/skyork/com.googlecode.iterm2.plist
But still, the resulted test.tar.bz2 file has only the last file of the array (/Users/skyork/com.googlecode.iterm2.plist) in it.
My bad, the files are indeed there but hidden.
tar cfvj files.tar.bz2 "${individual_files[#]}"
v should give you verbose information about how bz2 file is created.

How to extract a specific folder using IZARC (IZARCe)

I want to extract a specific directory form a huge zip file (>5GB) that is somewhat corrupted because of an inevitable bad maintained build system that creates the zip.
The tools such as winrar/7Zip GUI apps have no issues extracting the files, but some command line tools such as mks unzip and 7za fails to extract from the corrupted archive.
After a lot of digging around and trying out many such command line utilities I found out that IZARC successfully extracts files from the archive.
I am running the following command:
IZARCe.exe -e -d -o D:\aHugeZipFile.zip -pD:\temp #"source.txt"
The listing file source.txt contains just one entry:
source/lib/*
which is the only directory in the archive, from where the contents are to be extracted.
But, it is resulting in:
IZArc Command Line Extraction Add-On Version 1.1 (Build: 130)
Copyright(c) 2007 Ivan Zahariev, All Rights Reserved.
http://www.izarc.org contact#izarc.org
Archive File: aHugeZipFile.zip
WARNING: Nothing to do!
I have tried specifying:
/source/lib/*
source/lib/*
source/lib/
source/lib
*source/lib/*
in the listing file, all to no avail! :(
Any pointers on where the error is occurring, and how to fix the issue will be of great help. Thank you in advance!
Using relative or absolute paths for listfiles doesn't appear to work with IZArc. Try using wildcards such as ., *.doc, etc instead of paths in the listfile. Be aware that there appears to be a limitation for the folder depth that IZArc will extract to as well as a tendency to generate CRC errors when files with the same name are present in the same archive, even if they are in different directories.
I would suggest using 7-Zip command-line instead. It can recurse deeply through a file structure without error and can use relative directories and wildcards in its listfiles.
The following 7-Zip command was tested and worked perfectly.
7za x somearchive.zip -o"C:\Documents and Settings\me\desktop\temp_folder\test2" -ir#source.txt -aoa -scsWIN
the source.txt file may contain contain a combination of relative paths and/or wildcards on separate lines such as:
Output/, Folder2/, *, or *.doc.
In the command above: x (extract with full paths), -ir (include filenames, recurse subdirectories), -aoa (overide existing files without prompt), -scsWIN (set charset for list files). You may need to adjust these commands for your situation.

how to split/rejoin the zip file using ruby

i am new to Ruby. Is there any way to split a large zip file & then again join the split files to one large zip file?
i can see a link with split sample, but can see an error while running(split object error)
split sample link
Can anyone help me in SPlit/join the zip filesin ruby?
The Zip::ZipFile.split isn't available in the latest rubyzip version 0.9.9. It exists only in the latest master branch of the source code. If you're finding a way to split a large file into small parts and join them later, or rather, you don't rely on the intermediate split results, you can try split of Unix/Linux. E.g. you want to use a USB drive to copy the small files and join them in another computer.
# each file will contain 1048576 bytes
# the file will be splitted into xaa, xab, xac...
# You can add optional prefix to the end of the command
split -b 1048576 large_input_file.zip
# join them some where after
cat x* >large_input_file.zip
The rubyzip gem provides a way to create multi-part zip files from a large zip file. You can use p7zip or WinRAR to unzip the split zip file parts. However, it's strange that unzip doesn't support multi-part zip files. The manual of unzip says,
Multi-part archives are not yet supported, except in conjunction with zip. (All parts must be concatenated together in order, and then zip -F'' (for zip 2.x) orzip -FF'' (for zip 3.x) must be performed on the concatenated archive in order to fix'' it. Also, zip 3.0 and later can combine multi-part (split) archives into a combined single-file archive usingzip -s- inarchive -O outarchive''. See the zip 3 manual page for more information.) This will definitely be corrected in the next major release.
If you want this, you can clone the latest master branch and use that lib to do the job.
$ git clone https://github.com/aussiegeek/rubyzip.git
$ vim split.rb
Then in your ruby file "split.rb":
$:.unshift './rubyzip/lib'
require 'zip/zip'
part_zip_count = Zip::ZipFile.split("large_zip_file.zip", 102400, false)
puts "Zip file splitted in #{part_zip_count} parts"
You can checkout the docs for split

Resources