LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-10-2015, 04:29 PM   #1
jzoudavy
Member
 
Registered: Apr 2012
Distribution: Ubuntu, SUSE, Redhat
Posts: 188

Rep: Reputation: Disabled
python3 extract specifc tar files


hi all

I have a bunch of tar files which I have to untar and extract specific files from them.

The problem is that the tar file structured like this:

sosreport-xx.xx.xx.xx.1-some_sort_of_hashA-some_sort_of_hashB.tar.xz
---xx.xx.xx.xx.some_sort_of_hashA
-------folders/files
-------folders/files

the xx.xx.xx.xx.some_sort_of_hashA is unique to each file and I am not sure how to include that in the path for extraction.

I want to do something like this:


x = tarfile.open(sosreport)
x.extractall(full path to the file that I want).

The problem is the with the root path always in flux I am not sure how to cut that up.

Thanks in advance for all your help
 
Old 11-10-2015, 04:40 PM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,223

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
The approach that comes to mind, for me, is to list them file paths contained in the tarball and then use os.path.basename to determine which ones you want to extract.
 
Old 11-10-2015, 10:59 PM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Use python to start find(1):

Code:
find /somepath -name 'sosreport-*.tar.xz' -exec tar xJvf {} files_to_extract \;
 
  


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
wants to extract the tar.gz files rajini23 Linux - Desktop 8 02-09-2012 11:32 AM
[SOLVED] Extract from `tar` archive as ordered in --files-from zx_ Linux - Newbie 6 02-04-2012 09:08 AM
Extract .tar.bz2 files cahardin76 Linux - Newbie 3 11-13-2010 10:35 PM
How can I extract only *.c files from a tar.gz? [KIA]aze Linux - Newbie 7 06-06-2007 04:39 AM
How to extract tar.bz2 files? akihandyman Linux - Newbie 3 12-21-2003 03:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:58 PM.

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