1

I've got a directory that contains a directory (with subdirectories and files) and a hidden (with a dot in front of its name) file. e.g:

dir1\
-- dir2\...
-- .hiddenFile

How do I create a tar.xz archive that would contain dir2 and .hiddenFilein its root (not dir1 nor .)?

I have googled a lot and tried a number of solutions but none helped.

3

To avoid dir1 appearing in the archive, you can run tar from inside it; and to avoid . as the leading element of the stored paths, don’t name it. There are two ways of going about this:

cd dir1
tar cvfJ ../archive.tar.xz dir2 .hiddenFile

or

tar cvfJ archive.tar.xz -C dir1 dir2 .hiddenFile

(without the cd-C tells tar to change directories itself, when it reads it, so archive.tar.xz is created in the current directory but dir2 and .hiddenFile are relative to dir1).

This produces an archive containing

dir2/
.hiddenFile

(along with dir2’ contents).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.