标签:txt strong span 就会 移动目录 linux /usr 目标 lin
Linux第二周学习笔记(6)2.12.MV命令
mv命令:用来对文件或目录重新命名,或者将文件从一个目录移到另一个目录中。
---------------------------------------------------------------------------------------------
文件更名:把/tmp/目录里面的01.txt改名为01.1.txt
[root@daizhihong01 ~]# ls /tmp/
01.txt
daizhihong
daizhihong1
daizhihong3
ks-script-9pf2WE
yum.log
[root@daizhihong01 ~]# cd /tmp/
[root@daizhihong01 tmp]# mv 01.txt 01.1.txt(把01.txt名称改为01.1.txt)
[root@daizhihong01 tmp]# ls /tmp/
01.1.txt
daizhihong
daizhihong1
daizhihong3
ks-script-9pf2WE
---------------------------------------------------------------------------------------------
把文件移动到其它分区并且改名字:
把/tmp/目录下的01.1.txt文件移动到root分区下并且把01.1.txt改名为02.txt
[root@daizhihong01 tmp]# ls
01.1.txt
daizhihong
daizhihong1
daizhihong3
ks-script-9pf2WE
[root@daizhihong01 tmp]# mv 01.1.txt /root/02.txt(把/tmp/目录下的01.1.txt文件移动到root分区下并且把01.1.txt改名为02.txt)
[root@daizhihong01 tmp]# ls
daizhihong
daizhihong1
daizhihong3
ks-script-9pf2WE
[root@daizhihong01 tmp]# ls /root/
02.txt anaconda-ks.cfg(01.1.txt已经移动到/root/目录下并且更名为02.txt)
---------------------------------------------------------------------------------------------
把文件移动到目录下:把/tmp/目录下的11.txt文件移动到/tmp/daizhihong/目录下
[root@daizhihong01 tmp]# tree daizhihong/
daizhihong/
0 directories, 0 files
[root@daizhihong01 tmp]# ls
11.txt
daizhihong
daizhihong1
daizhihong3
ks-script-9pf2WE
yum.log
[root@daizhihong01 tmp]# mv 11.txt daizhihong/
[root@daizhihong01 tmp]# ls
daizhihong
daizhihong1
daizhihong3
ks-script-9pf2WE
yum.log
[root@daizhihong01 tmp]# tree daizhihong/
daizhihong/
└── 11.txt
0 directories, 1 file
-----------------------------------------------------------------------------------------------
“-i”的参数:在我们使用which查询命令绝对路径的时候会出现一个“-i”的参数,这个参数的意义是一个安全参数,询问是否执行就是因为加了“-i”的参数
[root@daizhihong01 tmp]# touch 11.txt
[root@daizhihong01 tmp]# ls
11.txt
daizhihong
daizhihong1
daizhihong3
ks-script-9pf2WE
yum.log
[root@daizhihong01 tmp]# mv 11.txt daizhihong/
mv:是否覆盖"daizhihong/11.txt"? n((加了“-i”参数就会提示是否需要覆盖或者执行rm命令的时候是否需要删除,所以“-i”是一个安全参数))
键入命令的时候不询问命令格式如下:
[root@daizhihong01 tmp]# /usr/bin/mv 11.txt daizhihong/使用
[root@daizhihong01 tmp]#
绝对路径命令格式执行就不会提示询问,直接覆盖
[root@daizhihong01 tmp]# ls
daizhihong
daizhihong1
daizhihong3
ks-script-9pf2WE
yum.log
[root@daizhihong01 tmp]# ls daizhihong
11.txt
-----------------------------------------------------------------------------------------
移动目录:把/tmp/daizhizhong1/目录移动到/tmp/daizhizhong/目录下,如果该目录存在,则会把源文件或目录移动到该目录当中
[root@daizhihong01 tmp]# ls
daizhihong
daizhihong1
daizhihong3
ks-script-9pf2WE
[root@daizhihong01 tmp]# mv daizhihong1/ daizhong/
[root@daizhihong01 tmp]# ls
daizhihong
daizhihong3
daizhong
ks-script-9pf2WE
--------------------------------------------------------------------------------------------
目录移动的时候目标目录不存在,就会把源目录从命名为给定的目标文件名
[root@daizhihong01 tmp]# ls
Daizhihong(源文件)
daizhihong3
daizhong
ks-script-9pf2WE
yum.log
[root@daizhihong01 tmp]# mv daizhihong/ daizhihong2/
[root@daizhihong01 tmp]# ls
daizhihong2(源目录从命名为给定的目标文件名)
daizhihong3
daizhong
ks-script-9pf2WE
yum.log
-----------------------------------------------------------------------------------------
移动时目标目录存在的时候,就会把原目录放到目标目录下面
[root@daizhihong01 tmp]# ls
daizhihong2
daizhihong3
daizhong
ks-script-9pf2WE
yum.log
[root@daizhihong01 tmp]# mv daizhihong2/ daizhong/
[root@daizhihong01 tmp]# ls
daizhihong3
daizhong
ks-script-9pf2WE
yum.log
[root@daizhihong01 tmp]# ls daizhong/(目标目录)
01 daizhihong daizhihong2(原目录)
[root@daizhihong01 tmp]#
---------------------------------------------------------------------------------------------
移动目录时时如果该目录存在则会询问是否覆盖
[root@daizhihong01 tmp]# rm daizhhong/
rm: 无法删除"daizhhong/": 没有那个文件或目录
[root@daizhihong01 tmp]# mkdir daizhihong
[root@daizhihong01 tmp]# touch daizhihong/01.txt
[root@daizhihong01 tmp]# tree daizhihong/
daizhihong/
└── 01.txt
0 directories, 1 file
[root@daizhihong01 tmp]# tree daizhihong3
daizhihong3
└── daizhihong
└── 11.txt
1 directory, 1 file
[root@daizhihong01 tmp]# mv daizhihong/ daizhihong3/
mv:是否覆盖"daizhihong3/daizhihong"? y
mv: 无法将"daizhihong/" 移动至"daizhihong3/daizhihong": 文件已存在
标签:txt strong span 就会 移动目录 linux /usr 目标 lin
原文地址:http://blog.51cto.com/13577820/2066362