(五)复制、移动与删除:cp mv rm
cp(复制档案或目录)
实例一:复制单个文件到目标目录,文件在目标文件中不存在
1 [root@localhost ~]# mkdir test 2 [root@localhost ~]# ls -l 3 总用量 80 4 -rw-------. 1 root root 2454 8月 10 21:36 anaconda-ks.cfg 5 -rw--w-rw-. 1 root users 52211 8月 10 21:36 install.log 6 -rw-r--r--. 1 root root 14312 8月 10 21:34 install.log.syslog 7 drwxr-xr-x. 2 root root 4096 8月 12 01:37 test 8 [root@localhost ~]# cp install.log test //复制install.log到test文件夹下 9 [root@localhost ~]# ls -l 10 总用量 80 11 -rw-------. 1 root root 2454 8月 10 21:36 anaconda-ks.cfg 12 -rw--w-rw-. 1 root users 52211 8月 10 21:36 install.log 13 -rw-r--r--. 1 root root 14312 8月 10 21:34 install.log.syslog 14 drwxr-xr-x. 2 root root 4096 8月 12 01:37 test 15 [root@localhost ~]# cd test 16 [root@localhost test]# ls -l 17 总用量 52 18 -rw----r--. 1 root root 52211 8月 12 01:37 install.log
mv(移动档案或目录,或更名)
实例一:复制一档案,建立一目录,将档案移动到目录中
1 [root@localhost ~]# ls -l 2 总用量 128 3 -rw-------. 1 root root 2454 8月 10 21:36 anaconda-ks.cfg 4 -rw--w-rw-. 1 root users 52211 8月 10 21:36 install.log 5 -rw-r--r--. 1 root root 14312 8月 10 21:34 install.log.syslog 6 -rw----r--. 1 root root 52211 8月 12 02:31 log 7 [root@localhost ~]# mkdir test //新建一个test文件夹 8 [root@localhost ~]# mv log test //将log文件移到test文件夹下 9 [root@localhost ~]# ls -l 10 总用量 80 11 -rw-------. 1 root root 2454 8月 10 21:36 anaconda-ks.cfg 12 -rw--w-rw-. 1 root users 52211 8月 10 21:36 install.log 13 -rw-r--r--. 1 root root 14312 8月 10 21:34 install.log.syslog 14 drwxr-xr-x. 2 root root 4096 8月 12 02:43 test 15 [root@localhost ~]# cd test 16 [root@localhost test]# ls -l 17 总用量 52 18 -rw----r--. 1 root root 52211 8月 12 02:31 log 19 [root@localhost test]#
实例二:将目录改名
1 [root@localhost ~]# ls -l 2 总用量 80 3 -rw-------. 1 root root 2454 8月 10 21:36 anaconda-ks.cfg 4 -rw--w-rw-. 1 root users 52211 8月 10 21:36 install.log 5 -rw-r--r--. 1 root root 14312 8月 10 21:34 install.log.syslog 6 drwxr-xr-x. 2 root root 4096 8月 12 02:43 test 7 [root@localhost ~]# mv test qq //将test文件夹改名为qq 8 [root@localhost ~]# ls -l 9 总用量 80 10 -rw-------. 1 root root 2454 8月 10 21:36 anaconda-ks.cfg 11 -rw--w-rw-. 1 root users 52211 8月 10 21:36 install.log 12 -rw-r--r--. 1 root root 14312 8月 10 21:34 install.log.syslog 13 drwxr-xr-x. 2 root root 4096 8月 12 02:43 qq 14 [root@localhost ~]#
rm(移除档案或目录)
写法:rm [-参数] 档案或目录
参数:
-f :(force),强制删除
-i:在删除前会询问使用者是否动作
-r:递归删除,最常用在目录的删除
1 [root@localhost ~]# cd test 2 [root@localhost test]# ls -l 3 总用量 104 4 -rw----r--. 1 root root 52211 8月 12 01:37 install.log 5 -rw----r--. 1 root root 52211 8月 12 01:46 test 6 [root@localhost test]# rm -i install.log //询问删除 7 rm:是否删除普通文件 "install.log"?y 8 [root@localhost test]# ls -l 9 总用量 52 10 -rw----r--. 1 root root 52211 8月 12 01:46 test 11 [root@localhost test]#
删除一个不为空的目录 :rm -rf 目录
1 [root@localhost ~]# ls -l 2 总用量 80 3 -rw-------. 1 root root 2454 8月 10 21:36 anaconda-ks.cfg 4 -rw--w-rw-. 1 root users 52211 8月 10 21:36 install.log 5 -rw-r--r--. 1 root root 14312 8月 10 21:34 install.log.syslog 6 drwxr-xr-x. 2 root root 4096 8月 12 02:01 test 7 [root@localhost ~]# rm -rf test 8 [root@localhost ~]# ls -l 9 总用量 76 10 -rw-------. 1 root root 2454 8月 10 21:36 anaconda-ks.cfg 11 -rw--w-rw-. 1 root users 52211 8月 10 21:36 install.log 12 -rw-r--r--. 1 root root 14312 8月 10 21:34 install.log.syslog 13 [root@localhost ~]#
删除一个带有-开头的档案:rm ./档案名
1 [root@localhost ~]# echo 1>-a //新建一个-a文件 2 [root@localhost ~]# ls -l 3 总用量 84 4 -rw-r--r--. 1 root root 1 8月 12 02:10 -a 5 -rw-------. 1 root root 2454 8月 10 21:36 anaconda-ks.cfg 6 drwxr-xr-x. 2 root root 4096 8月 12 02:04 asd 7 -rw--w-rw-. 1 root users 52211 8月 10 21:36 install.log 8 -rw-r--r--. 1 root root 14312 8月 10 21:34 install.log.syslog 9 [root@localhost ~]# rm ./-a //删除一个带有-开头的文件 10 rm:是否删除普通文件 "./-a"?y 11 [root@localhost ~]# ls -l 12 总用量 80 13 -rw-------. 1 root root 2454 8月 10 21:36 anaconda-ks.cfg 14 drwxr-xr-x. 2 root root 4096 8月 12 02:04 asd 15 -rw--w-rw-. 1 root users 52211 8月 10 21:36 install.log 16 -rw-r--r--. 1 root root 14312 8月 10 21:34 install.log.syslog


浙公网安备 33010602011771号