LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-25-2010, 09:35 AM   #1
networkingnub
LQ Newbie
 
Registered: Jul 2009
Posts: 16

Rep: Reputation: 0
Not allowed to Unzip a file in DIR. -


Hello again;

I have a problem where I have certain foo.tgz files that are to big to gunzip in a directory, the box that it is on has limited space in /var/tmp for all intents and purposes. I did the standard gunzip -l to see how big the file was.

How can I look in the .tgz to see what files are there and pull out only the ones that I need. tar -t foo.tgz doesn't seem to work or am I doing something wrong?

Once I do find the file how do I only extract the one file from the .tgz, remember I can't uncompress the entire foo.tgz
 
Old 02-25-2010, 09:41 AM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
You should be able to list the files with
Code:
tar tzf foo.tgz
You can extract a specific file with
Code:
tar xzf too.tgz  some/file/listed/in/previous/command
You can unzip the file to a differnt location with
Code:
cd /some/dir
tar xzf /var/tmp/foo.tgz
HTH,

Evo2
 
1 members found this post helpful.
Old 02-25-2010, 10:07 AM   #3
networkingnub
LQ Newbie
 
Registered: Jul 2009
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by evo2 View Post
You should be able to list the files with
Code:
tar tzf foo.tgz
You can extract a specific file with
Code:
tar xzf too.tgz  some/file/listed/in/previous/command
You can unzip the file to a differnt location with
Code:
cd /some/dir
tar xzf /var/tmp/foo.tgz
HTH,

Evo2
Is there a way to look at the contents of one of the files, when you run the second command, for lets say a string of characters, that way I can then uncompress just that one file for what I need?
 
Old 02-25-2010, 10:28 AM   #4
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Quote:
Originally Posted by networkingnub View Post
Is there a way to look at the contents of one of the files, when you run the second command, for lets say a string of characters, that way I can then uncompress just that one file for what I need?
Not really sure what you mean here. I'm assuming that the file you want to look at is just a text file and you want to read what is in it without actually extracting it. In that case I think you can pass tar the -O flag to pipe it to std out. For example:

Code:
tar Oxzf foo.tgz /the/file/to/read | less
Please note that I've not personally used this stdout feature of tar in this way before.

Evo2.
 
1 members found this post helpful.
Old 02-25-2010, 10:36 AM   #5
JimBrewster
Member
 
Registered: Feb 2010
Location: usa:/dev/random
Distribution: Slackware-15.0; -current
Posts: 245

Rep: Reputation: 60
GNU Emacs can read the contents of tarballs. Just open the tar file as a buffer and it will look like a directory listing. You can navigate just like a regular directory tree and read text files. Works by default in Slackware, and I assume other standard distros.
 
1 members found this post helpful.
Old 02-25-2010, 11:45 AM   #6
networkingnub
LQ Newbie
 
Registered: Jul 2009
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by JimBrewster View Post
GNU Emacs can read the contents of tarballs. Just open the tar file as a buffer and it will look like a directory listing. You can navigate just like a regular directory tree and read text files. Works by default in Slackware, and I assume other standard distros.
Thank again, I greatly appreciate your efforts and time helping me with my nubness :-)

Essentially, it is all text in the foo.tgz file. When it's uncompressed it's actually about 200 files in one directory /foodir/foo1 /foodir/foo2 /foodir/foo3 etc etc... Those foo files have strings or text that I need to look up exact matches for. So if I zgrep/grep 'blahblahblah' in foo3 I have to go in to foo3 after I've completed all my searches to do additional work there.

The problem as stated in my earlier posts is I cannot uncompress the file. I will look at Emacs. Is there any addition points you can add in regards to Emacs, especially you're comments about the buffer.
 
Old 02-25-2010, 11:51 AM   #7
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
A versatile tool on most Linux is 'lesspipe.sh'
( 'lesspipe' on Debian / Ubuntu ).

'lesspipe <any-compressed-package>
.. will show content from .tar.gz , .rpm , .deb , etc.
.. .....
 
1 members found this post helpful.
Old 02-25-2010, 11:53 AM   #8
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
How about a simple script that unpacks one file at a time to stdout and is then greped for your searchsting?

Here is an untested example:
Code:
for f in $(tar tzf foo.tar.gz) ; do
   tar Oxzf foo.tar.gz $f | grep searchstring && echo "Found in $f"
done
Evo2.
 
1 members found this post helpful.
Old 02-25-2010, 11:55 AM   #9
networkingnub
LQ Newbie
 
Registered: Jul 2009
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by evo2 View Post
Not really sure what you mean here. I'm assuming that the file you want to look at is just a text file and you want to read what is in it without actually extracting it. In that case I think you can pass tar the -O flag to pipe it to std out. For example:

Code:
tar Oxzf foo.tgz /the/file/to/read | less
Please note that I've not personally used this stdout feature of tar in this way before.

Evo2.

Actually this helps out a lot

tar Oxzf FOO.tgz | grep 'SOME LINE OF TEXT I NEED TO EXTRACT'

