Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Linux Commands»Wget Command in Linux with Examples

    Wget Command in Linux with Examples

    RahulBy RahulJune 19, 20214 Mins ReadUpdated:June 14, 2022

    GNU Wget is a free command-line utility for downloading files from the Web. It supports standard web protocols like HTTP, HTTPS, and FTP, as well as retrieval data through HTTP proxies. Wget is a non-interactive command, which means no user login is required and can be run in the background.

    Wget follows the links in the HTML and CSS pages and works recursively. Which makes it smart for cloning remote websites and running them on local machines. This is sometimes referred to as “recursive downloading.”

    How to Install Wget on Linux

    Generally, the Wget package is pre-installed on Linux distributions. But in some cases of minimal installations, It may not be installed.

    Open a terminal and execute the following commands to install or upgrade the Wget package from the default package manager.

    • On Ubuntu, Debian & Linux Mint Systems
      sudo apt update && apt install wget -y 
      
    • On CentOS, RHEL & Fedora Systems
      sudo dnf install wget -y
      

    Wget Command Syntax

    A simple Wget command follows the below syntax.

    wget [option]... [URL]...
    

    A large number of command-line options make it more usable. Wget uses GNU getopt to process command-line arguments, which means all options have a long-form along with a short one.

    Wget required a URL to an archive, IOS, or webpage to download.

    Wget Command Examples

    Here are some frequently used wget commands with examples.

    1. Downloading a file using Wget

    Open a terminal and type wget followed by the remote file URL to download on the local machine. No additional parameters are required to download a file.

    wget https://wordpress.org/latest.zip 
    

    The above command will download the file in the current working directory. The filename will remain the same in the local system as on the remote machine.

    Wget Command Example
    Downloading a file using Wget

    2. Downlaod file with a New Name

    Default wget downloads the file with the same name on the local system. Use -O (Capital O) command-line option followed by a new name to write file on local system.

    wget -O local.zip https://wordpress.org/latest.zip 
    

    See the below screenshot, showing the local file is created with a new name.

    Wget write file with new name
    Wget – Creating File with Different Name

    3. Downlaod Large files with Resume Option

    The Wget allows us to resume downloading for a partially downloaded file. It is helpful for downloading large files from a remote. In any case, the download interrupts, can resume downloading remaining content only instead of full download.

    Use -c or --continue switch with the file.

    wget -c //mirrors.edge.kernel.org/linuxmint/stable/20.1/linuxmint-20.1-cinnamon-64bit.isop 
    

    See the below example, Downloading a large file with -c option. In the first attempt, once the downloading started killed the download process with CTRL+C. Now again execute the same command and you can see the downloading resumes.

    Wget resume downloading

    4. Wget to Execute Remote Scripts without Creating Local File

    Wget is also widely used for executing remote scripts through scheduled jobs like crontab. But we found that it creates a new file with each run under the home directory. We can instruct wget to redirect all content to /dev/null and ignore creating files.

    wget -q -O /dev/null https://google.com 
    

    Here -q will suppress all the output on-screen and -O will redirect all the content to /dev/null file.

    5. How to Mirror a Website in Wget

    Wget allows us to download website content recursively. It follows the internal links available in HTML content. Use --recursive option with wget command to download entire site in your local system.

    wget --recursive https://google.com 
    

    You can also set the maximum depth for recursion with -l opiton.

    wget --recursive -l 2 https://google.com 
    

    The above commands will create a directory with the same name to the domain in the current directory and place all files under it.

    6. How to Authorize Requests with User & Password

    Most of the files over remote FTP servers are secured with authentication. In some cases, content over the HTTP can be secured with authentication. Wget allows us to pass authentication details with this request.

    wget --user=USER --password=PASS https://example.com/backup.zip 
    

    You can use --user and --password for both FTP and HTTP authentications.

    Conclusion

    In this tutorial, you have learned the basics of the Linux wget command with examples.

    command wget
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Create a Sudo User in Debian
    Next Article How to Rename a SQL Server Database

    Related Posts

    How to Search Recently Modified Files in Linux

    2 Mins Read

    Bash Printf Command

    Updated:December 23, 20212 Mins Read

    (Resolved) -bash: /bin/mv: Argument list too long

    Updated:January 13, 20222 Mins Read

    Tee Command in Linux with Examples

    4 Mins Read

    How to Scan Open Ports with Nmap

    5 Mins Read

    Handling filenames with spaces in Linux

    3 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • What is CPU? – Definition, Types and Parts
    • What is the /etc/aliases file
    • What is the /etc/nsswitch.conf file in Linux
    • How to Install Ionic Framework on Ubuntu 22.04
    • What is the /etc/hosts file in Linux
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.