38

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

因此,我需要摆脱存储在%hist. 话虽如此,我不想抹去整个历史。- 只有我不小心输入password =或类似选择的术语的部分。

谢谢


我不需要的评论:

  • %clear只清除会话。它不会抹去历史。
  • 是的。从现在开始,我将只使用 xSA_keys。
4

6 回答 6

43

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

签入$(ipython locate)/profile_default/和其他$(ipython locate)/profile_xxx您没有任何其他历史记录文件。$(ipython locate)通常是~/.ipython/但可能会有所不同:

ls $(ipython locate)/profile_*/*.sqlite
于 2013-10-26T12:40:56.290 回答
25

一种解决方案是:

sqlite ~/.ipython/profile_default/history.sqlite

delete from history where source like '%password =%';
于 2016-08-19T20:44:51.440 回答
6

@Ovidiu Ghinet答案@Matt接受的答案相结合:

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? ;) */
于 2018-07-05T21:09:55.860 回答
3

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

sqlite ~/.ipython/profile_default/history.sqlite

请注意,在某些系统上,您需要运行sqlite3而不是sqlite.

SQLite 内部:

select * from history;
# session is the first column in history
delete from history where session=XXX;

此外,这是一个 SQLite 查询,它将为您提供上次会话的 id:

select session from history order by -session limit 1;
于 2019-05-30T20:13:29.673 回答
1

我找不到有选择地擦除 IPython 历史记录的方法,但我发现了如何通过内置的 func 非 SQLite 方式擦除数据:

%clear out #清除输出历史

顺便说一句,您也可以通过 %clear in 在历史记录中清除

于 2018-09-02T22:23:48.377 回答
0

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

/home/user/.ipython/profile_default/history.sqlite

于 2018-07-15T07:13:15.357 回答