Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Possible to removing directory names while tarring? 1

Status
Not open for further replies.

cptk

Technical User
Mar 18, 2003
305
0
0
US
Is there a way to tar-up a directory containing sub-directories so that the resulting tar file just contains the file names from the sub-directories and doersn't include the name of the sub-dirs?

e.g.:
> /test/one/file1.txt
> /test/two/file2.txt

and run something like ... tar -cvf final.tar *
where the final.tar contains:
file1.txt
file2.txt

instead of :
./one/file1.txt
./two/file2.txt
 
You could copy all your files to one directory and then tar that directory:

Code:
find /mydir -type f -print| xargs -i cp {} /pathto/mytmp

Of course, if you have any duplicate file names you'll copy over them

 
from the tar man page (this is on AIX53):

-C Directory
Causes the tar command to perform a chdir
subroutine to the directory specified by the
Directory variable. Using the -C flag allows
multiple directories not related by a close
common parent to be archived, using short
relative path names. For example, to archive
files from the /usr/include and /etc
directories, you might use the following
command: tar c -C /usr/include File1 File2 -C
/etc File3 File4

so:

tar -c -f my.tar -C /test/one . -C /test/two .

files will be tarred like this though:

./file1.txt
./file2.txt

Note: different files with the same name in the two directories will be added to the tar twice, and it is kind of hard to extract the different copies later on...


HTH,

p5wizard
 
Thanks p5wizard ... that works great !!

I originally tried the "-C" argument, but I wasn't supplying the "file" portion (i.e. - the dot '.') after the the -C option. [I should of read the man page more closely]

> tar -cvf final.tar -C /test/one . -C /test/two .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top