相对路径与绝对路径
时间:2010-08-28 来源:cup
绝对路径
Linux中,绝对路径是从/(也被称为根目录)开始的,比如/usr、/etc/X11.如果一个路径是从/开始的,它一定是绝对路径,这样就好理解了。 [root@localhost ~]# pwd
/root
[root@localhost ~]# cd /usr/share/doc/ 注:以绝对路径方式进入/usr/share/doc目录下。
相对路径
相对路径,顾名思义,就是相对于当前路径的那个路径。 在路径中一些特殊符号的说明:
. 表示用户所处的当前目录;
.. 表示上级目录;
~ 表示当前用户自己的家目录;
~USER 表示用户名为USER的家目录,这里的USER是在/etc/passwd中存在的用户名。 相对于家目录 [root@localhost ~]#mkdir ~/test 注:在当前的家目录下创建一个目录s。
[root@localhost ~]#ll 注:显示当前路径下的文件。ll=ls -l 此时可以看到显示出的文件中有刚创建的s目录。 相对于当前路径 [root@localhost test]# mkdir a
[root@localhost test]# cd ./a 请注意此处的相对路径写法,.代表当前目录
[root@localhost a]# pwd
/home/test/a 易混淆点: [root@localhost ~]# ls -a 注:显示所有的文件信息,包括隐藏文件
. .bash_logout d install.log.syslog .tcshrc
.. .bash_profile .gconf .lesshst .viminfo
anaconda-ks.cfg .bashrc .gconfd s .vimrc
.bash_history .cshrc
可以看到其中有个.bashrc的隐藏文件。 [root@localhost ~]# cd /home/sungh
[root@localhost test]# cp ~/.bashrc .
[root@localhost test]# ll 注:显示文件的详细信息
total 36
-rw-r--r-- 1 root root 142 Jun 20 20:41 a.txt
-rw-r--r-- 1 root root 1 Jun 20 20:44 hosts
-rw-r--r-- 1 root root 3206 Jun 20 17:12 man.config
-rw-r--r-- 1 root root 4528 Jun 20 22:03 man.txt 由于.bashrc是隐藏文件,故没有显示出来
[root@localhost test]# ls -a 注:显示所有的文件信息,包括隐藏文件
. .. a.txt .bashrc hosts man.config man.txt
Linux中,绝对路径是从/(也被称为根目录)开始的,比如/usr、/etc/X11.如果一个路径是从/开始的,它一定是绝对路径,这样就好理解了。 [root@localhost ~]# pwd
/root
[root@localhost ~]# cd /usr/share/doc/ 注:以绝对路径方式进入/usr/share/doc目录下。
相对路径
相对路径,顾名思义,就是相对于当前路径的那个路径。 在路径中一些特殊符号的说明:
. 表示用户所处的当前目录;
.. 表示上级目录;
~ 表示当前用户自己的家目录;
~USER 表示用户名为USER的家目录,这里的USER是在/etc/passwd中存在的用户名。 相对于家目录 [root@localhost ~]#mkdir ~/test 注:在当前的家目录下创建一个目录s。
[root@localhost ~]#ll 注:显示当前路径下的文件。ll=ls -l 此时可以看到显示出的文件中有刚创建的s目录。 相对于当前路径 [root@localhost test]# mkdir a
[root@localhost test]# cd ./a 请注意此处的相对路径写法,.代表当前目录
[root@localhost a]# pwd
/home/test/a 易混淆点: [root@localhost ~]# ls -a 注:显示所有的文件信息,包括隐藏文件
. .bash_logout d install.log.syslog .tcshrc
.. .bash_profile .gconf .lesshst .viminfo
anaconda-ks.cfg .bashrc .gconfd s .vimrc
.bash_history .cshrc
可以看到其中有个.bashrc的隐藏文件。 [root@localhost ~]# cd /home/sungh
[root@localhost test]# cp ~/.bashrc .
[root@localhost test]# ll 注:显示文件的详细信息
total 36
-rw-r--r-- 1 root root 142 Jun 20 20:41 a.txt
-rw-r--r-- 1 root root 1 Jun 20 20:44 hosts
-rw-r--r-- 1 root root 3206 Jun 20 17:12 man.config
-rw-r--r-- 1 root root 4528 Jun 20 22:03 man.txt 由于.bashrc是隐藏文件,故没有显示出来
[root@localhost test]# ls -a 注:显示所有的文件信息,包括隐藏文件
. .. a.txt .bashrc hosts man.config man.txt
注:有时会有类似于~/.bashrc路径的写法,此时.不代表当前路径,而代表隐藏文件。
相关阅读 更多 +