Tar a file with a different name

filenamestar

To make my environment deployable, I occasionally tar up some handy files and scripts:

tar -czvf env.tgz .vimrc .vim/ bin/lsl bin/s

I would like to add .bashrc to the mix, but I have some sensitive information in there so I maintain .bashrc-deploy which I can then simply rename once the tarball is on the new server. However, I would really like to have the tarball have the correct name .bashrc from the get-go so that I would not have to rename. I considered writing a script which would temporarily rename the files and make the tarball, like so:

#!/bin/bash
mv .bashrc .bashrc-real
mv .bashrc-deploy .bashrc
tar -czvf env.tgz .bashrc .vimrc .vim/ bin/lsl bin/s
mv .bashrc .bashrc-deploy
mv .bashrc-real .bashrc

However, does tar have any internal way of storing someFile with the name anotherName in the tarball?

Best Answer

One way you could do this is a chainload.

In .bashrc:

#!/bin/bash

# ...
# Non-private information
# ...

[[ -r ~/.bashrc-private ]] && . ~/.bashrc-private

Then put (only) your private stuff in ~/.bashrc-private and everything else in ~/.bashrc. Then just deploy ~/.bashrc.

Related Question