this is not a duplicate of creating a tar archive without including parent directoryIf 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 cding to directorythis is not a duplicate of what its showing:I have a directory called somedir with contents as abc, xyz:ls somedirabc xyzI want to make archive that will contain files abc, xyz, not somedir folderUpdate: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):
how to add files from a folder to archive instead of the folders itself?
tar
Use -C:tar czf archive -C directory .This instructs tar to use directory as its working directory, and archive everything contained in the directory (.).Using -C is nearly equivalent to using cd; archive above is interpreted relative to the current directory when tar starts, then tar changes its working directory to directory before interpreting ..I'm not sure how widespread support for tar -C is, but any Linux distribution should support it.