Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to rename files you put into a tar archive using linux 'tar'

Tags:

People also ask

How do I rename a Linux archive file?

The traditional way to rename a file is to use the mv command. This command will move a file to a different directory, change its name and leave it in place, or do both.

What does the command tar XVZF * .tar do?

The xvf flag is used to extract the files in an archived file. The name of the archived file is sent as an argument to the tar command.


I'm trying to create a tar archive with a couple files, but rename those files in the archive. Right now I have something like this:

tar -czvf file1 /some/path/to/file2 file3 etc 

But I'd like to do something like:

tar -czvf file1=file1 /some/path/to/file2=file2 file3=path/to/renamedFile3 etc=etc 

Where, when extracted into directory testDir, you would see the files:

  • testDir/file1
  • testDir/file2
  • testDir/path/to/renamedFile3
  • testDir/etc

How can I do this?