ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Copy files and directories recursively with tar

Copy files and directories recursively with tar

原创 Linux操作系统 作者:flyerchen2000 时间:2010-03-17 10:30:05 0 删除 编辑
http://www.tech-recipes.com/rx/115/copy-files-and-directories-recursively-with-tar/

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博客 ” ,链接:https://blog.itpub.net/3637/viewspace-629663/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-08-25

  • 博文量
    43
  • 访问量
    84412