It sends me the type of information I need to standard output which is GREAT!!! However is there a way for it to tell me what the filename 'SOME LINE OF TEXT I NEED TO EXTRACT' is located in?
 
Old 02-25-2010, 12:03 PM   #10
JimBrewster
Member
 
Registered: Feb 2010
Location: usa:/dev/random
Distribution: Slackware-15.0; -current
Posts: 245

Rep: Reputation: 60
Quote:
Originally Posted by networkingnub View Post
Thank again, I greatly appreciate your efforts and time helping me with my nubness :-)

Essentially, it is all text in the foo.tgz file. When it's uncompressed it's actually about 200 files in one directory /foodir/foo1 /foodir/foo2 /foodir/foo3 etc etc... Those foo files have strings or text that I need to look up exact matches for. So if I zgrep/grep 'blahblahblah' in foo3 I have to go in to foo3 after I've completed all my searches to do additional work there.

The problem as stated in my earlier posts is I cannot uncompress the file. I will look at Emacs. Is there any addition points you can add in regards to Emacs, especially you're comments about the buffer.
Yeah, let me just clarify the "buffer" thing if I can...

Just start emacs from your desktop. It might be under "editors," "programming," or "development," depending on your desktop. The emacs window will open with a splash screen and some hints. There are a million keyboard shortcuts, but there is also a menu bar. Select "Open buffer" from the file menu or type Ctrl-x f. You can then enter the path to your tarball, or just hit enter and you'll get a directory listing of your home directory that looks a bit like the output of 'ls -al', from which you can navigate to anywhere in the filesystem.

Another cool thing is that you can run shell commands inside emacs, which may be useful in your case to grep around in your tarball.

HTH
 
Old 02-25-2010, 12:09 PM   #11
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Quote:
Originally Posted by networkingnub View Post
It sends me the type of information I need to standard output which is GREAT!!! However is there a way for it to tell me what the filename 'SOME LINE OF TEXT I NEED TO EXTRACT' is located in?
See post #8, which I guess appeared as you were typing the above. The key here is that only one file at a time is extracted.

Cheers,

Evo2.
 
Old 02-25-2010, 12:47 PM   #12
networkingnub
LQ Newbie
 
Registered: Jul 2009
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by evo2 View Post
See post #8, which I guess appeared as you were typing the above. The key here is that only one file at a time is extracted.

Cheers,

Evo2.
I think I might have made a mistake and generalized the directory structure. The loop ends up showing the FOO-TOP-DIR. But then again I could have screwed up.

FOO-TOP-DIR-

-FOODIR1
-FILENAME1
-FILENAME2
-FILENAME3
-FOODIR2
-FILENAME1
-FILENAME2
-FILENAME3
-FOODIR3
-FILENAME1
-FILENAME2
-FILENAME3

Yeah I posted at the same time of your response :-)

Last edited by networkingnub; 02-25-2010 at 12:49 PM.
 
Old 02-25-2010, 01:20 PM   #13
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
I just tested the code I posted, and can see now that it won't work. I can't think of a good solution using the -O flag for tar.

You could just untar one file at a time, grep it and if the match is not found, delete it. I guess that would look something like:
Code:
for f in $(tar tzf foo.tgz) ; do
    tar xzf foo.tgz $f
    grep "thing to look for" $f || rm $f
done
This should leave you with all the files that have that string, and a bunch of empty directories. Not ideal, but a step in the right direction.

Again this is untested, and perhaps somewhat dangerous since it contains an "rm". USE WITH EXTREME CARE.

Evo2.
 
Old 02-25-2010, 01:37 PM   #14
networkingnub
LQ Newbie
 
Registered: Jul 2009
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by evo2 View Post
I just tested the code I posted, and can see now that it won't work. I can't think of a good solution using the -O flag for tar.

You could just untar one file at a time, grep it and if the match is not found, delete it. I guess that would look something like:
Code:
for f in $(tar tzf foo.tgz) ; do
    tar xzf foo.tgz $f
    grep "thing to look for" $f || rm $f
done
This should leave you with all the files that have that string, and a bunch of empty directories. Not ideal, but a step in the right direction.

Again this is untested, and perhaps somewhat dangerous since it contains an "rm". USE WITH EXTREME CARE.

Evo2.
Yes and as such I cp the file to another directory, but this is actually a valid approach also, geeze you guys know how to use all the options available, really should look at learning more shell script related stuff
 
Old 02-25-2010, 05:08 PM   #15
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
These may prove useful:
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the difference between using "jar xvf" and "unzip" to unzip the zip-file? thomas2004ch Linux - Newbie 4 08-27-2009 05:11 AM
Compress dir keep file/dir permissions powadha Linux - General 1 11-14-2006 07:07 PM
how to unzip a zip file on a selected dir in linux ? sunlinux Linux - Software 1 06-12-2006 04:52 AM
how do i unzip a .gz file? xstealthrtx Linux - General 3 01-20-2005 12:26 PM
httpd one dir allowed and no others korozion Linux - Software 4 12-22-2004 05:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration