1 | initial version |

You can use

```
%history
```

This works both in the Sage console and in the Jupyter notebook.

2 | No.2 Revision |

You can use

~~%history
~~%history -f my_session.sage

This ~~works both ~~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 ~~console ~~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 ~~Jupyter notebook.~~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.

3 | No.3 Revision |

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 ~~@John_Palmieri's answer.

4 | No.4 Revision |

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 `~~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.

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.