Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6379309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:07:16+00:00 2026-05-25T02:07:16+00:00

I am using python tarfile module to extract files from a *.tgz file. Here

  • 0

I am using python tarfile module to extract files from a *.tgz file. Here what I use:

import tarfile
tar = tarfile.open("some.tar")
tar.extractall(".")
tar.close()

Assume “some.tar” contents as:

-a.txt ===> user:usr1 , group: grp1
-b.txt ===> user:usr2 , group: grp2

But after extracting I lose all of user,group,date… information. They now belong to whoever calls the script(in my case root). They become like:

-a.txt ===> user:root , group: root
-b.txt ===> user:root , group: root

Is there a way to keep file owner,date information of files?

From tarfile module page:

–handles directories, regular files, hardlinks, symbolic links, fifos, character devices and block devices and is able to acquire and restore file information like timestamp, access permissions and owner.

From this statement I understand that is is very well possible to do this by “tarfile” module, or do I understand it wrong?

Python version is 2.6.1

Edit: I am running this script as root

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:07:17+00:00Added an answer on May 25, 2026 at 2:07 am

    As guettli says, you have to be root to be able to change the ownership of a file to somebody else. Otherwise, you open a huge security hole. This is true when using the tar(1) program or when trying to use the tarfile package from python.

    Note, though, that some earlier version of Python have a bug (see issue in comments below) that means files extracted by root are owned by root instead of the real owner (user and group).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to use Python's tarfile module to extract a tar.gz archive. I'd like
Using python 2.6.5, I can use the with statement without calling from __future__ import
I'm using zipfile and tarfile Python modules to open, extract and compress archives. I
Using Python, how would I go about reading in (be from a string, file
I have a large tar.gz file to analyze using a python script. The tar.gz
Using python to pick it some pieces so definitely a noob ? here but
Using Python's Imaging Library I want to create a PNG file. I would like
Using Python module re, how to get the equivalent of the \w (which matches
Using Python, how does one parse/access files with Linux-specific features, like ~/.mozilla/firefox/*.default ? I've
Using python and wsgiref.handlers, I can get a single variable from a form with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.