乐闻世界logo
搜索文章和话题

How to rename the downloaded file with wget?

1个答案

1

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:

bash
wget -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 -O option, 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 回复

你的答案