The Easiest Way To Download A File From Linux Command Line

I often am doing something in the linux command line and realize I need to download a file from the Internet. This often happens if I need to download a photo for a website I might be building, but I also use it to download files and programs that I need to run at that moment. Sometimes I want to download a whole website. Whatever it is that I am downloading, if it is on the Internet, there is a single easy command that will allow me to download things directly from the linux command line. That command is

wget [option] [URL]

Run this from a certain directory and the target URL will be downloaded into that directory.

To download a webpage plus any files needed to render that single html page (such as images or css files) use the wget -p option:

wget -p http://example.com/

To download a whole website use the reclusive -r flag:

wget -r http://example.com/

Though some websites try to prevent this by checking the user agent. To get around this, use the -U flag which specifies the user agent. For example:

 wget  -r -p -U Mozilla http://www.stupidsite.com/restricedplace.html

You can use wget to download images, compressed files, websites, web directories, javascript and other scripts, and anything else you can reach with a web browser. This makes wget one of the most useful linux command line commands. There is no need to open a FTP program or even a browser to get the file you need as long as you know the URL.

This is especially great if you are remotely logged into a server. If you are using SSH to manage a remote server then wget is the easiest and fastest way to download files to that remove server.

To read more about wget and see all the options, check out the wget manual.