相对路径和绝对路径 目录的建立 cd mkdir rm 等命令

   1. 相对路径和绝对路径linux

       若用比喻的话,  相对路径以我的当前位置为中心,绝对路径以地球为中心。vim

        相对路径,对于我的而言,是随时均可能变化的。ide

        而绝对路径,就跟咱们现实中的街道地址同样,几乎都没有变化的。spa

       linux中,相对路径,都是针对于你如今,所工做的目录而言的。it

       而绝对路径,就是从根目录开始的, 找任何路径都从根目录开始,就能够理解为绝对路径,其它的,就能够理解为相对路径。class

   2. 目录的建立 :test

    mkdir 命令,  所带的参数有  -p
file

    建立一个目录能够用:im

    mkdir  dirnametouch

    建立多个层级目录能够用

    mkdir -p   dirname/dirname1/dirname2

    同时建立多个目录用

    mkdir dir dir1 dir2    或  mkdir {dir1,dir2,dir3}

如:

nfyx@nfyx:~/test$ ls
nfyx@nfyx:~/test$ mkdir 11
nfyx@nfyx:~/test$ ls
11
nfyx@nfyx:~/test$  mkdir 22/33
mkdir: 没法建立目录"22/33": 没有那个文件或目录
nfyx@nfyx:~/test$ mkdir -p 22/33
nfyx@nfyx:~/test$ ls 22/33
nfyx@nfyx:~/test$ cd 22/33
nfyx@nfyx:~/test/22/33$ pwd
/home/nfyx/test/22/33
nfyx@nfyx:~/test/22/33$ cd ../../
nfyx@nfyx:~/test$ pwd
/home/nfyx/test
nfyx@nfyx:~/test$ mkdir 44 55
nfyx@nfyx:~/test$ ls
11  22  44  55
nfyx@nfyx:~/test$ mkdir {66,77}
nfyx@nfyx:~/test$ ls
11  22  44  55  66  77
nfyx@nfyx:~/test$


2 目录删除 rmdir (只能删除空目录)

rmdir  dirname   (它的用处不是很大)

如:

nfyx@nfyx:~/test$ ls
11  22  44  55  66  77
nfyx@nfyx:~/test$ rmdir 11
nfyx@nfyx:~/test$ ls
22  44  55  66  77
nfyx@nfyx:~/test$ touch ./22/aa
nfyx@nfyx:~/test$ rmdir 22
rmdir: 删除 '22' 失败: 目录非空


3. rm命令(这是常常用的命令)

 rm filename (若不带参数的话,只能删除一个文件)

 rm -r  dirname  删一个目录 带r参数

 rm -rf  dirname 或 filename  强制删除目录或文件, 这命令也是最经常使用的。

如:

nfyx@nfyx:~/test$ ls
44  55  66  77
nfyx@nfyx:~/test$ touch aa
nfyx@nfyx:~/test$ ls
44  55  66  77  aa
nfyx@nfyx:~/test$ rm aa
nfyx@nfyx:~/test$ ls
44  55  66  77
nfyx@nfyx:~/test$ rm 44
rm: 没法删除'44': 是一个目录
nfyx@nfyx:~/test$ rm -r 44
nfyx@nfyx:~/test$ ls
55  66  77
nfyx@nfyx:~/test$ touch ./55/aa
nfyx@nfyx:~/test$ rm -r 55
nfyx@nfyx:~/test$ ls
66  77
nfyx@nfyx:~/test$ vim aa
nfyx@nfyx:~/test$ ls
66  77  aa
nfyx@nfyx:~/test$ rm aa
nfyx@nfyx:~/test$ ls
66  77
nfyx@nfyx:~/test$


4. cd 命令(改变目录或理解为,进入到指定目录)


cd  ./dirname   (进入一个目录,即进入相对目录)

注释:  ./  表示当前目录下的***

               ..  表示当前目录的上一层目录  (即 cd ..  就表示进入上一层目录(父目录))

cd /path/to/dirname (进入一个绝对路径的目录)

如:

nfyx@nfyx:~/test$ ls
66  77
nfyx@nfyx:~/test$ cd 66
nfyx@nfyx:~/test/66$ pwd
/home/nfyx/test/66
nfyx@nfyx:~/test/66$ cd /home/nfyx/test/77
nfyx@nfyx:~/test/77$ pwd
/home/nfyx/test/77
nfyx@nfyx:~/test/77$


2017.10.24

相关文章
相关标签/搜索