You can use

```
%history -f my_session.sage
```

This saves all the sage commands typed during your session in the text file `my_session.sage`

. Then, you can load this file in a new Sage session by

```
%load my_session.sage
```

In the Jupyter notebook, this loads all the saved commands in a single cell. In the Sage console, you will have to press Enter at the prompt `...:`

to rerun the commands and possibly enter `n`

to the question

```
File u'my_session.sage' exists. Overwrite?
```

This occurs because the `%history`

command has been saved in the file `my_session.sage`

and therefore is run again when you load the file.

An alternative is to use `%attach`

as described in @John_Palmieri's answer.

make a text file with the extension .sage

http://doc.sagemath.org/html/en/tutor...