Remove directory prefix tar package
Explanation
Example: existing directory structure shown below.
# tree /a
/a
└── b
└── c
├── hello
└── hello.md5sum
Normally packed files in the directory c
压缩
# tar cf /opt/test.tar /a/b/c/hello /a/b/c/hello.md5sum
解压
# tar xf test.tar
# ls
a test.tar
# tree /opt/a/
/opt/a/
└── b
└── c
├── hello
└── hello.md5sum
As described above, under normal circumstances the compressed file in the default directory of the directory structure packing tape, until the last layer of the file needs to be packaged.
Then only the last layer of compressed files how to package and not to bring any directory or directory is not needed it a few levels?
Method to realize
A, cp
Cp command, files are copied to the target path first, and then packaged.
# cp /a/b/c/* /opt/ && cd /opt && tar cf /opt/test2.tar ./hello ./hello.md5sum
Second, use the "--transform"
parameter: --transform s=xxx/==
# tar cvf /trans/testfile2.tar.gz --transform s=a/b/c/== ./a/b/c/hello ./a/b/c/hello.md5sum
Explains: "s = a / b / c / ==" indicates a directory omitted, it is behind all the files to be packaged
# tar xf testfile2.tar.gz
# ls
hello hello.md5sum
These are by --transform packaged files without directory