007 檔案和目錄操作命令 mv

2021-10-05 20:13:23 字數 1233 閱讀 5136

mv

#移動檔案或目錄

-i    #如果目的檔案已存在,詢問是否覆蓋。在別名中可以看到已被系統定義,可以用alis mv來檢視

-t #反轉,把源與目標反轉,詳見範例2

#### 範例1:建立/lili/chenliang目錄,然後把/lili/chenliang目錄移動到/tmp目錄下

[root@db01 ~]

# mkdir /lili/chenliang -p #建立/lili/chenliang目錄

[root@db01 ~]

# ls -ld /lili/chenliang/ #檢視/lili/chenliang目錄是否建立成功

drwxr-xr-x 2 root root 4096 jul 5 14:54 /lili/chenliang/

[root@db01 ~]

# mv /lili/chenliang/ /tmp/ #移動/lili/chenliang目錄到/tmp目錄下

[root@db01 ~]

# ls -ld /tmp/chenliang/ #檢視/lili/chenliang目錄是否成功移動到/tmp目錄下

drwxr-xr-x 2 root root 4096 jul 5 14:54 /tmp/chenliang/

#### 範例2:將/tmp/chenliang目錄移動到/lili目錄下,不能直接用mv /tmp/chenliang /lili命令

[root@db01 ~]

# find /tmp/ -maxdepth 1 -type d -name "chenliang" #先查詢出/tmp/chenliang目錄

/tmp/chenliang

[root@db01 ~]

# find /tmp/ -maxdepth 1 -type d -name "chenliang"|xargs mv -t /lili

#把/tmp/chenliang目錄移動到/lili目錄下

[root@db01 ~]

# ls -ld /lili/chenliang/ #檢視是否成功將/tmp/chenliang目錄移動到/lili目錄下

drwxr-xr-x 2 root root 4096 jul 5 14:54 /lili/chenliang/

007 檔案操作

1 類unix 中 一切裝置皆是檔案 2 操作檔案的過程 01開啟檔案,或者新建乙個檔案 02讀 寫檔案 03關閉檔案 3 開啟檔案 open 檔名,訪問模式 demo f open test.txt w 開啟檔案的目的 r 讀 w 寫 a 增 常用的 w r a 帶加號表示可以讀也可以寫 rb w...

002 檔案和目錄操作命令 touch

touch 建立檔案 a 更新檔案的訪問 acces 時間,同時檔案的改變 change 時間也會同時更新 m 更新檔案的修改 modify 時間,同時檔案的改變 change 時間也會同時更新 c 更新檔案的改變 change 時間 範例1 建立 chenliang.txt檔案 root db01...

009 檔案和目錄操作命令 rmdir

rmdir 刪除空目錄 目錄沒有任何檔案 root db01 mkdir root chenliang 建立 root chenliang目錄 root db01 ls ld root chenliang 檢視是否建立成功 drwxr xr x 2 root root 4096 jul 8 09 4...