Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a minimal headless *nix which does not have any command line utilities for downloading files (e.g. no curl, wget, etc). I only have bash.

How can I download a file?

Ideally, I would like a solution that would work across a wide range of *nix.

share|improve this question
up vote 34 down vote accepted

If you have bash 2.04 or above with the /dev/tcp pseudo-device enabled, you can download a file from bash itself.

Paste the following code directly into a bash shell (you don't need to save the code into a file for executing):

function __wget() {
    : ${DEBUG:=0}
    local URL=$1
    local tag="Connection: close"
    local mark=0

    if [ -z "${URL}" ]; then
        printf "Usage: %s \"URL\" [e.g.: %s http://www.google.com/]" \
               "${FUNCNAME[0]}" "${FUNCNAME[0]}"
        return 1;
    read proto server path <<<$(echo ${URL//// })
    DOC=/${path// //}
    [[ x"${HOST}" == x"${PORT}" ]] && PORT=80
    [[ $DEBUG -eq 1 ]] && echo "HOST=$HOST"
    [[ $DEBUG -eq 1 ]] && echo "PORT=$PORT"
    [[ $DEBUG -eq 1 ]] && echo "DOC =$DOC"

    exec 3<>/dev/tcp/${HOST}/$PORT
    echo -en "GET ${DOC} HTTP/1.1\r\nHost: ${HOST}\r\n${tag}\r\n\r\n" >&3
    while read line; do
        [[ $mark -eq 1 ]] && echo $line
        if [[ "${line}" =~ "${tag}" ]]; then
    done <&3
    exec 3>&-

Then you can execute it as from the shell as follows:

__wget http://example.iana.org/

Source: Moreaki's answer upgrading and installing packages through the cygwin command line?

share|improve this answer
So you answered your own question at the same time as you asked it. That's an interesting time machine you have ;) – Meer Borg Jul 22 '13 at 7:59
@MeerBorg - when you ask a question, look for the tick box 'answer your own question' - blog.stackoverflow.com/2011/07/… – SHC Jul 22 '13 at 8:08
@eestartup - I don't think you can vote for your own answer. Can I explain the code? Not yet! But it does work on cygwin. – SHC Jul 22 '13 at 9:24
Just a note: This won't work with some configurations of Bash. I believe Debian configures this feature out of their distribution of Bash. – Evan Teitelman Jul 22 '13 at 15:57

Use lynx.

It is pretty common for most of Unix/Linux.

lynx -dump http://www.google.com

-dump: dump the first file to stdout and exit

man lynx

Or netcat:

/usr/bin/printf 'GET / \n' | nc www.google.com 80

Or telnet:

(echo 'GET /'; echo ""; sleep 1; ) | telnet www.google.com 80
share|improve this answer
The OP has "*nix which does not have any command line utilities for downloading files", so no lynx for sure. – Celada Jul 25 '14 at 14:06
Note lynx -source is closer to wget – Steven Penny Dec 20 '14 at 8:34

If you have this package libwww-perl

You can simply use:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.