Linux 下面的bash命令是什么意思?

Linux 下面的bash命令是什么意思?,linux,bash,Linux,Bash,命令- (cd /source/directory && tar cf - . ) | (cd /dest/directory && tar xpvf -) 文档中如何解释此命令- (cd /source/directory && tar cf - . ) | (cd /dest/directory && tar xpvf -) # Move entire file tree from one directory to anoth

命令-

(cd /source/directory && tar cf - . ) | (cd /dest/directory && tar xpvf -)
文档中如何解释此命令-

(cd /source/directory && tar cf - . ) | (cd /dest/directory && tar xpvf -)
# Move entire file tree from one directory to another
# [courtesy Alan Cox <a.cox@swansea.ac.uk>, with a minor change]

# 1) cd /source/directory
#    Source directory, where the files to be moved are.
# 2) &&
#   "And-list": if the 'cd' operation successful,
#    then execute the next command.
# 3) tar cf - .
#    The 'c' option 'tar' archiving command creates a new archive,
#    the 'f' (file) option, followed by '-' designates the target file
#    as stdout, and do it in current directory tree ('.').
# 4) |
#    Piped to ...
# 5) ( ... )
#    a subshell
# 6) cd /dest/directory
#    Change to the destination directory.
# 7) &&
#   "And-list", as above
# 8) tar xpvf -
#    Unarchive ('x'), preserve ownership and file permissions ('p'),
#    and send verbose messages to stdout ('v'),
#    reading data from stdin ('f' followed by '-').
#
#    Note that 'x' is a command, and 'p', 'v', 'f' are options.
#
# Whew!
(cd/source/directory&&tar cf-)|(cd/dest/directory&&tar xpvf-)
#将整个文件树从一个目录移动到另一个目录
#[艾伦·考克斯提供,稍有改动]
#1)cd/source/directory
#要移动的文件所在的源目录。
# 2) &&
#“和列表”:如果“cd”操作成功,
#然后执行下一个命令。
#3)焦油cf-。
#“c”选项“tar”存档命令创建一个新的存档,
#“f”(文件)选项后跟“-”指定目标文件
#作为标准输出,并在当前目录树('.')中执行。
# 4) |
#传送到。。。
# 5) ( ... )
#地下室
#6)cd/dest/目录
#更改到目标目录。
# 7) &&
#“和清单”,如上所述
#8)焦油xpvf-
#取消归档('x'),保留所有权和文件权限('p'),
#并向stdout('v')发送详细消息,
#从stdin读取数据('f'后跟'-')。
#
#请注意,“x”是一个命令,“p”、“v”、“f”是选项。
#
#唷!
在上面给出的解释中,有几件事我不明白-


  • 在第三步中,它声明
    f-
    将目标文件指定为stdout,但是现在输出中没有任何内容,而创建存档您从代码中引用的解释非常好。我希望我读过(或写过!)的每一个脚本都能被很好地记录下来


    在第三步中,它声明
    f-
    将目标文件指定为stdout,但现在输出中没有任何内容,而创建存档时,第一个括号执行以下操作:它将目录更改为/source/directory/,并生成一个tar文件,其内容为当前目录并将其发送到标准输出

    第二个括号将目录更改为/dest/directory/,并从标准输入中提取它读取的归档文件

    i、 e.对“/source/directory”的内容进行tar,然后在“/dest/directory”中对其进行untar,而无需使用中间文件,只需使用管道将两个命令连接起来

    注意:括号中创建了一个子进程,因此有一个子进程执行tar c,另一个子进程执行tar f,同时运行,一个子进程的输出被送入第二个子进程


    在第三步中,它声明f-将目标文件指定为stdout,但现在输出中没有任何内容,在创建归档文件时,我不知道代码解释是否在主题中。无论如何,它的要点是:1)
    tarcf-。
    :源是当前文件夹,
    ,目标是
    stdout
    。2) 第一个子shell的输出通过管道传输到第二个子shell,因为它的输入3)
    tar xpvf-
    stdin
    (从管道中提交)侧注,
    rsync
    很流行,可以复制目录do
    rsync-a/source/directory//dest/directory/
    ,如果这样做,还记得尾随的
    /
    吗?虽然约翰的答案有4票赞成票,但你的答案更详细更好,我对此感到困惑