7.每日一个Linux命令----mv

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

用法:mv [-fiu] source destinationit

           mv [option] source1 source2 source3 ...  directoryio

经常使用参数:test

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

-f:强制移动

-i:互动模式di

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

示例:备份

1.文件重命名co

[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~
相关文章
相关标签/搜索