文件的复制和移动命令:cp和mv
2016-10-17 15:04
316 查看
cp:copy复制
命令作用:
复制和移动文件;
2.命令格式:
cp [options] source...source destination //源可以有多个,目标只能有一个;
3.参数说明:
-f:force强行,强行复制不论目的文件或目录是否存在;
-i:interactive交互,覆盖之前先询问用户;
-P:preserve,保留源文件或目录的属性,包括所有者、所属组、权限与时间戳;
-r:recursive递归,递归复制,连同指定目录下的子目录和文件;
-R:recursive同-r;
-v:verbose详细,显示命令执行过程;
-a:archive档案,归档复制,保留所有属性,常用于备份,等同于-dpR;
4.范例:
[root@localhost ~]# cp /etc/inittab ./
[root@localhost ~]# ll
total 108
-rw-------. 1 root root 1645 Mar 16 2016 anaconda-ks.cfg
-rw-r--r--. 1 root root 884 Oct 16 21:13 inittab
-rw-r--r--. 1 root root 50101 Mar 16 2016 install.log
-rw-r--r--. 1 root root 10608 Mar 16 2016 install.log.syslog
[root@localhost ~]# cp -i /etc/inittab ./
cp: overwrite `./inittab'? y
[root@localhost ~]# ll
total 108
-rw-------. 1 root root 1645 Mar 16 2016 anaconda-ks.cfg
-rw-r--r--. 1 root root 884 Oct 16 21:14 inittab
-rw-r--r--. 1 root root 50101 Mar 16 2016 install.log
-rw-r--r--. 1 root root 10608 Mar 16 2016 install.log.syslog
[root@localhost ~]# cp -r /etc/ ./
[root@localhost ~]# ll
total 120
-rw-------. 1 root root 1645 Mar 16 2016 anaconda-ks.cfg
drwxr-xr-x. 120 root root 12288 Oct 16 21:18 etc
-rw-r--r--. 1 root root 884 Oct 16 21:15 inittab
-rw-r--r--. 1 root root 50101 Mar 16 2016 install.log
-rw-r--r--. 1 root root 10608 Mar 16 2016 install.log.syslog
[root@localhost ~]# cp -v /etc/passwd .
`/etc/passwd' -> `./passwd'
[root@localhost ~]# ll
total 124
-rw-------. 1 root root 1645 Mar 16 2016 anaconda-ks.cfg
drwxr-xr-x. 120 root root 12288 Oct 16 21:18 etc
-rw-r--r--. 1 root root 884 Oct 16 21:15 inittab
-rw-r--r--. 1 root root 50101 Mar 16 2016 install.log
-rw-r--r--. 1 root root 10608 Mar 16 2016 install.log.syslog
-rw-r--r--. 1 root root 1676 Oct 16 21:19 passwd
[root@localhost ~]# cp -a /etc/sudo.conf ./
cp: overwrite `./sudo.conf'? y
[root@localhost ~]# ll ./sudo.conf /etc/sudo.conf
-rw-r-----. 1 root root 1786 Sep 25 2012 ./sudo.conf
-rw-r-----. 1 root root 1786 Sep 25 2012 /etc/sudo.conf
mv:move移动
命令作用:
用来移动文件或重命名文件,经常用来备份文件或目录;
2.命令格式:
mv [options] source...source destination
3.参数说明:
-f:fource强行,如果目标已经存在则不会询问直接覆盖;
-i:interactive交互,覆盖前进行询问;
-u:update更新,若目标文件已经存在且源文件比较新才会更新;
-t:target目标,指定mv的目标目录,该选项适用于移动多个源文件到一个目标中,此时目标目录在前,源文件在后;
4.范例:
[root@localhost ~]# mv -v ./inittab /tmp
`./inittab' -> `/tmp/inittab'
[root@localhost ~]# ll /tmp
total 40
-rw-r--r--. 1 root root 884 Oct 16 21:15 inittab
drwx------. 2 root root 4096 Oct 16 20:46 keyring-U00hv0
drwx------. 2 root root 4096 Oct 15 17:18 keyring-UTq8Qb
drwx------. 2 root root 4096 Oct 16 20:47 orbit-root
drwx------. 2 cgy cgy 4096 Mar 16 2016 pulse-FsSpAseXSLkn
drwx------. 2 root root 4096 Oct 16 20:46 pulse-TuT0VNMAElV9
drwx------. 2 root root 4096 Oct 16 20:46 ssh-AhhoWr1925
drwx------. 2 root root 4096 Oct 15 19:15 virtual-root.2bgEqz
drwx------. 2 root root 4096 Oct 16 20:46 virtual-root.NWQZFc
drwx------. 2 root root 4096 Oct 15 17:18 virtual-root.wG1kVw
[root@localhost ~]# mv -i inittab /tmp
mv: overwrite `/tmp/inittab'? y
[root@localhost ~]# cp /etc/inittab .
[root@localhost ~]# mv -f inittab /tmp
[root@localhost ~]# ll /tmp
total 40
-rw-r--r--. 1 root root 884 Oct 16 21:40 inittab
drwx------. 2 root root 4096 Oct 16 20:46 keyring-U00hv0
drwx------. 2 root root 4096 Oct 15 17:18 keyring-UTq8Qb
drwx------. 2 root root 4096 Oct 16 20:47 orbit-root
drwx------. 2 cgy cgy 4096 Mar 16 2016 pulse-FsSpAseXSLkn
drwx------. 2 root root 4096 Oct 16 20:46 pulse-TuT0VNMAElV9
drwx------. 2 root root 4096 Oct 16 20:46 ssh-AhhoWr1925
drwx------. 2 root root 4096 Oct 15 19:15 virtual-root.2bgEqz
drwx------. 2 root root 4096 Oct 16 20:46 virtual-root.NWQZFc
drwx------. 2 root root 4096 Oct 15 17:18 virtual-root.wG1kVw
[root@localhost ~]# mv -t /tmp ./sudo.conf
[root@localhost ~]# ll /tmp
total 48
-rw-r--r--. 1 root root 1676 Oct 16 21:19 a
-rw-r--r--. 1 root root 884 Oct 16 21:40 inittab
drwx------. 2 root root 4096 Oct 16 20:46 keyring-U00hv0
drwx------. 2 root root 4096 Oct 15 17:18 keyring-UTq8Qb
drwx------. 2 root root 4096 Oct 16 20:47 orbit-root
drwx------. 2 cgy cgy 4096 Mar 16 2016 pulse-FsSpAseXSLkn
drwx------. 2 root root 4096 Oct 16 20:46 pulse-TuT0VNMAElV9
drwx------. 2 root root 4096 Oct 16 20:46 ssh-AhhoWr1925
-rw-r-----. 1 root root 1786 Sep 25 2012 sudo.conf
drwx------. 2 root root 4096 Oct 15 19:15 virtual-root.2bgEqz
drwx------. 2 root root 4096 Oct 16 20:46 virtual-root.NWQZFc
drwx------. 2 root root 4096 Oct 15 17:18 virtual-root.wG1kVw
命令作用:
复制和移动文件;
2.命令格式:
cp [options] source...source destination //源可以有多个,目标只能有一个;
3.参数说明:
-f:force强行,强行复制不论目的文件或目录是否存在;
-i:interactive交互,覆盖之前先询问用户;
-P:preserve,保留源文件或目录的属性,包括所有者、所属组、权限与时间戳;
-r:recursive递归,递归复制,连同指定目录下的子目录和文件;
-R:recursive同-r;
-v:verbose详细,显示命令执行过程;
-a:archive档案,归档复制,保留所有属性,常用于备份,等同于-dpR;
4.范例:
[root@localhost ~]# cp /etc/inittab ./
[root@localhost ~]# ll
total 108
-rw-------. 1 root root 1645 Mar 16 2016 anaconda-ks.cfg
-rw-r--r--. 1 root root 884 Oct 16 21:13 inittab
-rw-r--r--. 1 root root 50101 Mar 16 2016 install.log
-rw-r--r--. 1 root root 10608 Mar 16 2016 install.log.syslog
[root@localhost ~]# cp -i /etc/inittab ./
cp: overwrite `./inittab'? y
[root@localhost ~]# ll
total 108
-rw-------. 1 root root 1645 Mar 16 2016 anaconda-ks.cfg
-rw-r--r--. 1 root root 884 Oct 16 21:14 inittab
-rw-r--r--. 1 root root 50101 Mar 16 2016 install.log
-rw-r--r--. 1 root root 10608 Mar 16 2016 install.log.syslog
[root@localhost ~]# cp -r /etc/ ./
[root@localhost ~]# ll
total 120
-rw-------. 1 root root 1645 Mar 16 2016 anaconda-ks.cfg
drwxr-xr-x. 120 root root 12288 Oct 16 21:18 etc
-rw-r--r--. 1 root root 884 Oct 16 21:15 inittab
-rw-r--r--. 1 root root 50101 Mar 16 2016 install.log
-rw-r--r--. 1 root root 10608 Mar 16 2016 install.log.syslog
[root@localhost ~]# cp -v /etc/passwd .
`/etc/passwd' -> `./passwd'
[root@localhost ~]# ll
total 124
-rw-------. 1 root root 1645 Mar 16 2016 anaconda-ks.cfg
drwxr-xr-x. 120 root root 12288 Oct 16 21:18 etc
-rw-r--r--. 1 root root 884 Oct 16 21:15 inittab
-rw-r--r--. 1 root root 50101 Mar 16 2016 install.log
-rw-r--r--. 1 root root 10608 Mar 16 2016 install.log.syslog
-rw-r--r--. 1 root root 1676 Oct 16 21:19 passwd
[root@localhost ~]# cp -a /etc/sudo.conf ./
cp: overwrite `./sudo.conf'? y
[root@localhost ~]# ll ./sudo.conf /etc/sudo.conf
-rw-r-----. 1 root root 1786 Sep 25 2012 ./sudo.conf
-rw-r-----. 1 root root 1786 Sep 25 2012 /etc/sudo.conf
mv:move移动
命令作用:
用来移动文件或重命名文件,经常用来备份文件或目录;
2.命令格式:
mv [options] source...source destination
3.参数说明:
-f:fource强行,如果目标已经存在则不会询问直接覆盖;
-i:interactive交互,覆盖前进行询问;
-u:update更新,若目标文件已经存在且源文件比较新才会更新;
-t:target目标,指定mv的目标目录,该选项适用于移动多个源文件到一个目标中,此时目标目录在前,源文件在后;
4.范例:
[root@localhost ~]# mv -v ./inittab /tmp
`./inittab' -> `/tmp/inittab'
[root@localhost ~]# ll /tmp
total 40
-rw-r--r--. 1 root root 884 Oct 16 21:15 inittab
drwx------. 2 root root 4096 Oct 16 20:46 keyring-U00hv0
drwx------. 2 root root 4096 Oct 15 17:18 keyring-UTq8Qb
drwx------. 2 root root 4096 Oct 16 20:47 orbit-root
drwx------. 2 cgy cgy 4096 Mar 16 2016 pulse-FsSpAseXSLkn
drwx------. 2 root root 4096 Oct 16 20:46 pulse-TuT0VNMAElV9
drwx------. 2 root root 4096 Oct 16 20:46 ssh-AhhoWr1925
drwx------. 2 root root 4096 Oct 15 19:15 virtual-root.2bgEqz
drwx------. 2 root root 4096 Oct 16 20:46 virtual-root.NWQZFc
drwx------. 2 root root 4096 Oct 15 17:18 virtual-root.wG1kVw
[root@localhost ~]# mv -i inittab /tmp
mv: overwrite `/tmp/inittab'? y
[root@localhost ~]# cp /etc/inittab .
[root@localhost ~]# mv -f inittab /tmp
[root@localhost ~]# ll /tmp
total 40
-rw-r--r--. 1 root root 884 Oct 16 21:40 inittab
drwx------. 2 root root 4096 Oct 16 20:46 keyring-U00hv0
drwx------. 2 root root 4096 Oct 15 17:18 keyring-UTq8Qb
drwx------. 2 root root 4096 Oct 16 20:47 orbit-root
drwx------. 2 cgy cgy 4096 Mar 16 2016 pulse-FsSpAseXSLkn
drwx------. 2 root root 4096 Oct 16 20:46 pulse-TuT0VNMAElV9
drwx------. 2 root root 4096 Oct 16 20:46 ssh-AhhoWr1925
drwx------. 2 root root 4096 Oct 15 19:15 virtual-root.2bgEqz
drwx------. 2 root root 4096 Oct 16 20:46 virtual-root.NWQZFc
drwx------. 2 root root 4096 Oct 15 17:18 virtual-root.wG1kVw
[root@localhost ~]# mv -t /tmp ./sudo.conf
[root@localhost ~]# ll /tmp
total 48
-rw-r--r--. 1 root root 1676 Oct 16 21:19 a
-rw-r--r--. 1 root root 884 Oct 16 21:40 inittab
drwx------. 2 root root 4096 Oct 16 20:46 keyring-U00hv0
drwx------. 2 root root 4096 Oct 15 17:18 keyring-UTq8Qb
drwx------. 2 root root 4096 Oct 16 20:47 orbit-root
drwx------. 2 cgy cgy 4096 Mar 16 2016 pulse-FsSpAseXSLkn
drwx------. 2 root root 4096 Oct 16 20:46 pulse-TuT0VNMAElV9
drwx------. 2 root root 4096 Oct 16 20:46 ssh-AhhoWr1925
-rw-r-----. 1 root root 1786 Sep 25 2012 sudo.conf
drwx------. 2 root root 4096 Oct 15 19:15 virtual-root.2bgEqz
drwx------. 2 root root 4096 Oct 16 20:46 virtual-root.NWQZFc
drwx------. 2 root root 4096 Oct 15 17:18 virtual-root.wG1kVw
相关文章推荐
- linux下文件的复制、移动与删除命令为:cp,mv,rm
- linux-14基础命令之-复制(cp)移动(mv),删除(rm),拷贝文件(dd)
- Linux命令之目录切换、创建/删除/复制/移动文件 - cd,mkdir,cp,mv,rmdir,rm
- Linux命令学习(一):复制(cp),删除(rm)和移动(mv)文件的命令
- linux下文件的复制、移动与删除命令为:cp,mv,rm
- linux下文件的复制、移动与删除命令为:cp,mv,rm
- linux下文件的复制、移动与删除命令为:cp,mv,rm
- linux命令---复制和移动文件 cp和mv
- 文件的复制,移动和删除命令(cp,mv,rm)
- linux 命令之 复制移动重命名(cp ,mv ,install)
- Linux基础命令之-复制、删除与移动:cp,rm,mv
- linux中cp复制、mv移动、重命名,SVN回滚命令的应用
- Linux命令:cp 命令--创建文件和目录的副本 mv命令--移动或重命名文件/目录
- 02.linux的文件系统简介、查看目录ls命令、切换目录cd命令、创建目录mkdir、删除目录rm、移动重命名mv、创建文件touch、拷贝cp
- linux学习(6) ls(查看文件,目录) 复制、删除与移动: cp, rm, mv,取得路径的文件名称与目录名称
- 关于linux下的复制命令cp,文件覆盖时不提示overwrite的方法
- linux学习笔记(三) 复制、删除、移动、重命名文件(文件夹)命令
- Linux 入门常用命令-2.Linux文件的复制、删除和移动命令
- Unix移动复制mv cp
- LINUX CP 复制文件 命令