cp命令
cp是用來將文件進行單源或多源文件或目錄複製到指定的文件或目錄
語法
cp [OPTION]... [-T] SOURCE DEST 單源複製 cp [OPTION]... SOURCE... DIRECTORY 多源複製目標必須是目錄 cp [OPTION]... -t DIRECTORY SOURCE...多源複製目標必須是目錄
常用選項
-a,--archive #備份的時候用 跟-dR 同義 same as -dR --preserve=all -d #如果文件爲link#鏈接不加-d默認複製link指定文件。加-d只複製軟鏈接文件 -f, --force #強制複製,無論目的文件是否存在 -i, --interactive #覆蓋之間詢問用戶 prompt before overwrite (overrides a previous -n option) -l, --link #創建硬鏈接 link files instead of copying -p same as --preserve=mode,ownership, --preserve[=ATTR_LIST] #保留源文件的屬主、權限、時間戳 preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes: context, links, xattr, all -R, -r, --recursive #遞歸,用來複制目錄 copy directories recursively -s, --symbolic-link 複製軟鏈接 make symbolic links instead of copying -v, --verbose #顯示詳細操作 explain what is being done
示例
[root@localhost /]# cp -a /etc /testdir/ #遞歸複製,onwership,timestamp,mode不變 [root@localhost /]# ll -d /etc /testdir/etc/ drwxr-xr-x. 102 root root 12288 Jul 26 11:40 /etc drwxr-xr-x. 102 root root 12288 Jul 26 11:40 /testdir/etc/ [root@localhost /]# cp /etc/redhat-release /testdir/noaddd [root@localhost /]# cp -d /etc/redhat-release /testdir/addd #複製軟鏈接 [root@localhost /]# ll /testdir/ total 4 lrwxrwxrwx 1 root root 14 Jul 26 11:46 addd -> centos-release #只複製軟鏈接一般鏈接錯誤 -rw-r--r-- 1 root root 27 Jul 26 11:46 noaddd [root@localhost /]# cp -s /etc/redhat-release /testdir/#-s創建正確的路徑的鏈接文件 [root@localhost /]# ll /testdir/ total 0 lrwxrwxrwx 1 root root 19 Jul 26 11:52 redhat-release -> /etc/redhat-release [root@localhost /]# cp -r /boot/ /testdir/ #-r複製目錄 [root@localhost /]# ll /testdir/ total 4 dr-xr-xr-x 5 root root 4096 Jul 26 11:55 boot [root@localhost /]# cp -v /etc/issue /etc/fstab /testdir/ `/etc/issue' -> `/testdir/issue' #顯示詳細信息 多源複製目標必須是目錄 `/etc/fstab' -> `/testdir/fstab' [root@localhost /]# ll /testdir/ total 8 -rw-r--r-- 1 root root 921 Jul 26 11:57 fstab -rw-r--r-- 1 root root 103 Jul 26 11:57 issue ......
mv命令
mv - move (rename) files #移動或從命名文件或目錄
語法
mv [OPTION]... [-T] SOURCE DEST 單源移動 mv [OPTION]... SOURCE... DIRECTORY #多源移動 必須目錄 mv [OPTION]... -t DIRECTORY SOURCE... #多源移動 必須目錄
常用選項
-f, --force #不提示覆蓋。 -i, --interactive #覆蓋前提醒用戶 -v, --verbose #顯示詳細過程
示例
[root@localhost /]# touch /testdir/fiel file1 #創建空文件做實驗 [root@localhost /]# mv /etc/issue /testdir/fiel #把文件複製覆蓋,默認是-i提醒 mv: overwrite `/testdir/fiel'? yes [root@localhost /]# mv -f /etc/fstab /testdir/fiel1 #把文件覆蓋, -f不提醒覆蓋。 [root@localhost /]# mv -v /etc/inittab /testdir/ `/etc/inittab' -> `/testdir/inittab' #顯示詳細信息 [root@localhost testdir]# mv file fi #相同路徑移動表示更改用戶名 [root@localhost testdir]# ls fi file1
rm命令
rm - remove files or directories #刪除文件或目錄。Linux中文件刪除是無法找回的,使用此命令請慎重
語法
rm [OPTION]... FILE...
常用選項
-f, --force #直接刪除,不提醒 -i #提醒用戶是否刪除,別名定義加有-i -r, -R, --recursive #遞歸,用來刪除目錄 -v, --verbose :顯示詳細過程
示例
[root@localhost roooa]# ls dir3 dir4 file7 file8 inittab [root@localhost roooa]# rm file7 #移除file7文件,默認交互是提醒 rm: remove regular empty file `file7'? yes [root@localhost roooa]# rm -r dir3/ #遞歸移除目錄 rm: descend into directory `dir3'? yes rm: remove regular empty file `dir3/fill2'? yes rm: remove regular empty file `dir3/fill3'? yes rm: remove regular empty file `dir3/fill1'? yes rm: remove directory `dir3'? yes [root@localhost roooa]# rm -fr dir4/ #強制刪除不提醒