IPython:如何有选择地安全地擦除IPython的历史记录?

问题描述 投票:24回答:5

我一直在学习如何使用paramiko包来发现我在IPython的%hist中以纯文本形式存储了所有密码。不太好。

因此,我需要摆脱存储在%hist中的特定部分。说,我不想抹去整个历史。 - 只有我不小心输入password =或类似选择条款的部分。

谢谢


评论我不需要:

  • %clear只清除会话。它没有抹去历史。
  • 是。从现在开始我只会使用xSA_keys。
ipython ipython-notebook
5个回答
32
投票

历史记录默认存储在$(ipython locate)/profile_default/history.sqlite上。您可以删除文件,或者对其执行任何操作(安全擦除等)。它是一个sqlite文件,因此您可以使用任何sqlite程序加载它并对其进行查询。

检查$(ipython locate)/profile_default/和其他$(ipython locate)/profile_xxx您没有任何其他历史文件。 $(ipython locate)通常是~/.ipython/但可以变化:

ls $(ipython locate)/profile_*/*.sqlite

16
投票

一个解决方案是:

sqlite ~/.ipython/profile_default/history.sqlite

delete from history where source like '%password =%';

2
投票

结合@Ovidiu Ghinetanswer@Mattaccepted answer

sqlite $(ipython locate)/profile_*/*.sqlite || sqlite3 $(ipython locate)/profile_*/*.sqlite

然后从sqlite控制台内:

delete from history where source like '%password%';
select * from history; /* confirm that no passwords left        */
.quit                  /* forgot how to exit sqlite console? ;) */

0
投票

如果你想完全从头开始,只需手动删除以下文件(它对我有用)

/home/user/.I Python/profile_default/history.SQLite


0
投票

我无法选择性地擦除IPython的历史记录,但我发现了如何通过内置的func,非sqlite方式擦除数据:

%clear out #it清除输出历史记录

顺便说一句,你也可以通过%clear清除历史


0
投票

如果要从特定会话中删除历史记录,请运行:

sqlite ~/.ipython/profile_default/history.sqlite

在SQLite里面:

select * from history;
# session is the first column in history
delete from history where session=XXX;
© www.soinside.com 2019 - 2024. All rights reserved.