When using wget to download files, you may wish to rename the downloaded file to a more descriptive or specific naming convention. wget provides a straightforward option for this: -O (capital O), followed by the desired filename. This enables saving the file with the new name directly during the download process.
Usage Example
Suppose you want to download a PDF file from an online resource and rename it to my_document.pdf. You can use the following command:
bashwget -O my_document.pdf https://example.com/path/to/file.pdf
This command instructs wget to download the file from the specified URL and save it as my_document.pdf using the -O option.
Important Notes
- When using the
-Ooption, regardless of the source filename, the downloaded file will be saved with the specified name. - If you download multiple files in a single command and attempt to use
-O, only the last file will be correctly renamed, while others may be overwritten. When handling multiple files, you might consider writing a script or using a loop to specify the output filename for each file individually.
2024年7月30日 00:22 回复