我一直在学习如何使用paramiko
包来发现我在IPython的%hist
中以纯文本形式存储了所有密码。不太好。
因此,我需要摆脱存储在%hist
中的特定部分。说,我不想抹去整个历史。 - 只有我不小心输入password =
或类似选择条款的部分。
谢谢
评论我不需要:
%clear
只清除会话。它没有抹去历史。历史记录默认存储在$(ipython locate)/profile_default/history.sqlite
上。您可以删除文件,或者对其执行任何操作(安全擦除等)。它是一个sqlite文件,因此您可以使用任何sqlite程序加载它并对其进行查询。
检查$(ipython locate)/profile_default/
和其他$(ipython locate)/profile_xxx
您没有任何其他历史文件。 $(ipython locate)
通常是~/.ipython/
但可以变化:
ls $(ipython locate)/profile_*/*.sqlite
一个解决方案是:
sqlite ~/.ipython/profile_default/history.sqlite
delete from history where source like '%password =%';
结合@Ovidiu Ghinet的answer和@Matt的accepted 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? ;) */
如果你想完全从头开始,只需手动删除以下文件(它对我有用)
/home/user/.I Python/profile_default/history.SQLite
我无法选择性地擦除IPython的历史记录,但我发现了如何通过内置的func,非sqlite方式擦除数据:
%clear out #it清除输出历史记录
顺便说一句,你也可以通过%clear清除历史
如果要从特定会话中删除历史记录,请运行:
sqlite ~/.ipython/profile_default/history.sqlite
在SQLite里面:
select * from history;
# session is the first column in history
delete from history where session=XXX;