wget Command in Linux

Topics Covered

Overview

The wget command is a powerful and versatile command-line utility for downloading files from the internet. It supports multiple protocols such as HTTP, HTTPS, and FTP. In this article, we will cover the syntax, options, and examples of the wget command.

Linux wget Command Syntax

The syntax for the wget command is as follows:

Where:

  • options: Optional flags that alter the behavior of the wget command.
  • URL: The URL of the file to be downloaded.

wget Command Options:

  • -O: Specifies the output file name.
  • -c: Resumes an interrupted download.
  • -r: Downloads files recursively from directories.
  • -np: Do not ascend to the parent directory when retrieving recursively.

Example Usages

  • Downloading a single file:

    Explanation: Downloads the 'file.txt' from the specified URL.

  • Resuming an interrupted download:

    Explanation: Resumes downloading the 'file.txt' from the specified URL if the download was interrupted.

Tips

  • Use '-nc' to skip downloading a file if it already exists in the local directory.

  • To limit the download speed, use the '--limit-rate' option followed by the desired speed (e.g., '--limit-rate=100k').

Advanced Use Cases of wget Command in Linux

  • Downloading a file and specifying the output file name:

    Explanation: Downloads the 'file.txt' from the specified URL and saves it as 'newfile.txt'.

  • Downloading files recursively:

    Explanation: Recursively downloads all files from the specified directory without ascending to the parent directory.

  • Downloading files with a specific file extension:

    Explanation: Recursively downloads all PDF files from the specified directory.

Conclusion

  • The wget command is a powerful command-line utility for downloading files from the internet.

  • wget supports multiple protocols, including HTTP, HTTPS, and FTP.

  • Advanced usages include specifying output file names, downloading files recursively, and downloading files with specific extensions.