G
G
GSnick2015-03-27 17:58:35
linux
GSnick, 2015-03-27 17:58:35

How to tar an archive with a given folder structure?

I have a number of folders:
/var/ftp/pub/bkp1
/home/user/bkp2
/home/user/bkp3 I
archive them like this:
tar -cvf bkp_re2.3.tar /var/ftp/pub/bkp1 /home/user/bkp2 /home/user/bkp3
and the folder structure is preserved in the archive the same as it was before archiving.
And I need the following structure in the archive:
/bkp1
/bkp2
/bkp3
How can I do this?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
T
t_q_l, 2015-03-27
@GSnick

We create an archive from the first directory group, and then add another directory group to the existing tar archive:

tar cvfC  /path/to/backup/bkp_re2.3.tar /var/ftp/pub/ .
tar vfCr  /path/to/backup/bkp_re2.3.tar /home/user .

J
jcmvbkbc, 2015-03-27
@jcmvbkbc

The -C option can change the current directory during archiving:
tar -cf bkp_re2.3.tar -C /var/ftp/pub/ bkp1 -C /home/user/ bkp2 bkp3

S
Sergey Petrikov, 2015-03-27
@RicoX

I'm not sure if it will work, but you can try this:

tar -cvf bkp_re2.3.tar -C `pwd` /var/ftp/pub/bkp1 /home/user/bkp2 /home/user/bkp3

D
Dmitry Skogorev, 2015-03-27
@EnterSandman

read about the -C key

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question