Extract tar.gz file and save again extracted file using Google colaboratory

Viewed 1405

I want to extract tar.gz file at google drive and then want to save it again at google drive. I am using google colaboratory. Can you give some guidance how it works

import shutil
shutil.unpack_archive("/content/gdrive/MyDrive/train_dataset.tar.gz", "/content/gdrive/MyDrive/FYP_dataset")

this one gives error No such file or directory: 'train_dataset.tar.gz'

2 Answers

If it is in your Google drive, you need to access it as follows:

from google.colab import drive
import shutil

drive.mount('/content/gdrive')
shutil.unpack_archive("gdrive/My Drive/train_dataset.tar.gz", "/content/gdrive/My Drive/FYP_dataset")

Try this code. Sometimes it may be fixed your issue. Give your file name with its destination where you want to extract the tar file in Google Drive.

Flags

  • -x : Extract a tarball.

  • -v : Verbose output or show progress while extracting files.

  • -f : Specify an archive or a tarball filename.

  • -C : Specify a different directory to extract

  • -z : Decompress and extract the contents of the compressed archive created by gzip program (tar.gz extension).

    #run this cell extract_tar.gz files
    
       !tar -xzvf "/content/drive/path/input_file_name.tar.gz" -C "/content/drive/path/output_folder/"
    
    
Related