1 命令功能(简要说明):

命令可以用来移动文件或者更改文件名字,经常用来备份文件或者目录,mv --> move

2 命令语法:

mv【选项】 【源文件或目录名】 【目标文件或目录名】    #注:【】中的内容为非必选项

3 命令选项(只做常用命令参数讲述):

  使用帮助命令:man mkdir 或 mkdir -help

--backup[=CONTROL] 为每个已存在的目标文件创建备份
-b 类似--backup 但不接受参数
-f, --force 覆盖前不询问,如果目标文件已经存在,不会询问而直接覆盖。
-i, --interactive 当目标文件已经存在当前目录,覆盖前会进行询问。
-n, --no-clobber 不覆盖已存在文件   如果您指定了-i、-f、-n 中的多个,仅最后一个生效。
--strip-trailing-slashes 去掉每个源文件参数尾部的斜线
-S, --suffix=SUFFIX 替换常用的备份文件后缀
-t, --target-directory=DIRECTORY 将所有参数指定的源文件或目录移动至指定目录,既该功能适用于移动多个源文件到一个目录的情况,注意此时目标目录在前,各个源文件在后
-T, --no-target-directory 将目标文件视作普通文件处理
-u, --update 只在源文件文件比目标文件新,或目标文件不存在时才进行移动

4 使用范例:

  (1)mv 文件改名

[root@localhost command_test]# ls
av.log
[root@localhost command_test]# mv av.log av.mp4
[root@localhost command_test]# ls
av.mp4
[root@localhost command_test]# 

  (2)mv 【文件名或目录】 【文件名或目录】 ------移动文件

#首先创建目录dir1
[root@localhost command_test]# mkdir dir
[root@localhost command_test]# ll
总用量 4
-rw-r--r--. 1 root root    0 7月  26 23:27 av.mp4
drwxr-xr-x. 2 root root 4096 7月  26 23:35 dir1
[root@localhost command_test]# #创建测试文件canglaoshi.txt,并移动文件到dir1目录下
[root@localhost command_test]# touch canglaoshi.txt
[root@localhost command_test]# ls
av.mp4  canglaoshi.txt  dir1
[root@localhost command_test]# mv canglaoshi.txt  dir1
[root@localhost command_test]# ls
av.mp4  dir1
[root@localhost command_test]# #创建canglaoshi.txt,因为canglaoshi.txt文件在上一步骤已经存在dir1目录下,继续将文件移动到dir1时相当于覆盖操作,覆盖前会进行询问
[root@localhost command_test]# touch canglaoshi.txt
[root@localhost command_test]# ls
av.mp4  canglaoshi.txt  dir1
[root@localhost command_test]# mv canglaoshi.txt  dir1
mv:是否覆盖"dir1/canglaoshi.txt"? y
[root@localhost command_test]# ls
av.mp4  dir1
[root@localhost command_test]# #再次创建canglaoshi.txt,这次试用-f 参数强制移动文件,无视目标目录是否已经存在目录,覆盖不会询问
[root@localhost command_test]# touch canglaoshi.txt
[root@localhost command_test]# ls
av.mp4  canglaoshi.txt  dir1
[root@localhost command_test]# mv -f canglaoshi.txt  dir1
[root@localhost command_test]# ls
av.mp4  dir1
[root@localhost command_test]#

 

  (3)mv 【文件1】 【文件2】 【文件3】 【目标目录】  ------- 多个文件移动到同一目录,注意-t参数的区别影响

#首先我们先创建文件和目录dir1
[root@localhost command_test]# touche canglaoshi.txt xioacang.txt boduo.txt
-bash: touche: command not found
[root@localhost command_test]# touch canglaoshi.txt xioacang.txt boduo.txt
[root@localhost command_test]# ls
boduo.txt  canglaoshi.txt  xioacang.txt
[root@localhost command_test]# mkdir dir1
[root@localhost command_test]# ls
boduo.txt  canglaoshi.txt  dir1  xioacang.txt
#注意mv命令在移动多个文件时,最后一个参数为已存在的目标目录,否则则会出错
[root@localhost command_test]# mv boduo.txt canglaoshi.txt xioacang.txt dir1
[root@localhost command_test]# ls
dir1
[root@localhost command_test]# cd dir1
[root@localhost dir1]# ls
boduo.txt  canglaoshi.txt  xioacang.txt
[root@localhost dir1]# #下列示例展示同为多个文件移动,但有一点不用的是,mv命令使用-t 参数,则需把目标目录放在第一为,后接需要移动的多个文件
[root@localhost command_test]# pwd
/home/command_test
[root@localhost command_test]# ls
dir1
[root@localhost command_test]# cd dir1
[root@localhost dir1]# ls
boduo.txt  canglaoshi.txt  xioacang.txt
[root@localhost dir1]# mv -t /home/command_test boduo.txt canglaoshi.txt xioacang.txt
[root@localhost dir1]# ls
[root@localhost dir1]#
[root@localhost dir1]# cd ..
[root@localhost command_test]# ls
boduo.txt  canglaoshi.txt  dir1  xioacang.txt
[root@localhost command_test]# 

  (4)mv  目录的移动

#创建两个二级目录,并把目录dir1以及其子目录移动到dir3,整个目录移动很方便
[root@localhost command_test]# mkdir -p dir1/dir2
[root@localhost command_test]# mkdir -p dir3/dir4
[root@localhost command_test]# ls
dir1  dir3
[root@localhost command_test]# mv dir1 dir3
[root@localhost command_test]# ls
dir3
[root@localhost command_test]# cd dir3
[root@localhost dir3]# ls
dir1  dir4
[root@localhost dir3]# cd dir1
[root@localhost dir1]# ls
dir2
[root@localhost dir1]# 

  (5)mv 使用相对路径移动目录到上一级目录

#使用相对路径移动当前目录下所有东西到上一级目录
[root@localhost command_test]# mkdir dir1
[root@localhost command_test]# ls
dir1
[root@localhost command_test]# cd dir1
[root@localhost dir1]# touch canglaoshi.txt xiaocang.txt
[root@localhost dir1]# ls
canglaoshi.txt  xiaocang.txt
[root@localhost dir1]# mv * ../
[root@localhost dir1]# ls
[root@localhost dir1]# cd ..
[root@localhost command_test]# ls
canglaoshi.txt  dir1  xiaocang.txt
[root@localhost command_test]# 

 

  

转载于:https://www.cnblogs.com/king-of-purple/p/9371481.html

linux一步一脚印---mv命令相关推荐

  1. linux 擦脚印工具,linux一步一脚印---rm命令

    1 命令功能(简要说明): 该命令用来删除Linux系统中的文件或目录.通常情况下rm不会删除目录,你必须通过指定参数-r或-R来删除目录.另外rm通常可以将该文件或目录恢复(注意,rm删除文件其实只 ...

  2. linux mv 递归拷贝,奇技淫巧 - 给Linux中的cp和mv命令中添加进度条的高级拷贝

    GNU cp和GNU mv命令用于在GNU/Linux操作系统中复制和移动文件和目录.这两个命令缺少的一个特性是它们不显示任何进度条.如果复制一个大文件或目录,您就不知道完成复制过程需要多长时间,也不 ...

  3. 给Linux中的cp和mv命令中添加进度条的高级拷贝

    GNU cp和GNU mv命令用于在GNU/Linux操作系统中复制和移动文件和目录.这两个命令缺少的一个特性是它们不显示任何进度条.如果复制一个大文件或目录,您就不知道完成复制过程需要多长时间,也不 ...

  4. linux一步一脚印---more、less、head、tail

    一.more 文件内容或输出查看命令 more 是我们最常用的工具之一,最常用的就是显示输出的内容,然后根据窗口的大小进行分页显示,然后还能提示文件的百分比: [root@localhost ~]# ...

  5. linux一步一脚印---stat

    1.命令功能说明 stat命令用于显示文件系统和文件的源或者说是属性信息: 2.stat命令的使用参数 -f,--file-system 不显示文件本身的信息,显示文件所在文件系统的信息 -Z,--c ...

  6. linux一步一脚印---touch

    1 命令功能(简要说明): touch命令主要存在两个用法(1)将文件的访问时间和修改时间改成当前时间:(2)不存在的文件将会被创建为空文件,除非使用-c或-h选项: 2 命令语法: touch [选 ...

  7. linux剪切到另一个文件夹,linux下文件夹操作常见命令如创建、复制、剪切、重命名、清空和删除命令 实例说明...

    linux下文件夹操作常见命令如创建.复制.剪切.重命名.清空和删除命令 实例说明,在home目录下有wwwroot目录,wwwroot下有sinozzz目录,即/home/wwwroot/sinoz ...

  8. 【Linux】一步一步学Linux——mv命令(30)

    00. 目录 文章目录 00. 目录 01. 命令概述 02. 命令格式 03. 常用选项 04. 参考示例 05. 附录 01. 命令概述 mv命令是"move"单词的缩写,其功 ...

  9. linux重命名文件或文件夹(mv命令 rename命令)

    转自:http://www.cnblogs.com/yes123/p/3919337.html 在linux下重命名文件或目录,可以使用mv命令或rename命令,这里分享下二者的使用方法. mv命令 ...

最新文章

  1. 一个研发团队是如何坚持7年技术分享的?
  2. 初识费用流 模板(spfa+slf优化) 餐巾计划问题
  3. 【数据结构与算法】1.二叉树代码
  4. python内存模型_内存篇3:CPython的内存管理架构-L2-块
  5. 黄国兴计算机应用基础,黄国兴计算机应用基础 - 百度学术
  6. memcache未授权访问漏洞
  7. 笔记五:python字符串
  8. Python音乐播放器-美观-简约-本地
  9. Intellij idea 主题下载网址
  10. JSFinder自动化脚本一键批量处理URL(附自动执行脚本带whatweb筛选)
  11. Qgis 3.18 的安装步骤
  12. 如何将CAD图纸转换成彩色jpg
  13. java 添加jbutton_在java中怎样在JLabel上添加JButton呢
  14. Jmeter5.0脚本录制
  15. 2016首次CCCC总结
  16. idea spring boot 修改html等不重启即时生效
  17. There was a problem confirming the ssl certificate: HTTPSConnectionPool(host=‘pypi.org‘, port=443)
  18. 银行用计算机实现了,银行考试计算机专项练习(一)!!!.pdf
  19. Python pygame 坦克大战
  20. 斯尔福化学实验室设计规划环境及建设要求

热门文章

  1. 搭建 OpenStack 实验环境 - 每天5分钟玩转 OpenStack(16)
  2. Intellij IDEA 14 安装之后
  3. TCP转输控制协议(转)
  4. 面试题 01.04. 回文排列
  5. virtual memory exhausted: Cannot allocate memory Linux虚拟内存不足,扩展虚拟内存的解决办法
  6. 苹果一体机系统恢复_趁双十一大促销,赶紧升级苹果一体机升级SSD固态和液态内存吧...
  7. kafka partition分配_logstash消费kafka数据,partition分配不均衡
  8. python 协程 多线程_python进阶之多线程(简单介绍协程)
  9. 文本分类训练集 测试集_【AI1000问】训练为什么要分测试集和验证集?
  10. FLOPs FLOPS