1.查看目錄中的內容:ls
2.進入目錄:cd
cd .. 表示回到上一級目錄政基,類似 Windows 的「向上」
cd ..
cd - 表示回到上一次所在的目錄焕刮,類似 Windows 的「后退」水评。
cd -
cd ~ 表示回到當前用戶的 home 目錄,類似 Windows 的「回到桌面」(但并非桌面)昼伴。
cd ~
cd / 表示進入根目錄茶袒,它是一切目錄的父目錄
cd /
3.使用 mkdir 命令可創(chuàng)建目錄
在 mkdir 后加入 -p 參數(shù),一次性創(chuàng)建多級目錄
mkdir -p one/two/three
創(chuàng)建多級目錄
4.新建空白文檔
使用 touch 命令可以新建文件哈蝇,比如我想在 /home/shiyanlou 目錄下新建一個名為 “hello” 的文件
shiyanlou:~/ $ cd /home/shiyanlou
shiyanlou:~/ $ touch hello
touch
5.復制
使用 cp 命令(Copy)復制文件到指定目錄下棺妓,比如要把 hello 文件復制到 one/two 這個目錄下:
shiyanlou:~/ $ cp hello one/two/
shiyanlou:~/ $ tree one
one
└── two
├── hello
└── three
2 directories, 1 file
shiyanlou:~/ $
如果要復制目錄,需要在 cp 后加上 -r 炮赦,然后接上 目錄名 目標目錄名:
shiyanlou:~/ $ mkdir test
shiyanlou:~/ $ cp -r test one/two
shiyanlou:~/ $ tree one
one
└── two
├── hello
├── test
└── three
3 directories, 1 file
上面的操作中怜跑,我們先新建了一個 test 目錄,然后把它復制進了 one/two 這個目錄中吠勘,再通過tree one 直接查看 one 的目錄結構性芬。
6.?? 刪除
使用 rm 命令刪除文件:
shiyanlou:~/ $ ls
Code Desktop hello one
shiyanlou:~/ $ rm hello
shiyanlou:~/ $ ls
Code Desktop one
刪除目錄要加上 -r 選項,類似 cp -r 拷貝目錄剧防,會刪除目錄和目錄下的所有內容:
shiyanlou:~/ $ mkdir test
shiyanlou:~/ $ ls
Code Desktop one test
shiyanlou:~/ $ rm -r test
shiyanlou:~/ $ ls
Code Desktop one
7.?? 移動文件 / 目錄與重命名
使用 mv 命令可以移動文件或目錄植锉。
首先,我們進入到 /home/shiyanlou 目錄峭拘,使用 touch 創(chuàng)建空文件 test1:
shiyanlou:~/ $ cd ~
shiyanlou:~/ $ touch test1
然后俊庇,我們創(chuàng)建一個新目錄 dir1狮暑,ls 查看一下
shiyanlou:~/ $ mkdir dir1
shiyanlou:~/ $ ls
Code Desktop dir1 one test1
然后使用 mv 命令 將 test1 移動到 dir1 目錄,然后進入 dir1 目錄查看一下:
shiyanlou:~/ $ mv test1 dir1
shiyanlou:~/ $ cd dir1
shiyanlou:dir1/ $ ls
test1
使用 mv 移動文件或目錄時辉饱,如果第二個參數(shù)不存在搬男,系統(tǒng)會判斷為你在 重命名 該目錄或文件。
如 mv test1 test2彭沼,如果 test2 不存在缔逛,該命令就會把 test1 重命名為 test2:
shiyanlou:dir1/ $ ls
test1
shiyanlou:dir1/ $ mv test1 test2
shiyanlou:dir1/ $ ls
test2