下面介绍三个文件cp, mv, rm管理命令:
1、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 |
2、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 |
3、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 /*
注意:不用的文件单独放到独立目录,不要轻易删除,否则找不回来;
上文内容不用于商业目的,如涉及知识产权问题,请权利人联系博为峰小编(021-64471599-8017),我们将立即处理。