Whatdoesthefollowingbashcommandmean?

The command-

(cd /source/directory && tar cf - . ) | (cd /dest/directory && tar xpvf -)

How this command is explained in the documentation-

(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!

There are a couple of things which I don't understand in the explanation given above-

  • In the 3rd step it states f - designates the target file as stdout, but there is nothing in output right now, while creating archive , from where is the name of file supplied?
  • In the 8th step it states, it reads data from stdin, but I didn't give any input, is there any input left in the stream?

这个命令工作正常,但我对它的工作方式有点困惑。任何帮助都会有所帮助。

编辑 -指向此的链接,向下滚动一点您会找到它。

回答

您从代码中引用的解释非常好。我希望我读过(或写过!)的每个脚本都记录得很好。

在第 3 步中,它指出f -将目标文件指定为标准输出,但现在输出中没有任何内容,在创建存档时,从哪里提供文件的名称?

没有文件名。归档数据被写入标准输出,即进程的标准输出流。如果它没有通过管道传输到另一个程序中,那么它将显示在屏幕上。

在第 8 步中,它从标准输入读取数据,但我没有给出任何输入,流中是否还有任何输入?

如文档的第 4 步所述,第一个tar命令的输出(到其标准输出)通过管道传输到第二个tar命令(的标准输入)中。你不能tar直接给第二个任何输入,因为它是从管道读取它的输入,而不是键盘或任何常规文件。


以上是Whatdoesthefollowingbashcommandmean?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>