Linux 常用目錄操作命令

2021-10-24 21:36:21 字數 3664 閱讀 1408

ls:(英文全拼:list files): 列出目錄及檔名

檢視根目錄的檔案分布

ls

/----------------------------

bin dev initrd.img lib64 mnt root snap sys var

boot etc initrd.img.old lost+found opt run srv tmp vmlinuz

cdrom home lib media proc sbin swapfile usr vmlinuz.old

cd:(英文全拼:change directory):切換目錄

clencay@ubuntu:~$ cd desktop/

--------------------------------

-clencay@ubuntu:~/desktop$

pwd:(英文全拼:print work directory):顯示目前的目錄

pwd

[-p]

# -p :顯示出確實的路徑,而非使用鏈結 (link) 路徑

clencay@ubuntu:~/desktop$ pwd

--------------------------------

-/home/clencay/desktop

mkidir:(英文全拼:make directory):建立乙個新的目錄

mkdir [-mp

] 目錄名稱

# -m :配置檔案的許可權喔!直接配置,不需要看預設許可權 (umask) 的臉色~

clencay@ubuntu:~/desktop$ mkdir a

clencay@ubuntu:~/desktop$ ls

----------------------------------

a----------------------------------

clencay@ubuntu:~/desktop$ mkdir a/b/c

--------------------------------------

mkdir: 無法建立目錄"a/b/c": 沒有那個檔案或目錄

----------------------------------------

clencay@ubuntu:~/desktop$ mkdir -p a/b/c #可以建立目錄a/b/c

clencay@ubuntu:~/desktop$ mkdir -m 711 test #建立檔案許可權

clencay@ubuntu:~/desktop$ ls

-l-----------------------------------

drwx--x--x 2 root root 4096 jul 18 12:54 test

rmdir:(英文全拼:remove directory):刪除乙個空的目錄

rmdir

[-p] 目錄名稱

clencay@ubuntu:~/desktop$ rmdir a #a為空,不為空刪除失敗

clencay@ubuntu:~/desktop$ ls

----------------------------------

clencay@ubuntu:~/desktop$

#若檔案a為 a/b/c,則需要加-p引數

clencay@ubuntu:~/desktop$ rmdir

-p a/b/c

clencay@ubuntu:~/desktop$ ls

clencay@ubuntu:~/desktop$

**cp: ** (英文全拼:copy file): 複製檔案或目錄

cp

[-adfilprsu] **檔(source) 目標檔(destination)

cp[options] source1 source2 source3 ...

. directory

#-f:為強制(force)的意思,若目標檔案已經存在且無法開啟,則移除後再嘗試一次;

#-i:若目標檔(destination)已經存在時,在覆蓋時會先詢問動作的進行(常用)

#-l:進行硬式鏈結(hard link)的鏈結檔建立,而非複製檔案本身;

#-p:連同檔案的屬性一起複製過去,而非使用預設屬性(備份常用);

#-r:遞迴持續複製,用於目錄的複製行為;(常用)

#-s:複製成為符號鏈結檔 (symbolic link),亦即『捷徑』檔案;

#-u:若 destination 比 source 舊才公升級 destination !

clencay@ubuntu:~/desktop$ cp

-r a b

clencay@ubuntu:~/desktop$ ls

----------------------------------------

a b

clencay@ubuntu:~/desktop$

**rm: ** ( 英文全拼:remove): 移除檔案或目錄

rm

[-fir] 檔案或目錄

#-f :就是 force 的意思,忽略不存在的檔案,不會出現警告資訊;

#-i :互動模式,在刪除前會詢問使用者是否動作

#-r :遞迴刪除啊!最常用在目錄的刪除了!這是非常危險的選項!!!

clencay@ubuntu:~/desktop$ rm

-r a

clencay@ubuntu:~/desktop$ ls

-----------------------------------

bclencay@ubuntu:~/desktop$

**mv: ** (英文全拼:move file): 移動檔案與目錄,或修改檔案與目錄的名稱

mv

[-fiu] source destination

mv[options] source1 source2 source3 ...

. directory

#-f :force 強制的意思,如果目標檔案已經存在,不會詢問而直接覆蓋;

#-i :若目標檔案 (destination) 已經存在時,就會詢問是否覆蓋!

#-u :若目標檔案已經存在,且 source 比較新,才會公升級 (update)

clencay@ubuntu:~/desktop$ ls

bclencay@ubuntu:~/desktop$ mv b a

----------------------------------

clencay@ubuntu:~/desktop$ ls

aclencay@ubuntu:~/desktop$

常用的Linux目錄操作命令

1 比較特殊的目錄 代表此層目錄 代表上一層目錄 代表前乙個目錄 代表前乙個目錄 account 代表account這個使用者的主資料夾 linux下的每乙個目錄都存在此層目錄上上層目錄,根目錄的上層目錄就是它本身。2 常見的處理目錄的命令 引數的意義 引數意義 f強制 force 的意思,表示強制...

Linux命令 常用目錄和檔案操作命令

在linux系統當中,ls 命令可能是最常被執行的。選項與引數 a 全部的檔案,連同隱藏檔 開頭為 的檔案 一起列出來 常用 d 僅列出目錄本身,而不是列出目錄內的檔案資料 常用 l 長資料串列出,包含檔案的屬性與許可權等等資料 常用 pwd是print working directory的縮寫,也...

Linux常用命令 目錄操作命令

主要用於顯示目錄下的內容 選項分類 root localhost ls 選項 檔名或目錄名 選項 a 顯示所有檔案 color when 支援顏色輸出,when的值預設是always 總顯示顏色 也可以never 從不顯示顏色 和auto 自動 d 顯示目錄資訊,而不是目錄下的檔案 h 人性化顯示 ...