I have below paths in my system
/a/b/z
/c/d/
/e/f/z
/y/g/
In "z" directory there are some files i just want to make tar of that files without going into directory .
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityLet's assume your tarfile is $TARBALL
with an absolute path.
tar cfC $TARBALL /a/b/z .
tar AfC $TARBALL /e/f/z .
The -C
option changes directory to the next argument. What's not clear is what will happen when files of the same name are in both directories.
The alternative is to keep the path names:
tar cf $TARBALL /a/b/z /e/f/z
The pathnames will be retained and kept in the tarball and those directories will be created during extraction.
Suppose your files are like
/home/usr/dir1/dir2/a.txt
/home/usr/dir1/dir2/b.txt
/home/usr/dir1/dir3/a.txt
/home/usr/dir1/dir3/b.txt
And you want to compress dir2
and a.txt
from dir3
,
then you can use
tar -cvf mytarfile.tar /home/usr/dir1/dir2/ /home/usr/dir1/dir3/a.txt
Or just do
tar -cvf mytarfile.tar dir2 dir3/a.txt
staying in directory dir1
where dir2
and dir3
reside.
a/b/z/file1
ande/f/z/file2
or justfile1
andfile2
?