158

once i click Tab on bash, the error message will appear, what's wrong?

symlink-hook: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
symlink-hook: error retrieving current directory: getcwd: cannot access parent directories: Success
symlink-hook: error retrieving current directory: getcwd: cannot access parent directories: Success
symlink-hook: error retrieving current directory: getcwd: cannot access parent directories: Success
symlink-hook: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
symlink-hook: error retrieving current directory: getcwd: cannot access parent directories: Success
symlink-hook: error retrieving current directory: getcwd: cannot access parent directories: Success
symlink-hook: error retrieving current directory: getcwd: cannot access parent directories: Success

sometimes, the error message is:

shell-init: error retrieving current directory: getcwd: cannot access parent directories: No s uch file or directory

how to solve shell init problem?

hugemeow
  • 7,177
  • 13
  • 43
  • 59

4 Answers4

296

This usually occurs when your current directory does not exist anymore. Most likely, from another terminal you remove that directory (from within a script or whatever). To get rid of this, in case your current directory was recreated in the meantime, just cd to another (existing) directory and then cd back; the simplest would be: cd; cd -.

Costi Ciudatu
  • 33,403
  • 5
  • 52
  • 89
  • 3
    i don't think my dir is not exist, not someone have recreated it, i am in /root... so the issue maybe a bit different as your saying... – hugemeow Sep 09 '12 at 14:24
  • 1
    can you check your HOME env variable ? `echo $HOME`; if that points to an unexisting location, that't it. – Costi Ciudatu Sep 09 '12 at 15:57
  • 1
    (i use shell in tmux)Tab works well some times, but sometimes when i create new tab with tmux, press Tab, and this error appears, i don't know what happened:( – hugemeow Sep 15 '12 at 18:39
  • @kevinarpe That's good to know, thanks! I always thought it was smart enough to do nothing on `cd .` – Costi Ciudatu May 27 '15 at 07:18
  • @kevinarpe, I'd strongly suggest `cd "$PWD"` rather than `cd $(pwd)`; the latter is both inefficient (spawning a subshell) and buggy (string-splitting and glob-expanding the directory name, so it fails on directories with spaces, directories whose names contain wildcards that successfully match anything else on disk, and other such "fun" cases). – Charles Duffy Sep 02 '15 at 21:06
  • @CharlesDuffy: Good point. (1) I don't know why I forgot to wrap with double quotes. (2) If `PWD` is guarantee to be defined, then it is certainly faster than called `pwd` from a subshell. My original comment should have read: As a trick: `cd `. or `cd "$(pwd)"` will also work. – kevinarpe Sep 03 '15 at 11:29
  • 2
    @kevinarpe, yes, `$PWD` is guaranteed by POSIX to be defined. See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html – Charles Duffy Sep 03 '15 at 16:38
65

Just change the directory to another one and come back. Probably that one has been deleted or moved.

HimalayanCoder
  • 8,577
  • 4
  • 49
  • 57
Meetai.com
  • 5,800
  • 3
  • 28
  • 35
7

By chance, is this occurring on a directory using OverlayFS (or some other special file system type)?

I just had this issue where my cross-compiled version of bash would use an internal implementation of getcwd which has issues with OverlayFS. I found information about this here:

It seems that this can be traced to an internal implementation of getcwd() in bash. When cross-compiled, it can't check for getcwd() use of malloc, so it is cautious and sets GETCWD_BROKEN and uses an internal implementation of getcwd(). This internal implementation doesn't seem to work well with OverlayFS.

http://permalink.gmane.org/gmane.linux.embedded.yocto.general/25204

You can configure and rebuild bash with bash_cv_getcwd_malloc=yes (if you're actually building bash and your C library does malloc a getcwd call).

jdknight
  • 1,526
  • 27
  • 46
6

Yes, cd; and cd - would work. The reason It can see is that, directory is being deleted from any other terminal or any other program and recreate it. So i-node entry is modified so program can not access old i-node entry.

Viraj Kulkarni
  • 129
  • 2
  • 4
  • I was able to fix it on ubuntu 14 by doing the full library updates here: https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-ubuntu-16-04 – Richard Day Dec 15 '17 at 22:30