Copying a directory tree and its contents to another filesystem using tar will preserve ownership, permissions, and timestamps. A neat trick allows using tar to perform. a recursive copy without creating an intermediate tar file.
To copy all of the files and subdirectories in the current working directory to the directory /target, use:
tar cf - * | ( cd /target; tar xfp -)
The first part of the command before the pipe instruct tar to create an archive of everything in the current directory and write it to standard output (the – in place of a filename frequently indicates stdout). The commands within parentheses cause the shell to change directory to the target directory and untar data from standard input. Since the cd and tar commands are contained within parentheses, their actions are performed together.
The -p option in the tar extraction command directs tar to preserve permission and ownership information, if possible given the user executing the command. If you are running the command as superuser, this option is turned on by default and can be omitted.
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/3637/viewspace-629663/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/3637/viewspace-629663/
本文介绍了一种利用tar命令进行目录及其内容递归复制的方法,这种方法能够保留文件的所有权、权限及时间戳等信息,并且不需要创建中间的tar文件。
2045

被折叠的 条评论
为什么被折叠?



