linux 7中安装mv命令,7.每日一个Linux命令----mv

描述: 移动文件与目录,或更名

用法:mv [-fiu] source destination

mv [option] source1 source2 source3 ...  directory

常用参数:

-b:若需覆盖文件,则覆盖前先行备份。

-f:强制

-i:互动模式

-u:若目标文件存在,且source比较新,才会更新。

示例:

1.文件重命名

[root@share19 ~]# mv 1.log 2.log

[root@share19 ~]# ll

total 4

-rw-r--r--. 1 root root 0 May 23 15:36 2.log

2.目录的移动

说明:

如果目录dir2不存在,将目录dir1改名为dir2;否则,将dir1移动到dir2中。

[root@share19 ~]# ll

total 4

drwxr-xr-x. 2 root root 6 May 23 15:38 test1

[root@share19 ~]# mv test1 test2

[root@share19 ~]# ll

total 4

drwxr-xr-x. 2 root root 6 May 23 15:38 test2

[root@share19 ~]# mkdir test1

[root@share19 ~]# ll

total 4

drwxr-xr-x. 2 root root 6 May 23 15:39 test1

drwxr-xr-x. 2 root root 6 May 23 15:38 test2

[root@share19 ~]# mv test1 test2

[root@share19 ~]# ll

total 4

drwxr-xr-x. 3 root root 18 May 23 15:39 test2

[root@share19 ~]# cd test2

[root@share19 test2]# ll

total 0

drwxr-xr-x. 2 root root 6 May 23 15:39 test1

3.移动当前文件夹下的所有文件到上一级目录

[root@share19 test2]# mv * ../

4.文件被覆盖前做简单备份,前面加参数-b

[root@share19 ~]# ll

total 12

-rw-r--r--. 1 root root 25 May 23 15:49 1.log

-rw-r--r--. 1 root root 53 May 23 15:49 2.log

[root@share19 ~]# mv -b 1.log 2.log

mv: overwrite ‘2.log’? y

[root@share19 ~]# ll

total 12

-rw-r--r--. 1 root root 25 May 23 15:49 2.log

-rw-r--r--. 1 root root 53 May 23 15:49 2.log~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值