Linux 命令 mv

mv 命令

--no-target-directory 参数确保对目录进行重命名而不是移动

https://www.gnu.org/software/coreutils/manual/html_node/Target-directory.html#Target-directory

1--no-target-directory’ 2Do 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. 3 4In 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. 5 6 7 8# 将 source 目录重命名为 dest ,如果 dest 存在,则将 source 放到 dest 目录下。 9[root@localhost ~]# mv source dest 10 11# 将 source 目录重命名为 dest ,如果 dest 存在,则提示是否覆盖。 12[root@localhost ~]# mv -T source dest 13mv: overwrite ‘dest’? y 14mv: cannot move ‘source’ to ‘dest’: File exists

场景 通配符匹配文件或目录

1通配符: 2* 匹配任意个字符 3? 匹配单个任意字符

格式

1<dir>/* 移动指定目录下所有源到目标目录 2<dir>/*xxx 后缀 3<dir>/xxx* 前缀 4<dir>/*xxx* 包含 5<dir>/?.xxx 名称为单个字符的 xxx 文件

实战

1# 全匹配 2[root@localhost ~]# mv test/* dev 3# 后缀匹配 4[root@localhost ~]# mv dev/*.txt test/ 5# 前缀匹配 6[root@localhost ~]# mv jie* dev 7# 包含匹配 8[root@localhost ~]# mv *ea* dev 9 10# 将匹配如 a.txt 不会匹配 ab.txt 。? 不是可选,而是表示任意单个字符 11[root@localhost ~]# mv test/a?.txt dev 12 13[root@localhost ~]# mv *a??.txt dev 14 15# 可以指定带通配符的多个源 16[root@localhost ~]# mv dev/* test/* ./

bugs

1# 提示没有找到文件或目录,当指定多个源时,其他存在的源会正常执行。注意这仅仅只是提示。 2mv: cannot stat ‘dev/*’: No such file or directory # 这只是提示 3 4 5[root@localhost ~]# mv dev/* test/* ./ 6mv: cannot stat ‘dev/*’: No such file or directory 提示 dev/* 没有匹配到任何文件或目录 7mv: cannot stat ‘test/*’: No such file or directory 提示 test/* 没有匹配到任何文件或目录 8[root@localhost ~]# ll dev 9total 0 10[root@localhost ~]# ll test 11total 0

场景 移动多个文件或目录到指定目录

格式

mv [OPTION]... SOURCE... DIRECTORY

实战

1最后一个参数为目标,当移动多个文件或目录到指定目录时,最后一个参数必须是已存在的目录。 2[root@localhost ~]# mv a/c.txt a.txt b.txt bak

场景 重命名文件或目录

格式

mv [OPTION]... [-T] SOURCE DEST

实战

1# 重命名文件 2[root@localhost test]# ll 3total 0 4-rw-r--r--. 1 root root 0 Aug 2 09:53 a.txt 5[root@localhost test]# mv a.txt b.txt 6[root@localhost test]# ll 7total 0 8-rw-r--r--. 1 root root 0 Aug 2 09:53 b.txt 9# 重命名目录 10[root@localhost test]# ll 11total 0 12drwxr-xr-x. 2 root root 6 Aug 2 09:55 dev 13[root@localhost test]# mv dev pro 14[root@localhost test]# ll 15total 0 16drwxr-xr-x. 2 root root 6 Aug 2 09:55 pro
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

swap空间的增减方法

(1)增大swap空间去激活swap交换区:swapoff v /dev/vg00/lvswap扩展交换lv:lvextend L 10G /dev/vg00/lvswap重新生成swap交换区:mkswap /dev/vg00/lvswap激活新生成的交换区:swapon v /dev/vg00/lvswap