不幸的是我刚刚用我的.bashrc
覆盖
echo "command" > ~/.bashrc
而不是通过追加
echo "command" >> ~/.bashrc
。
不是一个巨大的倒退,因为我更新在terminal工作。 但是我很好奇,如果有可能恢复我的.bashrc
重新启动我的terminal会话之前!
有会话命令存储的位置吗? 如果是这样 – 我如何提取我的自定义脚本?
期待最坏的消息,希望得到最好的消息! 我正在运行一个Ubuntu 13.04盒,会话在Guaketerminal – 如果这改变了一切。
你不能完全恢复。 但是你可以部分恢复使用set
。
如果你在同一个终端上运行set
,你将能够得到一个自定义脚本和其他环境变量集的完整列表。 在这方面,需要区分那些属于.bashrc
和其他类型的终端。 但是,您将无法恢复曾经作为bash登录的一部分执行的命令。
为了将来你可以考虑使用一个版本控制系统,比如git或者hg来保存以前版本的文件,比如~/.bashrc
。 那么如果将来你碰巧做了一个>
而不是>>
,那么你应该可以将文件恢复到最后一次提交给版本控制的时候。
一个如何设置为git
的例子是:
cd ~ git init git add ~/.bashrc git commit -m "Added .bashrc to version control" # Time goes by... echo "export FOO=bar" >> ~/.bashrc # Added a new line git commit -am "Added FOO to .bashrc" # Time goes by... echo "export SHEEP=lambs" > ~/.bashrc # Eeek! We've overwritten our file # Version control to the rescue git checkout ~/.bashrc # file is restored echo "export SHEEP=lambs" >> ~/.bashrc # Done correctly this time! git commit -am "Added SHEEP to .bashrc"
假设你用一堆类似的echo
命令构建了你的.bashrc
,你只需要检索它们:
有会话命令存储的位置吗?
如果您运行history
,则应该能够检索先前的命令。 欲了解更多信息,请参阅man history
。
在你的情况下,你可能会发现history | grep bashrc
的输出 history | grep bashrc
很有用。