wget rename file

How to Rename Downloaded File in Wget

Wget is a popular command to download files and transfer data in Linux. By default, it downloads the file as-is with the same filename as present on the URL. Sometimes you may want to change the filename of downloaded file. For example, the filename in URL may be too long with lots of dots and numbers making it non-intuitive. In such cases, you can directly change then name of file during download. In this article, we will learn how to rename downloaded file in wget.

How to Rename Downloaded File in Wget

Typically, we download file using wget with the following command.

$ wget URL

Now if the downloaded filename is really long, as shown in the following example, then even the downloaded file will have a long name.

$ wget -c https://gist.github.com/chales/11359952/archive/25f48802442b7986070036d214a2a37b8486282d.zip 

As you can see the downloaded file will have the name

25f48802442b7986070036d214a2a37b8486282d.zip 

Now if you want to save it as a simple, easy to understand filename, then use the -O option to specify the filename you want it to be saved as.

$ wget -c https://gist.github.com/chales/11359952/archive/25f48802442b7986070036d214a2a37b8486282d.zip -O db-test.zip

Now the downloaded file will have db-test.zip filename.

Alternatively, you can also run the above command as

$ wget -cO - https://gist.github.com/chales/11359952/archive/25f48802442b7986070036d214a2a37b8486282d.zip > db-test.zip

In this case, the file is written to standard output and then redirected by shell to specific file.

In this article, we have learnt how to rename file using wget command. It is useful for beginners who generally download file with their original name and try to rename it using mv/cp command.

Also read:

Wget Limit Download Speed Rate
How to Backup & Restore PostgreSQL database
How to Check Git Diff Between Commits
How to Checkout Specific Commit in Git
How to Take Screenshot of Div in JavaScript

Leave a Reply

Your email address will not be published. Required fields are marked *