My gunzip structure is like something like this
archive.tgz/manager-34038240834402384/temp1
/temp2/temp4/temp5
/temp3/temp6
I just need the string 'manager-34038240834402384' without extracting whole bundle. How to get it?
I tried tar -tvf which gives me whole path, but I just want above string. How to get it?
tar --list -f archive.tgz | head -n 1
Related
Check the Size of the tar, tar.gz and tar.bz2 Archive File.
To check the size of any tar, tar.gz and tar.bz2 archive file, use the following command. For example the below command will display the size of archive file in Kilobytes (KB).
tar -czf - tecmint-14-09-12.tar | wc -c
12820480
tar -czf - MyImages-14-09-12.tar.gz | wc -c
112640
tar -czf - Phpfiles-org.tar.bz2 | wc -c
20480
What does " - " do in this Command not able to find anything related to it in Official tar Documentation : ref 18
- is the option value for the -f option, which is the filename of the output file, normally a tgz filename.
- is special in that many tools accept it as an alias for stdout, which is in this case a pipe to wc -c. Remove the wc and you'll see it "messes up" your terminal
PS: it seems not documented in the tar man page, imo it should.
I have an archive named compressed.tar.gz
I want to exract its contents to the folder uncompressed, located in the same directory.
In terminal:
tar -xf compressed.tar.gz -C uncompressed
This works and extracts correctly, however I get an stderror: "Removing leading "/" from member names". I've running above command using -P to suppress the error message as so:
tar -Pxf compressed.tar.gz -C uncompressed
Although the contents are not being extracted at all to uncompressed folder. Any ideas would be greatly appreciated.
Is there a way to append a file into a specific dir inside a tar file?
I have dir1/TarFile.tar. Inside the TarFile.tar there is dir2.
I want to append file.txt (in dir 1) to TarFile.tar under dir2.
Thanks in advance.
As far as i know you can't do this on the fly. You can create directory dir2, move there the file file.txt and update the archive:
cd dir1
mkdir -p dir2
mv file.txt dir2/
tar uvf TarFile.tar dir2/file.txt
I'm trying to script the download of the node.js source and corresponding SHASUMS256.txt, checksum it, grep for OK, and return no results just exit code 0 on success using grep's -q flag:
wget http://nodejs.org/dist/latest/node-v0.10.26.tar.gz
wget http://nodejs.org/dist/latest/SHASUMS256.txt
sha256sum -c SHASUMS256.txt|grep -q OK
However, grep is returning a selection of the non-matching lines "no such file or directory" errors (though not all, confusingly):
> sha256sum -c SHASUMS256.txt|grep -q OK
sha256sum: node-v0.10.26-darwin-x64.tar.gz: No such file or directory
sha256sum: node-v0.10.26-darwin-x86.tar.gz: No such file or directory
sha256sum: node-v0.10.26-linux-x64.tar.gz: No such file or directory
sha256sum: node-v0.10.26-linux-x86.tar.gz: No such file or directory
sha256sum: node-v0.10.26-sunos-x64.tar.gz: No such file or directory
sha256sum: node-v0.10.26-sunos-x86.tar.gz: No such file or directory
sha256sum: node-v0.10.26-x86.msi: No such file or directory
sha256sum: node-v0.10.26.pkg: No such file or directory
sha256sum: node.exe: No such file or directory
Any idea what the problem is here? All I want from this script is return code 0 if the checksum succeeds (eg grep matches OK), or return code non-0 if it fails.
When you pipe the output of a command as input to other command, only stdout of first command is passed as stdin to the second command.
The lines you see are sent by the sha256sum program to stderr.
You can verify that by sending stderr of sha256sum command also to grep by
sha256sum -c SHASUMS256.txt 2>&1 |grep -q OK
Hope that helps.
I have the directory A/a A/b where both a and b are files.
When I run these commands I get the outputs.
-> tar --include A -v -cf A.tar A
a A
a A/a
a A/b
-> tar --include A/a -v -cf A.tar A
I don`t understand in the 2nd evocation why file A/a is not archived. I believe I do not understand how include works.
I am trying to give tar a list and have it create an archive with the contents. Please help.
Thank you.