download file to directory

How to Download File to Directory with Wget

wget is a useful Linux utility that allows you to download files to & from various locations. It provides numerous options for file download and data transfer. Sometimes you may need to download file to specific folder in Linux. In this article, we will look at how to download file to a directory with wget command.


How to Download File to Directory with Wget

You can easily download file to specific folder or subfolder using -P option in wget command. Here is how to download file to directory with wget.


1. Create Folder

Open terminal and run the following command to create an empty folder in Linux.

$ sudo mkdir /home/data


2. Download file to directory

Here is the syntax to download file to folder.

$ sudo wget /path/to/file -P /path/to/directory

In the above command you need to specify the path or URL to file after wget, followed by -P option and finally the path to directory, where you want to file to be downloaded.

Also, please make sure to use sudo keyword before wget command so that you are not denied permission during file download.

We will use wget command to download genisoimage to the above directory.

$ sudo wget http://mirror.centos.org/centos/7/os/x86_64/Packages/genisoimage-1.1.11-25.el7.x86_64.rpm -P /home/data

That’s it. In this article, we have learnt how to download to specific folder using -P option. You may also use other options such as -c command to ensure that file is downloaded continuously. This way the file download will resume in case it gets interrupted.

Also read:

How to Create Disk Image from Directory in Linux
Shell Script to Concatenate Strings
How to Run Shell Script in Background
How to Unrar Files with Password in Linux
How to Create Empty Disk Image in Linux

Leave a Reply

Your email address will not be published.