Run wget In Background For an Unattended Download of Files on Linux and Unix

Here is a quick tip, if you wish to perform an unattended download of large files such as Linux DVD ISO image file use the wget command.

ADVERTISEMENTS

Syntax

The syntax is as follows for a non-interactive download:
wget -bqc http://path-to-url/linux.iso
You will see a PID on screen:

Continuing in background, pid 12345.

Where,

  • -b : Go to background immediately after startup. If no output file is specified via the -o, output is redirected to wget-log.
  • -q : Turn off wget’s output aka save disk space.
  • -c : Resume broken download i.e. continue getting a partially-downloaded file. This is useful when you want to finish up a download started by a previous instance of wget, or by another program.

Examples

This tip will save your time while downloading large ISO file or any other files from the Internets:

## download a large file in background ##
wget -bqc  http://bay.uchicago.edu/centos/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-DVD.iso
 
## Verify it ##
ps aux | grep wget
ls -lh CentOS-7.0-1406-x86_64-DVD.iso
 
## [Optional] Stop download by killing by PID number
kill PID-HERE
ps aux | grep wget

Sample session from above commands:

Fig.01: Force wget go to background immediately after download startup

Fig.01: Force wget go to background immediately after download startup

The nohup command

You can also use the nohup command to execute commands after you exit from a shell prompt. The syntax is:

$ nohup wget -qc http://path-to-url/linux.iso &
 
## exit from shell or close the terminal ##
$ exit

The disown bash command

Another option is to use the disown command as follows:

$ wget -qc http://path-to-url/linux.iso &
[1] 10685
$ disown wget
$ ps
  PID TTY          TIME CMD
10685 pts/0    00:00:00 wget
10687 pts/0    00:00:00 bash
10708 pts/0    00:00:00 ps
$ logout

See disown command examples for more info.

The screen command

You can also use the screen command which is a full-screen window manager that multiplexes a physical terminal between several processes (typically interactive shells).

See also
🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source & DevOps topics via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
7 comments… add one
  • downforce Sep 14, 2007 @ 0:21

    Nice tip thanks.

    Personally though screen is still more useful.

  • skip Sep 14, 2007 @ 5:34

    How to download a file, In ‘save target as’ mode. Sometimes files are hidden under some urls. How to download such files.

  • Dave Feb 2, 2010 @ 9:36

    nice tip! if you give the -q option does -b not output to a log file?

  • mccbala Apr 15, 2011 @ 11:26

    Wow! I’ve really needed this… Thanks a ton!

  • majed Jul 19, 2011 @ 13:25

    Thanks, the b option is great, I can use this option to download large files, initiating the download from an SSH terminal, and the download will continue after I close the SSH terminal.

  • amplatfus Sep 12, 2012 @ 7:51

    Can option b used in dd-wrt router? I want the download to continue after closing the terminal in Ubuntu. I want the download to continue in router with dd-wrt firmware and HDD attashed.
    Thank you for post and all comments!

  • person Aug 4, 2014 @ 15:19

    perfect for using in win-scp or other tools that can issue single ssh commands but cant handle interactive output.

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.