./和〜/之间的区别
在创建文件路径和URL时,我注意到很多次该路径以./
或~/
开头.
When creating filepaths and URLs, I noticed that many times the path starts with ./
or ~/
.
以./
和~/
开头的文件路径有什么区别?
What is the difference between filepaths that start with ./
and ~/
?
它们各自是什么意思?
./
的意思是从当前目录开始". .
指向当前工作目录,因此类似./foo.bar
的东西将在当前目录中查找名为foo.bar
的文件. (作为附带说明,..
表示引用当前目录的父目录.因此../foo.bar
将在上方一个目录中查找该文件.)
./
means "starting from the current directory". .
refers to the current working directory, so something like ./foo.bar
would be looking for a file called foo.bar
in the current directory. (As a side note, ..
means refers to the parent directory of the current directory. So ../foo.bar
would be looking for that file one directory above.)
~/
的意思是从主目录开始".在不同的情况下,这可能具有不同的含义.例如,在Unix环境中,~/foo.bar
将在主目录中查找名为foo.bar
的文件,例如/home/totzam/foo.bar
.在许多Web应用程序中,~/foo.bar
会在Web应用程序的根目录中查找名为foo.bar
的文件,类似于/var/http/mywebapp/foo.bar
.
~/
means "starting from the home directory". This could have different meanings in different scenarios. For example, in a Unix environment ~/foo.bar
would be looking for a file called foo.bar
in your home directory, something like /home/totzam/foo.bar
. In many web applications, ~/foo.bar
would be looking for a file called foo.bar
in the web application root, something like /var/http/mywebapp/foo.bar
.