【问题标题】:IPython: How to wipe IPython's history selectively & securely?IPython:如何选择性且安全地擦除 IPython 的历史记录?
【发布时间】:2013-11-05 13:00:10
【问题描述】:

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

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

谢谢


我不需要的评论:

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

【问题讨论】:

  • 请注意,如果您只想删除所有内容,可以使用 ipython history clear 擦除整个历史记录。

标签: ipython ipython-notebook


【解决方案1】:

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

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

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

【讨论】:

  • 嗯,$(ipython locate) 给了我[TerminalIPythonApp] File not found: u'locate',但我可以在~/.ipython/profile_default/history.sqlite.找到它
【解决方案2】:

一种解决方案是:

sqlite ~/.ipython/profile_default/history.sqlite

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

【讨论】:

  • 如果你这样做,你可能想删除~/.sqlite_history中的sqlite3历史记录。
【解决方案3】:

结合@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? ;) */

【讨论】:

    【解决方案4】:

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

    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;
    

    【讨论】:

      【解决方案5】:

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

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

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

      【讨论】:

        【解决方案6】:

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

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

        【讨论】:

        • 这不是选择性删除,您会丢失历史记录中的所有好东西。
        猜你喜欢
        • 1970-01-01
        • 2013-05-27
        • 2013-09-07
        • 1970-01-01
        • 1970-01-01
        • 2016-05-07
        • 1970-01-01
        • 1970-01-01
        • 2013-07-13
        相关资源
        最近更新 更多