相對路徑和絕對路徑 目錄的建立 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

相關文章
相關標籤/搜索