这个问题困扰我很久了,现在越来越难了。在 Mac OS X 上,当我输入目录(例如)时cd /adirectory/another/andelse
,我找不到它。我只能输入直接目录(例如)cd Documents/Sites
。好吧,我的终端无法识别以“/”开头的绝对目录。我的终端是 bash。我知道你们所有的答案。
这是我的bash_profile
:
# Path for mysql
export PATH="/usr/local/mysql/bin:$PATH"
# Path for composer
export PATH="~/.composer/vendor/bin:$PATH"
# MacPorts Installer addition on 2016-01-25_at_17:56:55: adding an appropriate PATH variable for use with MacPorts.
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
# Finished adapting your PATH environment variable for use with MacPorts.
export PATH="/usr/local/bin:$PATH"
# Setting PATH for Python 3.5
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH
答案1
当目录以/
它开头时完全限定路径或文件名。相对路径基于当前目录,但完全限定路径/
每次都会从根目录 ( ) 重新开始。因此,cd adir
由于adir
位于当前目录中,因此可以正常工作,但由于不在根目录中,因此cd /adir
会失败。adir
$ mkdir adir
$ ls
adir
$ cd adir
$ pwd
/home/chicks/Documents/se-code-review/x/adir
$ cd .. # not required, but starting from the same place as the other cd
$ cd /adir
-bash: cd: /adir: No such file or directory
$ ls /
bin boot dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var www
PATH
您的条目有所.bash_profile
不同。这些条目指定了在何处查找运行的命令,但这对 bash 如何解释您指定的目录名称没有影响。