xref: /curl/docs/cmdline-opts/output.md (revision 2abfc759)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Long: output
5Arg: <file>
6Short: o
7Help: Write to file instead of stdout
8Category: important output
9Added: 4.0
10Multi: per-URL
11See-also:
12  - remote-name
13  - remote-name-all
14  - remote-header-name
15Example:
16  - -o file $URL
17  - "http://{one,two}.example.com" -o "file_#1.txt"
18  - "http://{site,host}.host[1-5].example" -o "#1_#2"
19  - -o file $URL -o file2 https://example.net
20---
21
22# `--output`
23
24Write output to the given file instead of stdout. If you are using globbing to
25fetch multiple documents, you should quote the URL and you can use `#`
26followed by a number in the filename. That variable is then replaced with the
27current string for the URL being fetched. Like in:
28
29    curl "http://{one,two}.example.com" -o "file_#1.txt"
30
31or use several variables like:
32
33    curl "http://{site,host}.host[1-5].example" -o "#1_#2"
34
35You may use this option as many times as the number of URLs you have. For
36example, if you specify two URLs on the same command line, you can use it like
37this:
38
39    curl -o aa example.com -o bb example.net
40
41and the order of the -o options and the URLs does not matter, just that the
42first -o is for the first URL and so on, so the above command line can also be
43written as
44
45    curl example.com example.net -o aa -o bb
46
47See also the --create-dirs option to create the local directories
48dynamically. Specifying the output as '-' (a single dash) passes the output to
49stdout.
50
51To suppress response bodies, you can redirect output to /dev/null:
52
53    curl example.com -o /dev/null
54
55Or for Windows:
56
57    curl example.com -o nul
58
59Specify the filename as single minus to force the output to stdout, to
60override curl's internal binary output in terminal prevention:
61
62    curl https://example.com/jpeg -o -
63