Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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?
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.
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.
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.
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?
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.
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.
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.