Linux 命令 mv
mv 命令
--no-target-directory 参数确保对目录进行重命名而不是移动
https://www.gnu.org/software/coreutils/manual/html_node/Target-directory.html#Target-directory
‘--no-target-directory’
Do not treat the last operand specially when it is a directory or a symbolic link to a directory. This can help avoid race conditions in programs that operate in a shared area. For example, when the command ‘mv /tmp/source /tmp/dest’ succeeds, there is no guarantee that /tmp/source was renamed to /tmp/dest: it could have been renamed to /tmp/dest/source instead, if some other process created /tmp/dest as a directory. However, if mv -T /tmp/source /tmp/dest succeeds, there is no question that /tmp/source was renamed to /tmp/dest.
In the opposite situation, where you want the last operand to be treated as a directory and want a diagnostic otherwise, you can use the --target-directory (-t) option.
# 将 source 目录重命名为 dest ,如果 dest 存在,则将 source 放到 dest 目录下。
[root@localhost ~]# mv source dest
# 将 source 目录重命名为 dest ,如果 dest 存在,则提示是否覆盖。
[root@localhost ~]# mv -T source dest
mv: overwrite ‘dest’? y
mv: cannot move ‘source’ to ‘dest’: File exists
场景 通配符匹配文件或目录
通配符:
* 匹配任意个字符
? 匹配单个任意字符
格式
<dir>/* 移动指定目录下所有源到目标目录
<dir>/*xxx 后缀
<dir>/xxx* 前缀
<dir>/*xxx* 包含
<dir>/?.xxx 名称为单个字符的 xxx 文件
实战
# 全匹配
[root@localhost ~]# mv test/* dev
# 后缀匹配
[root@localhost ~]# mv dev/*.txt test/
# 前缀匹配
[root@localhost ~]# mv jie* dev
# 包含匹配
[root@localhost ~]# mv *ea* dev
# 将匹配如 a.txt 不会匹配 ab.txt 。? 不是可选,而是表示任意单个字符
[root@localhost ~]# mv test/a?.txt dev
[root@localhost ~]# mv *a??.txt dev
# 可以指定带通配符的多个源
[root@localhost ~]# mv dev/* test/* ./
bugs
# 提示没有找到文件或目录,当指定多个源时,其他存在的源会正常执行。注意这仅仅只是提示。
mv: cannot stat ‘dev/*’: No such file or directory # 这只是提示
[root@localhost ~]# mv dev/* test/* ./
mv: cannot stat ‘dev/*’: No such file or directory 提示 dev/* 没有匹配到任何文件或目录
mv: cannot stat ‘test/*’: No such file or directory 提示 test/* 没有匹配到任何文件或目录
[root@localhost ~]# ll dev
total 0
[root@localhost ~]# ll test
total 0
场景 移动多个文件或目录到指定目录
格式
mv [OPTION]... SOURCE... DIRECTORY
实战
最后一个参数为目标,当移动多个文件或目录到指定目录时,最后一个参数必须是已存在的目录。
[root@localhost ~]# mv a/c.txt a.txt b.txt bak
场景 重命名文件或目录
格式
mv [OPTION]... [-T] SOURCE DEST
实战
# 重命名文件
[root@localhost test]# ll
total 0
-rw-r--r--. 1 root root 0 Aug 2 09:53 a.txt
[root@localhost test]# mv a.txt b.txt
[root@localhost test]# ll
total 0
-rw-r--r--. 1 root root 0 Aug 2 09:53 b.txt
# 重命名目录
[root@localhost test]# ll
total 0
drwxr-xr-x. 2 root root 6 Aug 2 09:55 dev
[root@localhost test]# mv dev pro
[root@localhost test]# ll
total 0
drwxr-xr-x. 2 root root 6 Aug 2 09:55 pro
Linux 命令 mv的更多相关文章
- Linux 命令 - mv: 移动或重命名文件
命令格式 cp [OPTION]... [-T] SOURCE DEST cp [OPTION]... SOURCE... DIRECTORY cp [OPTION]... -t DIRECTORY ...
- linux命令 mv
后缀--backup=<备份模式>:若需覆盖文件,则覆盖前先行备份: -b:当文件存在时,覆盖前,为其创建一个备份: -f:若目标文件或目录与现有的文件或目录重复,则直接覆盖现有的文件或目 ...
- 【LINUX命令】之MV
linux下重命名文件或文件夹的命令mv既可以重命名,又可以移动文件或文件夹. 例子:将目录A重命名为B mv A B 例子:将/a目录移动到/b下,并重命名为c mv /a /b/c 注意: mv命 ...
- linux命令(7):mv命令
mv命令 mv命令是move的缩写,可以用来移动文件或者将文件改名(move (rename) files),是Linux系统下常用的命令,经常用来备份文件或者目录. 1.命令格式: mv [选项] ...
- Linux命令行下cp,rm,mv命令的使用
以下的内容来源于<鸟哥的私房菜> Linux命令行下的复制.删除与移动:cp,rm,mv cp(copy)复制 cp这个命令的用途很多,除了单纯的复制之外,还可以创建链接文件 ...
- linux 命令随笔 ls cd pwd mkdir rm mv cp cat nl
Linux 命令练习 ls命令 ls就是list的简写,目的是打印当前目录下的清单 格式 ls[选项][目录名] 常用参数 -a –all 列出目录下的所有文件,包括以 . 开头的隐含文件 -l 除了 ...
- 【Linux基础】常用Linux命令: cd, cp, ls, mkdir, mv, rm, su, uname
常用Linux命令:cd, cp, ls, mkdir, mv, rm, su, uname cd命令:切换当前工作目录至 dirName(目录参数) 其中 dirName 可为绝对路径或相对路径.若 ...
- Linux 命令之mv
mv命令也是Linux中很常见命令 作用:可以用来移动文件或者将文件改名 命令格式: mv [选项] 源文件或目录 目标文件或目录 命令参数: -b :若需覆盖文件,则覆盖前先行备份. -f :for ...
- Linux命令-目录处理命令:mv
注意:在linux下面,剪切文件和改名是同一个命令mv,而不是两个独立的命令. mv /tmp/beijing/chaoyangqu /root 移动chaoyangqu目录到root目录下面 mv ...
随机推荐
- 实战django(二)--登录实现记住我
上节初步实现了登录和注册模块,这节我们进一步实现“记住我”功能. 大体功能分为以下模块: 1.在登录时如果勾选记住我,那么就将用户username存进cookie中,跳转到index页面: 2.此时, ...
- HTML连载26-谷歌开发者工具其它作用&CSS继承性
一.谷歌开发者工具其他特性(谷歌浏览器快捷键F12) (1)元素选择, 在里面我们可以看到某些行的具体代码 (2)查看源代码 (3)该元素的样式显示,我们可以看到我们选中的元素的具体样式属性,可以在里 ...
- SpringBoot第八篇:整合MyBatis-Generator
作者:追梦1819 原文:https://www.cnblogs.com/yanfei1819/p/10894278.html 版权声明:本文为博主原创文章,转载请附上博文链接! 注意:本章有大量代码 ...
- Scratch 3.6环境搭建(万江波实战记录)
1.Scratch官网在线环境 官方网址:scratch.mit.edu 进入后,点击“Create”建立 2. Scratch官网在线环境_简体中文(点击这个地球) 3-选择:创意 4-进入”创意“ ...
- Java8 新特性 Optional 类
Optional 类的简介 Optional类的是来自谷歌Guava的启发,然后就加入到Java8新特性中去了.Optional类主要就是为子决解价值亿万的错误,空指针异常. Optional ...
- 云原生生态周报 Vol. 16 | CNCF 归档 rkt,容器运行时“上古”之战老兵凋零
作者列表:木苏,临石,得为,等等 业界要闻 安全漏洞 CVE-2019-9512 CVE-2019-9514 http2 的 DOS 漏洞,一旦攻击成功会耗尽服务器的 cpu/mem,从而导致服务不可 ...
- Codeforces Global Round 3
Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...
- ThinkPad L460 拆机加ngff ssd与内存
ThinkPad L460 拆机加ngff ssd与内存 参考链接:http://blog.sina.com.cn/s/blog_82793ae60102wgtp.html 原有配置:i5 6200U ...
- 「福利」Java Swing 编写的可视化算法工程,包含树、图和排序
之前在整理<学习排序算法,结合这个方法太容易理解了>这篇文章时,发现了一个用 Java Swing 编写的可视化算法工程,真心不错!包含了常用数据结构和算法的动态演示,先来张图感受下: 可 ...
- 剑指Offer_栈的压入序列是否有对应的弹出序列
题目: 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否可能为该栈的弹出顺序. 如:假设压入栈的所有数字均不相等.例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是 ...