-o file, --output=file
Set the output file name to file. By default, a ``pathname''
is extracted from the specified URI, and its basename is used
as the name of the output file. A file argument of ‘-’
indicates that results are to be directed to the standard
output. If the file argument is a directory, fetched file(s)
will be placed within the directory, with name(s) selected as
in the default behaviour.
printf "HEAD /somefile.txt HTTP/1.1\r\nHost: www.example.com\r\n\r\n" | nc www.example.com 80On such tasks better think of curl(1) and evaluate the HTTP status code.I thought I would be able to use fetch for that ...
curl -s -o /dev/null -I -w "%{http_code}" "http://example.com/file" | grep -q '^2' && echo true || echo false
curl -I "http://example.com/file" fetch -q -o /dev/null "http://example.com/file"Can't you use the -s (--print-size) option?
fetch -s http://pkg.freebsd.org/FreeBSD:15:amd64/latest/meta
If the size is unknown, it will be displayed as Unknown.
Not 'Unknown'?That doesn't do it because the URL might exist and be downloadable, but the http server might not give the length in advance.
$ fetch -s http://pkg.freebsd.org/FreeBSD:15:amd64/latest/
Unknown
$ fetch -s http://pkg.freebsd.org/FreeBSD:15:amd64/latest/All/
fetch: Forbidden
$ fetch -s http://pkg.freebsd.org/FreeBSD:15:amd64/latest/Alle
fetch: Not Found
Not 'Unknown'?
Is it other than these?
Code:$ fetch -s http://pkg.freebsd.org/FreeBSD:15:amd64/latest/ Unknown $ fetch -s http://pkg.freebsd.org/FreeBSD:15:amd64/latest/All/ fetch: Forbidden $ fetch -s http://pkg.freebsd.org/FreeBSD:15:amd64/latest/Alle fetch: Not Found