2

I have a 100GB tar file of small files (each smaller than 1MB). With this file on disk, I have 20GB of free disk space left. In other words, I have enough disk space to contain the files in the tarball, but not enough to contain files + tarball.

How can I extract the files in the tarball while progressively freeing the disk space taken by the tarball?

I can access this disk from both Linux (Ubuntu) and Windows.

  • I think it's impossible, because file systems don't allow on the fly shrinking of files. Could be wrong though. – T Nierath May 26 '18 at 9:25
4

The documentation for the tar option --delete has this interesting text :

This operation will rewrite the archive. You can only use `--delete' on an archive if the archive device allows you to write to any point on the media, such as a disk; because of this, it does not work on magnetic tapes.

As this requires the media to support random reads/writes, this might with a bit of luck mean that --delete is done in-place without doing unpack in order to create a a new instance of the archive. In this case, you might unpack 20 GB of files and then delete them in order to shrink the archive. Repeat the operation five (or six) times.

I would advise to unpack the files from the end of the archive and delete them in reverse order of the archive. If tar is intelligent enough, it will just shrink the archive each time the last file in the archive is deleted, and it wouldn't this way need to copy all the following files again and again for each delete.

If this doesn't work, your only option would be to find another disk to contain the untarred files.

|improve this answer|||||
0

I know this is not an exact answer, but with the lack of good options I ended up with untar on another host, followed by using

scp -r /path/to/folder user@host:/path/to/remote

Not the best solution, but for me it worked as an acceptable workaround. I would say this would be good as a workaround for more than half of the cases where we want to use tar and remove the files simultaneously.

|improve this answer|||||

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.