wget https://some.url/with/a/file.txt
尽管 (可以通过浏览器下载)
file.txt
存在于该位置,但返回 No such file or directory
。同时,运行该命令的用户具有写入所保存目录的权限。wget https://some.url/with/a/file.txt
file.txt
存在于该位置,但返回 No such file or directory
。同时,运行该命令的用户具有写入所保存目录的权限。有很多相关的帖子,但都没有帮助。
最后发现URL前面存在非法字符!
这个问题难以找到,我在这里发布以防有人遇到同样的问题。
关闭终端并尝试再次运行脚本。
在使用curl时,我遇到了类似的问题。
对我来说,根本原因是curl无法找到目标目录。
将--create-dirs
添加到命令中,将会要求curl在目录不存在时创建目录,这解决了我的问题。
例如:
# I want to download this file to ~/development/csvs/saved_file.csv
# Assume I am executing from a ~/development/ directory, which has no csv dir
# this will not work
curl 'https://bla.com/cool_csv.csv' > csvs/saved_file.csv
# this will work
curl 'https://bla.com/cool_csv.csv' -o csvs/saved_file.csv --create-dirs
-o
会取代>
并指定输出