Sometimes, we may need to compress the file/directory to the specified directory. For example, to compress all the files and directories in the/home And/boot directories to the Bak directories, you must first create a Bak directory, copy the/home And/boot directories to the Bak directory, and then compress the Bak directory. In this way, both time and disk space are wasted.
Now there is a better way to solve this problem, that is, to use the -- XForm parameter of tar. this parameter is used to modify the file name by replacing the SED command during packaging and compression, you can add a prefix before the file name.
For example.
Tar czvf test.tar.gz -- XForm's # ^ # bak/# '/home/boot
This article from the "Last Night stars" blog, please be sure to keep this source http://yestreenstars.blog.51cto.com/1836303/1554654
Tar command -- compress the file/directory to the specified directory