下面介紹三個文件cp, mv, rm管理命令:
- cp命令:copy,復制命令
命令格式: cp 源文件 目標文件
復制又分為單源復制和多源復制兩種情況:- 單源復制
- 如果目標文件不存在,創建此文件,并復制數據流到此文件;
[root@localhost tmp]# cp yum.log ok [root@localhost tmp]# ls -l total 4 drwxr-xr-x. 2 root root 21 Feb 28 02:38 ok -rw-------. 1 root root 24 Feb 28 02:29 yum.log [root@localhost tmp]# ls -l ok/ total 4 -rw-------. 1 root root 24 Feb 28 02:38 yum.log
- 如果目標文件存在
- 目標文件是非目錄文件,覆蓋目標文件;
[root@localhost tmp]# cat ok/yum.log !!!!! [root@localhost tmp]# cp yum.log ok/ cp: overwrite ‘ok/yum.log’? y [root@localhost tmp]# cat ok/yum.log aaaaa bbbbb ccccc ddddd
- 目標文件是目錄文件,先在目錄下創建此文件,并復制數據流到此文件;
[root@localhost tmp]# tree . ├── ok └── yum.log [root@localhost tmp]# cp yum.log ok/ [root@localhost tmp]# tree . ├── ok │ └── yum.log └── yum.log 1 directory, 2 files
- 目標文件是非目錄文件,覆蓋目標文件;
- 如果目標文件不存在,創建此文件,并復制數據流到此文件;
- 多源復制
- 目標不存在;錯誤提示;
[root@localhost tmp]# tree . ├── ok ├── yum1.log └── yum.log 1 directory, 2 files [root@localhost tmp]# cp {yum.log,yum1.log} ok1 cp: target ‘ok1’ is not a directory
- 目標存在:
- 目標非目錄,錯誤;
[root@localhost tmp]# ls -l total 12 -rw-r--r--. 1 root root 7 Feb 28 03:11 aaa drwxr-xr-x. 2 root root 6 Feb 28 03:05 ok -rw-------. 1 root root 30 Feb 28 03:02 yum1.log -rw-------. 1 root root 24 Feb 28 02:29 yum.log [root@localhost tmp]# cp {yum.log,yum1.log} aaa cp: target ‘aaa’ is not a directory
- 目標是目錄文件,分別復制每個文件到目錄中,保持原名
[root@localhost tmp]# tree . ├── aaa ├── ok ├── yum1.log └── yum.log 1 directory, 3 files [root@localhost tmp]# cp {yum.log,yum1.log} ok/ [root@localhost tmp]# tree . ├── aaa ├── ok │ ├── yum1.log │ └── yum.log ├── yum1.log └── yum.log 1 directory, 5 files
- 目標非目錄,錯誤;
- 目標不存在;錯誤提示;
- 單源復制
- mv命令:move,移動命令
命令格式:mv 源文件 目標文件 (除了復制成功后刪除源文件,其他都和復制命令相同)- 剪切到ok目錄下
[root@localhost tmp]# tree . ├── aaa ├── ok ├── yum1.log └── yum.log 1 directory, 3 files [root@localhost tmp]# mv {yum.log,yum1.log} ok/ [root@localhost tmp]# tree . ├── aaa └── ok ├── yum1.log └── yum.log 1 directory, 3 files
- ok目錄改名為yes目錄
[root@localhost tmp]# tree . ├── aaa └── ok ├── yum1.log └── yum.log 1 directory, 3 files [root@localhost tmp]# mv ok/ yes/ [root@localhost tmp]# tree . ├── aaa └── yes ├── yum1.log └── yum.log 1 directory, 3 files
- 剪切到ok目錄下
- rm命令:remove,刪除命令
[root@localhost tmp]# tree . ├── aaa └── yes ├── yum1.log └── yum.log 1 directory, 3 files [root@localhost tmp]# rm -rf yes/ [root@localhost tmp]# tree . └── aaa 0 directories, 1 file
危險操作:rm -rf /*
注意:不用的文件單獨放到獨立目錄,不要輕易刪除,否則找不回來;
本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/91778
盡量把一周作業寫在一個博客上。