This does not look like a tar archive - tar

[root#c0002242 lfeng]# tar -zxvf /opt/test/ALLscripts.tar.gz -C /opt/test1
tar: This does not look like a tar archive
tar: Skipping to next header
tar: Exiting with failure status due to previous errors
Could you please help me on this ?

Run the command
$ file ALLscripts.tar.gz
Compare the output, if it's gzip (as shown below) then use unzip tool to extract it
$ ALLscripts.tar.gz: gzip compressed data,from Unix

I was facing this error because my file was not downloaded yet and I was trying to extract it :).

Related

Bypass `-C` flag when unzipping tar archive

I have a .tar.gz archive with the following structure:
opt/client/py/utils/mappings/templates/config.json
opt/
opt/mag/
opt/mag/sw/
opt/mag/sw/apps/
opt/mag/sw/apps/service/
opt/mag/etc/
opt/mag/etc/service.environment
opt/mag/etc/service.toml
And this .tar.gz archive is extracted using this command:
tar -zxf ../service.tar.gz -C opt/mag/ --strip-components=2
Thee issue is this will extract the opt/client/py/utils/mappings/templates/config.json file inside opt/mag so it will become: opt/mag/py/utils/mappings/templates/config.json which is obviously wrong. Notice the removal of opt/client/ by --strip-components=2.
The issue is that I cannot change the unzip command
I've tried to hack it around by inserting 2 dummy directories to bypass --strip-components=2 something like this:
dummy1/dummy2/opt/client/py/utils/mappings/templates/config.json
opt/
opt/mag/
opt/mag/sw/
opt/mag/sw/apps/
opt/mag/sw/apps/service/
opt/mag/etc/
opt/mag/etc/service.environment
opt/mag/etc/service.toml
This way --strip-components=2 will remove dummy1/dummy2 and the config file will be extracted to /opt/mag/opt/client/py/utils/mappings/templates/config.json which is still wrong, because that -C opt/mag will force the extraction inside opt/mag.
Given the fact that I cannot change the unzip command is there anyway to bypass the -C switch or some way to hack it around?
Also, I cannot edit or move files on the container where this archive is extracted

How to create tar file with 7zip

I'm trying to create a tar file on windows using 7zip.
Most of the documents I found said to do something like this:
7z a -ttar -so dwt.tar dwt/
But when I tried to run it I got this error:
Command Line Error:
I won't write compressed data to a terminal
I'm currently using 7-Zip [64] 16.04
Any idea?
On Linux:
tar cf - <source folder> | 7z a -si <Destination archive>.tar.7z
from here
On Windows:
7za.exe a -ttar -so archive.tar source_files | 7za.exe a -si archive.tgz
from here.
I managed to do that making simply, with 7zip installed:
Right click on the folder you want to compress
Choose -7zip/add to file
Once there, on the new screen, on file type, you can choose 7z/tar/wim/zip
Choose tar, and there you go :)
From the manpage:
-so Write data to stdout (e.g. 7z x -so directory.tar.7z | tar xf -)
It does what you told it to. 7z can guess archive format from the file extension so it's enough to use
7z a archive.tar input/
To further compress as gzip you can use a pipe and a combination of stdin and stdout flags like in Tu.Ma.'s answer.

How do I untar a tar file containing the tar program?

I have downloaded tar-latest.tar.gz from gnu. I have unzipped it; now I have to untar it. But how can I do that, when the only tar program I have is the one in tar-latest?
Use the command
tar -xvf filename.tar
Reference : http://www.tecmint.com/18-tar-command-examples-in-linux/
You can download tar for windows not packed in tar archive from http://gnuwin32.sourceforge.net/packages/gtar.htm
Binaries Setup 1331695 3 October 2003
http://gnuwin32.sourceforge.net/downlinks/tar-bin.php
or tar for ms-dos (exe): http://ftp.gnu.org/gnu/tar/tar-1.12.msdos.exe
or package which includes tar: http://unxutils.sourceforge.net/
or any freeware archiver capable of opening tar archives: 7-zip.org, peazip.org
(Best and easier way is 7-zip.org or peazip.org)

How to tar my C++ files on a linux server?

I know this is a simple question, but I'm not sure why the tar process isn't working and I can't find a definitive answer on here. When doing the tar command:
tar -cvjf<assign2comp.tar.bz2> <assign2.cpp header.cpp header.h>
I'm getting the error, Missing name for redirect.
Our professor shows this code as the example so I'm not sure what I'm doing wrong.
tar -cvjf<filename.tar.bz2> <files you want in archive>
Then to extract:
tar -jxvf filename.tar.bz2
So I want to archive the assign2.cpp header.cpp and header.h files then test the extract command to make sure I can access them.
Thanks for the help!
drop the < and > characters from commands. e.g. tar -cvjf assign2comp.tar.bz2 assign2.cpp header.cpp header.h
When you were told to use <file> it means to write your filename there, without < and >. So:
tar -cvjf assign2comp.tar.bz2 assign2.cpp header.cpp header.h
This is a common convention on Unix: <file> means a filename is required, [host] means a host is optional, and so on.

tar: This does not look like a tar archive

I split a huge folder:
tar cvpf - somedir | split -b 50000m
I then transfered split files to another server and merge it:
cat x* > somedir.tar.gz
but when I tried to extract the file it shows errors:
tar xvf tar xvf somedir.tar.gz tar: This does not look like a tar
archive tar: Skipping to next header tar: Archive contains obsolescent
base-64 headers tar: Error exit delayed from previous errors
How to fix this problem?
It is not guaranteed that x* will expand to the same order in which the files are split. Assuming the file is split into three chunks then the first chunk would have the tar(1) header so you'll have to assemble them back in the same way.
Use ls(1) with the -t option to concatenate the files in that order.
Hope that helps.

Resources