There is a file with the name **flag_999.tar.gz** which has been packed maybe 999 times is there any way of unpacking all of them or a bash script because nothing is working for me.

The name is the file goes as flag_999.tar.gz and inside the archive, there is flag_998.tar.gz and inside that there is flag_997.tar.gz. So here the "flag_" is constant and then the number goes descending I reached flag_967.tar.gz manually to check the file names inside.

I tried:

file=(*tar); while [[ -e $file ]]; do tar zxf "$file"; rm "$file"; file=(*tar); done

no output

awk -F'\0' '/[^\0]/{print $(NF)}' flag_999.tar.gz

output not readable

for i in {1000..1}; do tar -xf $i.tar; done

maybe this could work I don't know because I don't know how to use it.

Click here to see and download the file https://drive.google.com/file/d/1ycWVR0htwFyexCJRohTGHio4UFdvGuPW/view?usp=sharing

  • 1
    Does this answer your question? How to repeatedly un tar files that are within the tar itself
    – Panki
    Jun 21 '21 at 12:43
  • You will have to use -xzf instead of -xf obviously
    – Panki
    Jun 21 '21 at 12:44
  • no tried them all
    – farzan
    Jun 21 '21 at 12:44
  • Unlikely, and even if you did, you should edit your question and provide the details of what you tried and how it failed
    – Panki
    Jun 21 '21 at 12:45
  • What I flagged as dupe is the solution - you just need to do a little transfer exercise, because your files are named differently. Also, you should try to understand what it does, not blindly copy-paste and execute it.
    – Panki
    Jun 21 '21 at 13:03

With the GNU implementation of tar, you could write an extract script like:

#! /bin/sh -
PROGNAME="$0" exec tar -zxvvf - --to-command='
  case "$TAR_FILENAME" in
    (*.tar.gz | *.tgz) exec "$PROGNAME";;
    (*) set -o noclobber
        mkdir -p -- "$(dirname -- "$TAR_FILENAME")" &&
          exec cat > "$TAR_FILENAME"
  esac' 3<&-

To be invoked as:

path/to/extract < flag_999.tar.gz

in your case.

That script will call itself recursively via tar's --to-command for each archive member whose name ends in .tar.gz or .tgz. It will extract files on the fly without storing the intermediate tar files on disk.

Note that it only extracts regular files and doesn't restore any file metadata.

  • Sorry I tried the above script but it didn't work.
    – farzan
    Jun 27 '21 at 5:28
  • @farzan In which way did it not work? Jun 27 '21 at 5:38
  • @farzan, FWIW, that script works for me (in that it eventually extracts the contents of flag.txt) on your file with GNU tar 1.34 on Debian GNU/Linux. Jun 27 '21 at 6:36
  • ./script.sh: 2: exec: /home/rasiq/Downloads/flag_999.tar.gz: Permission denied Even after chmod +x
    – farzan
    Jun 29 '21 at 5:31
  • @farzan, did you start it as ./script.sh < /home/rasiq/Downloads/flag_999.tar.gz? Though even if you didn't, I can't see how you could get that error message with this script as written. Jun 29 '21 at 5:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.