Movatterモバイル変換


[0]ホーム

URL:


everything curl

    Storing downloads

    If you try the example download as in the previous section, you might noticethat curl outputs the downloaded data to stdout unless told to do somethingelse. Outputting data to stdout is really useful when you want to pipe it intoanother program or similar, but it is not always the optimal way to deal withyour downloads.

    Give curl a specific filename to save the download in with-o [filename](with--output as the long version of the option), where filename is eitherjust a filename, a relative path to a filename or a full path to the file.

    Also note that you can put the-o before or after the URL; it makes nodifference:

    curl -o output.html http://example.com/curl -o /tmp/index.html http://example.com/curl http://example.com -o ../../folder/savethis.html

    This is, of course, not limited tohttp:// URLs but works the same way nomatter which type of URL you download:

    curl -o file.txt ftp://example.com/path/to/file-name.ext

    If you ask curl to send the output to the terminal, it attempts to detect andprevent binary data from being sent there since that can seriously mess upyour terminal (sometimes to the point where it stops working). You canoverride curl's binary-output-prevention and force the output to get sent tostdout by using-o -.

    curl has several other ways to store and name the downloaded data. Detailsfollow.

    Overwriting

    When curl downloads a remote resource into a local filename as describedabove, it overwrites that file in case it already existed. Itclobbers it.

    curl offers a way to avoid this clobbering:--no-clobber.

    When using this option, and curl finds that there already exists a file withthe given name, curl instead appends a period plus a number to the filename inan attempt to find a name that is not already used. It starts with1 andthen continues trying numbers until it reaches100 and picks the firstavailable one.

    For example, if you ask curl to download a URL topicture.png, and in thatdirectory there already are two files calledpicture.png andpicture.png.1, the following saves the file aspicture.png.2:

    curl --no-clobber https://example.com/image -o picture.png

    A user can use the--write-out option's%filename_effective variable to figure out which name that was eventuallyused.

    Leftovers on errors

    By default, if curl runs into a problem during a download and exits with anerror, the partially transferred file is left as-is. It could be a smallfraction of the intended file, or it could be almost the entire thing. It isup to the user to decide what to do with the leftovers.

    The--remove-on-error command line option changes this behavior. It tellscurl to delete any partially saved file if curl exits with an error. No moreleftovers.


    [8]ページ先頭

    ©2009-2025 Movatter.jp