【问题标题】:Preserve history between sessions of terminal usage (Mac osx)保留终端使用会话之间的历史记录(Mac osx)
【发布时间】:2016-04-22 16:55:11
【问题描述】:

我遵循了不同的指南:https://apple.stackexchange.com/questions/50649/how-to-make-bash-terminal-app-remember-history-of-previous-sessions

并调用了三个命令:

sudo -iu root
cd ~(myusername)
chown (myusername) .bash_history

但现在每次启动终端时,我都会得到以下输出:

Last login: Thu Apr 21 15:39:19 on ttys000
-bash: USERNAME: No such file or directory

我仍然无法使用向上箭头键检索历史记录中的最新命令。我知道我不应该执行我不知道其含义的命令。谁能指出我正确的方向,将我的终端放回原位,并在关闭终端时帮助保存历史记录?

【问题讨论】:

    标签: macos terminal


    【解决方案1】:

    您输入的确切命令是什么?我的意思是,大概你确实用你的名字代替了(myusername),不是吗?和命令

    cd ~(myusername)
    

    对我来说毫无意义。就其本身而言,

    cd ~ 
    

    会将您带到您的主目录。

    好的。基本故障排除(把你的答案放在这里)。加载终端并输入(请注意,无需为此使用 sudo):

    cd ~ # changes to your home directory
    ls -la .bash_history # checks the permissions and ownership of your bash_history
    

    您的 bash 历史记录应具有以下权限(或类似权限):

    -rw-------@ 1 headbanger  staff  10619 20 Apr 17:08 .bash_history
    

    所以,如果我要为我的帐户解决此问题,我会输入:

    chown headbanger:staff .bash_history # if you aren't the owner, it will be necessary to use sudo here.
    chmod "u+rw,go-rwx" .bash_history # greybeards will use Octal 600 for this
    

    我已经避免在 chmod 中使用八进制以使其更具可读性。 chmod 中的字母含义如下:

    u User
    g Group
    o Other
    a All (u,g & o)
    
    - Remove permission
    + Add permission
    = Set permission
    
    r Read
    w Write
    x Execute
    

    让我们知道你的进展情况!

    【讨论】:

    • 所以对于您的第一条评论,我使用了 cd ~akashkakumani 然后我按照您的建议将其余的 headbanger 替换为 akashkakumani 但是当我重新启动终端时,我仍然留下:
    • 上次登录时间:4 月 23 日星期六 16:22:47 在 ttys000 -bash: 用户名:没有这样的文件或目录 wireless1x-155-41-93-240:~ akashkakumani$
    • 这是一个小问题 - 但 'cd ~akashkakumani' 和 'cd ~' 会做同样的事情。请问你能显示'ls -la .bash_history'的结果吗
    猜你喜欢
    • 1970-01-01
    • 2012-12-21
    • 2012-09-10
    • 2020-07-14
    • 1970-01-01
    • 1970-01-01
    • 2013-09-01
    • 2018-11-22
    • 1970-01-01
    相关资源
    最近更新 更多