Linux 使用 curl 复制本地文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21023048/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:49:23  来源:igfitidea点击:

Copying local files with curl

linuxunixcurl

提问by zibi

Is there a way to copy local files with curl, I need it to work as an alternative for cp command.

有没有办法用 curl 复制本地文件,我需要它作为 cp 命令的替代品。

This is a bit strange, but I'm working on an environment where cp is not available.

这有点奇怪,但我正在一个 cp 不可用的环境中工作。

采纳答案by devnull

You could say:

你可以说:

curl -o /path/to/destination file:///path/to/source/file 

This would copy /path/to/source/fileto /path/to/destination.

这将复制/path/to/source/file/path/to/destination.

回答by ray

you can use rsync

您可以使用 rsync

rsync -avz /path/to/src/file /path/to/dst/dir

You can also use tar

你也可以使用 tar

cd /path/to/src/dir; tar -cpf - sourcefile | (cd /path/to/dest/dir; tar -xpf -)

if your tar support -C

如果你的 tar 支持 -C

cd /path/to/src/dir; tar -cpf - sourcefile | tar -xpf - -C /path/to/dest/dir