
在这个网页上看到(cd backup && tar c .) | (cd backupArchives && tar xf -)这条命令,对于 tar 直接用管道进行打包解包这个操作直呼少见,man tar中也没看到相关介绍
1 codehz 2021-03-04 21:15:31 +08:00 via Android (就是约定俗称,最初的原因就是这玩意天然不适合做文件名,刚好可以用来表达标准输入输出( 按标准写法的话是直接用-O 表示标准输出,不写文件名就是标准输入( |
2 polaa 2021-03-04 21:19:30 +08:00 man tar 里有 -f file, --file file Read the archive from or write the archive to the specified file. The filename can be - for standard input or standard output. The default varies by system; on FreeBSD, the default is /dev/sa0; on Linux, the default is /dev/st0. |
3 billlee 2021-03-04 22:35:37 +08:00 GNU tar 这里也可以不指定 f 选项,没有 f 时就是读标准输入 GNU cp 可以用 cp -rT backup backupArchives 来达到同样目的 但 POSIX 里面 tar 不指定 f 时的输入是不确定的. POSIX cp 也没有 -T 这个选项,所以那个网页才给了个这么绕的命令吧 |
4 billlee 2021-03-04 22:38:00 +08:00 |
6 Usaki 2021-03-05 08:41:39 +08:00 via Android 最近用 pigz 和 tar 也遇到这个-了,不加还报错 |
7 xltfes OP @polaa 手册居然还有不一样的,用的 tar 不一样么? tar --version tar (GNU tar) 1.29 Copyright (C) 2015 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Written by John Gilmore and Jay Fenlason. |
9 julyclyde 2021-03-07 15:05:24 +08:00 man tar 不介绍是因为这事和 tar 根本没关系 只是把管道当作文件操作而已 |