9

wget 默认文件名附加URL查询部分的去除

 3 years ago
source link: https://blog.lilydjwg.me/posts/21910.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

wget 默认文件名附加URL查询部分的去除

本文来自依云's Blog,转载请注明。

拿wget下文件,它总是把URL的查询部分(?q=test这种)附加到默认的文件名后,让人十分不爽。查了man手册,也Google过,结论是没有办法解决。虽说拿shell写个脚本在下载完之后把这种尾巴也不难,但总觉得应该从根本上解决问题。于是就hack源码了。

要改的地方其实很好找,在url.c的第1556行附近:

/* Append "?query" to the file name. */
u_query = u->query && *u->query ? u->query : NULL;
if (u_query)
{
append_char (FN_QUERY_SEP, &fnres);
append_uri_pathel (u_query, u_query + strlen (u_query), true, &fnres);
}

把这几行注释掉,然后重新编译就可以了。不需要安装,可以直接覆盖掉系统的wget,但不推荐,因为更新后就没了。我是把它放到~/bin下。这个目录在我的$PATH变量的前面,所以会优先使用这里的wget。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK