linux命令-mv命令

简介

mv(Move file)将源文件重命名为目标文件,
或将源文件移动至指定目录。。

语法

     mv [选项]... [-T] 源文件 目标文件
     mv [选项]... 源文件... 目录
     mv [选项]... -t 目录 源文件...

选项

  • --backup[=CONTROL] : 为每个已存在的目标文件创建备份
  • -b : 类似–backup 但不接受参数
  • -f, --force : 覆盖前不询问
  • -i, --interactive : 覆盖前询问
  • -n, –nechoo-clobber : 不覆盖已存在文件 如果您指定了-i、-f、-n 中的多个,仅最后一个生效。
  • --strip-trailing-slashes : 去掉每个源文件参数尾部的斜线
  • -S, --suffix=SUFFIX : 替换常用的备份文件后缀
  • -t, --target-directory=DIRECTORY : 将所有参数指定的源文件或目录 移动至 指定目录
  • -T,--no-target-directory : 将目标文件视作普通文件处理
  • -u, --update : 只在源文件文件比目标文件新,或目标文件不存在时才进行移动
  • -v, --verbose : 详细显示进行的步骤

实例

1、更改文件名
[root@VM_0_4_centos mv]# touch a.txt
[root@VM_0_4_centos mv]# ll
total 0
-rw-r--r-- 1 root root 0 Jun 21 22:44 a.txt
[root@VM_0_4_centos mv]# mv a.txt b.txt
[root@VM_0_4_centos mv]# ll
total 0
-rw-r--r-- 1 root root 0 Jun 21 22:44 b.txt
2、显示详细信息
[root@VM_0_4_centos mv]# mv -v b.txt a.txt
‘b.txt’ -> ‘a.txt
3、将单个文件移动至目录
[root@VM_0_4_centos mv]# mkdir dir1
[root@VM_0_4_centos mv]# mv a.txt dir1/
    4、将多个文件移动至目录
#mv b.txt c.txt dir1/
[root@VM_0_4_centos mv]# mv *.txt dir1/
[root@VM_0_4_centos mv]# ll

[root@VM_0_4_centos mv]# mv -vt dir2/ b.txt c.txt
‘b.txt’ -> ‘dir2/b.txt’
‘c.txt’ -> ‘dir2/c.txt’
5、  将文件a.txt改名为b.txt,即使b.txt存在,也是直接覆盖掉。
[root@VM_0_4_centos dir2]# mv -vf  b.txt a.txt
‘b.txt’ -> ‘a.txt
6、重命名dir1为dir2(dir2不存在)
[root@VM_0_4_centos mv]# mv dir1 dir2
[root@VM_0_4_centos mv]# ll
total 4
drwxr-xr-x 2 root root 4096 Jun 21 23:04 dir2
7、将dir1移动到dir2中(dir2存在)。(->会放在dir2的目录下面)
[root@VM_0_4_centos mv]# mv -v dir1 dir2
‘dir1’ -> ‘dir2/dir1’
8、文件被覆盖前做简单备份,前面加参数-b
[root@VM_0_4_centos dir1]# mv -bv a.txt b.txt
mv: overwrite ‘b.txt’? y
‘a.txt’ -> ‘b.txt’ (backup: ‘b.txt~’)
9、只在源文件比目标文件新时才移动
[root@VM_0_4_centos dir1]# mv -uv b.txt c.txt
[root@VM_0_4_centos dir1]# mv -uv c.txt b.txt
mv: overwrite ‘b.txt’? y
‘c.txt’ -> ‘b.txt

参考

http://www.cnblogs.com/xqzt/p/5398913.html

猜你喜欢

转载自blog.csdn.net/ab_xue/article/details/80767638