Writing cookies to file
The place where cookies are stored is sometimes referred to as the cookiejar. When you enable the cookie engine in curl and it has received cookies,you can instruct curl to write down all its known cookies to a file, thecookie jar, before it exits. It is important to remember that curl onlyupdates the output cookie jar on exit and not during its lifetime, no matterhow long the handling of the given input takes.
You point out the cookie jar output with-c
:
curl -c cookie-jar.txt http://example.com
-c
is the instruction towrite cookies to a file,-b
is the instructiontoread cookies from a file. Oftentimes you want both.
When curl writes cookies to this file, it saves all known cookies includingthose that are session cookies (without a given lifetime). curl itself has nonotion of a session and it does not know when a session ends so it does notflush session cookies unless you tell it to.