首先,在*nix系统上,使用tar打包文件时,一般不建议使用绝对路径。
通常,在两台环境相似的计算机上进行同步复制时,需要使用绝对路径打包。 如果在使用绝对路径打包时未指定适当的参数,tar将生成警告消息“tar : removing leading ` /’frommembernames”,实际生成的压缩包是绝对路径
例如,root @ queen~# tar-czvf robin.tar.gz/home/robin
tar : removing leading `/' frommembernames
/home/robin/
/home/robin/file1
/home/robin/file2
/home/robin/file3
root @ queen~# tar-tzvf robin.tar.gz
drwxr-xr-xrobin/root 02009-11-1018336051336031 home/robin /
- rw-r---r---robin/root 02009-11-1018336051336028 home/robin/file 1
- rw-r---r---robin/root 02009-11-1018336051336030 home/robin/file 2
- rw-r-- r-- robin/root 02009-11-1018336051336031家庭/robin /文件3
root@queen ~ #
当我们重新求解这些压缩包时,将在当前目录(在本例中为“~”)下创建一个新的两级目录:“./home/robin/”。 对于这种压缩包,解压缩方法使用参数“-C”将目标目录指定为根目录“/”。 tar -xzvf robin.tar.gz -C /
更可靠的方法是在包装和解压缩中使用参数- p:root @ queen~# tar-czvpfrobin.tar.gz/home/robin /
/home/robin/
/home/robin/file1
/home/robin/file2
/home/robin/file3
root @ queen~# tartzvfrobin.tar.gz
rwxr-xr-xrobin/root 02009-11-1018336051336031/home/robin /
- rw-r-- r-- robin/root 02009-11-1018336051336028/home/robin/file 1
- rw-r-- r-- robin/root 02009-11-1018336051336030/home/robin/file 2
- rw-r-- r-- robin/root 02009-11-1018336051336031/home/robin/file 3
root @ queen~# tar-xzvpfrobin.tar.gz
/home/robin/
/home/robin/file1
/home/robin/file2
/home/robin/file3
root@queen ~ #