Downloading files off of the Internet can be dangerous, so be sure you are downloading from reputable sources. Out of the box, without any command-line arguments, the curl command will fetch a file and display its contents to the standard output.
Fetching a file and display its contents is all well and good, but what if you want to actually save the file to your system? You can check on things with the cat command:. Execute the following command to download the remote robots. Now use the cat command to display the contents of do-bots. If you happened to try to fetch the robots. You can verify this by using the -I flag, which displays the request headers rather than the contents of the file:.
If you are looking for a utility to download a file then please see wget. We would recommend reading our wget tutorial first and checking out man wget before using curl as wget is more user-friendly in most cases. However, for more complex operations you cannot beat cURL. It has over different command line options many of which can be used in combinations. It is very powerful and can even handle cookies, forms and ssl. However it can also be used for some very simple tasks that you will find useful.
At its most basic you can use cURL to download a file from a remote server. To download the homepage of example. It will, however, try other protocols as well and it can intelligently guess which protocol to use if hints are given. For instance, if you use curl ftp. If you want to give the downloaded file a different name you would use the -o option.
You can see that there are two rows in our download table that didn't download any data. These are the URLs that were redirected. We can review this redirect chain with:. Don't have a Linux machine? If you'd like the file to have a different file name perhaps readme is too bossy for you , specify it after -O : curl -o dontreadme. Use cURL to download multiple files That's all well and good, but downloading lots of files in this way would quickly become a hassle.
To read more about basic authentication, you can read the article 3 methods to use basic authentication with cURL. To see more examples, you can read the article How to use a proxy with cURL. If you do not want cURL to show the progress meter or error messages, you can use the -s or --silent option:.
0コメント