Saving output of \ commands to disk
Use the \o command as documented in the manual:

http://www.postgresql.org/docs/current/static/app-psql.html

specifically:

&gt; \o &lt;path_to_the_file_where_you_want_the_output&gt;
&gt; [your command]
&gt; \o 


the last statement switches the output of psql back to stdout.