Skip to main content
Notice removed Draw attention by CommunityBot
Bounty Ended with no winning answer by CommunityBot
Notice added Draw attention by BrainStone
Bounty Started worth 50 reputation by BrainStone
Added second related question
Source Link
BrainStone
  • 3.8k
  • 12
  • 41
  • 58

I have a tar file that contains some files in a folder named old_name. Now I'd like to create a new tar file where that folder has been renamed to new_name without extracting to file to disk as that would be significantly slower for large archives (More than double the disk reads and writes).
I know how to do that: tar -xf old.tar; tar -cf new.tar --transform 's/old_name/new_name/' old_name

I've tried a few things but none seemed to work:

  • tar -cOf old.tar | tar -xf new.tar --transform 's/old_name/new_name/'
  • cat old.tar | tar --delete --transform 's/old_name/new_name/' > new.tar
  • cat old.tar | tar -u --transform 's/old_name/new_name/' > new.tar

But nothing seems to work.

Closed I've found are these:

But those are about removing files in the tarball, not changing their paths.

I have a tar file that contains some files in a folder named old_name. Now I'd like to create a new tar file where that folder has been renamed to new_name without extracting to file to disk as that would be significantly slower for large archives (More than double the disk reads and writes).
I know how to do that: tar -xf old.tar; tar -cf new.tar --transform 's/old_name/new_name/' old_name

I've tried a few things but none seemed to work:

  • tar -cOf old.tar | tar -xf new.tar --transform 's/old_name/new_name/'
  • cat old.tar | tar --delete --transform 's/old_name/new_name/' > new.tar
  • cat old.tar | tar -u --transform 's/old_name/new_name/' > new.tar

But nothing seems to work.

I have a tar file that contains some files in a folder named old_name. Now I'd like to create a new tar file where that folder has been renamed to new_name without extracting to file to disk as that would be significantly slower for large archives (More than double the disk reads and writes).
I know how to do that: tar -xf old.tar; tar -cf new.tar --transform 's/old_name/new_name/' old_name

I've tried a few things but none seemed to work:

  • tar -cOf old.tar | tar -xf new.tar --transform 's/old_name/new_name/'
  • cat old.tar | tar --delete --transform 's/old_name/new_name/' > new.tar
  • cat old.tar | tar -u --transform 's/old_name/new_name/' > new.tar

But nothing seems to work.

Closed I've found are these:

But those are about removing files in the tarball, not changing their paths.

Source Link
BrainStone
  • 3.8k
  • 12
  • 41
  • 58

Modify file names in tar file without extracting files to temporary location

I have a tar file that contains some files in a folder named old_name. Now I'd like to create a new tar file where that folder has been renamed to new_name without extracting to file to disk as that would be significantly slower for large archives (More than double the disk reads and writes).
I know how to do that: tar -xf old.tar; tar -cf new.tar --transform 's/old_name/new_name/' old_name

I've tried a few things but none seemed to work:

  • tar -cOf old.tar | tar -xf new.tar --transform 's/old_name/new_name/'
  • cat old.tar | tar --delete --transform 's/old_name/new_name/' > new.tar
  • cat old.tar | tar -u --transform 's/old_name/new_name/' > new.tar

But nothing seems to work.