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
Related posts:
How to Upload & Download Files From FTP in Linux
How to Use Auto Indent in Vi Editor
How to Find Folder By Name in Linux
How to Change Color Scheme in Vim
How to Schedule Shutdown in Ubuntu Linux
How to Show Disk Usage Only for Top Level Directories
How to Remove Startup Applications in Ubuntu
How to Show Asterisk for Password in Ubuntu

Sreeram has more than 10 years of experience in web development, Python, Linux, SQL and database programming.