If you have ever used cURL to retrieve the output of a file, believe me, saving that output to a file only takes a few more characters. You can use the -O or --remote-name option to save the output to a local file in the current working directory using the remote file name.
You can use the -o or --output option followed by a file name you want to save the output. 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:. The output shows that the URL was redirected. Silent or quiet mode. Don't show progress meter or error messages. Makes Curl mute. So those are the basics for the curl command.
There are many, many more options, but for now, we know how to use curl to do something that is actually quite powerful: fetch a file, anywhere on the Internet, from the simple confines of our command-line. Before we go further, though, let's look at the various ways this simple command can be re-written and, more crucially, screwed up:.
As you might have noticed in the --silent documentation, it lists the alternative form of -s. Many options for many tools have a shortened alias. In fact, --output can be shortened to -o. Now watch out: the number of hyphens is not something you can mess up on; the following commands would cause an error or other unexpected behavior:.
Also, mind the position of my. The argument must follow after the -o …because curl. For that, we must use the -O option:. You'll notice that cURL will display a download progress table rather than the file contents this time:. If you'd like the file to have a different file name perhaps readme is too bossy for you , specify it after -O :. That's all well and good, but downloading lots of files in this way would quickly become a hassle. You can download more than one file in a single command by using the following syntax:.
If you have a long list of different files you want to download, you can place them in a text file and run cURL with xargs:.
0コメント