this is not a duplicate of creating a tar archive without including parent directory
If I do tar -czf archive directory
, directory will be added to the archive. I want to add the files of the folder directory
not the directory itself, how?
please suggest answer that does not involve cd
ing to directory
this is not a duplicate of what its showing:
I have a directory called somedir
with contents as abc
, xyz
:
ls somedir
abc xyz
I want to make archive that will contain files abc
, xyz
, not somedir
folder
Update:
if i use the command tar -C /home/username/dir1/dir2 -cvf temp.tar yourarchive
(which the answer to the question of which my question is called duplicate of)
i get this:
what I wanted is tar czf archive.tar.gz -C yourarchive .
, I get this (which is close enough of what I wanted):
what I wanted was is this (directly files, no folder):
Best Answer
Use
-C
:This instructs
tar
to usedirectory
as its working directory, and archive everything contained in the directory (.
).Using
-C
is nearly equivalent to usingcd
;archive
above is interpreted relative to the current directory whentar
starts, thentar
changes its working directory todirectory
before interpreting.
.I'm not sure how widespread support for
tar -C
is, but any Linux distribution should support it.