用 curl -O 下载文件
终端里一条命令把文件下载到本地,自动跟随重定向,保存原始文件名。
运行 curl -LO https://example.com/tool.tar.gz — 大写 -O 保留远程文件名,-L 跟随重定向链接。
01命令
命令
$ curl -LO https://example.com/tool.tar.gz02作用说明
-O 按 URL 中的文件名保存,小写 -o 则可以自己指定名字(curl -o myname.tar.gz URL)。-L 很关键:大多数下载链接会重定向到 CDN,不加它的话 curl 只会把重定向的 HTML 页面存成文件。与 wget 相比,curl 几乎在所有发行版都预装,所以脚本和一次性下载首选它。
03风险
!注意: curl 是边下边写——中途失败会留下截断的文件;可用 -C - 断点续传,或者删掉残缺文件重下。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- curl(1) — Ubuntu man page依据: Man page text includes -O/--remote-name and -L/--location (follow redirects), confirming the flags used in the command.
- curl(1) — Linux man page依据: Documents -o/--output (write output to file) and -O/--remote-name (save with the remote filename part of the URL); both flags confirmed in page text.
最后验证: 2026-09-19 · 分类: 网络