1.11- 重命名文件 mv命令详解

在Linux中,重命名文件的过程称为移动,mv命令可以将文件和目录移动到另一个位置:
mv取move之意
1、用法一:mv 源文件 目标文件,将源文件重命名为目标文件
1> 重命名普通文件
重命名文件仅仅是更改文件名,保留原来的索引节点和最后修改文件时间

[root@hadoop tmp]# mv test_file1 new_test_file1
[root@hadoop tmp]# ls -li *test_file*
16811483 -rw-r--r--. 1 root root  7 8月  10 18:48 new_test_file1
16811794 -rw-r--r--. 2 root root  7 8月  11 12:56 test_file2
16811794 -rw-r--r--. 2 root root  7 8月  11 12:56 test_file22
16811795 -rw-r--r--. 1 root root  7 8月  11 12:56 test_file3
16811797 lrwxrwxrwx. 1 root root 10 8月  11 12:57 test_file33 -> test_file3

2> 重命名硬链接文件的源文件
源文件及硬链接都能用,硬链接文件不做改变,仅更改源文件的文件名

[root@hadoop tmp]# mv test_file2 new_test_file2
[root@hadoop tmp]# ls -li *test_file*
16811483 -rw-r--r--. 1 root root  7 8月  10 18:48 new_test_file1
16811794 -rw-r--r--. 2 root root  7 8月  11 12:56 new_test_file2
16811794 -rw-r--r--. 2 root root  7 8月  11 12:56 test_file22
16811795 -rw-r--r--. 1 root root  7 8月  11 12:56 test_file3
16811797 lrwxrwxrwx. 1 root root 10 8月  11 12:57 test_file33 -> test_file3

3> 重命名硬链接文件
源文件及硬链接都能用,硬链接文件不做改变,仅更改硬链接文件的文件名

[root@hadoop tmp]# mv test_file22 new_test_file22
[root@hadoop tmp]# ls -li *test_file*
16811483 -rw-r--r--. 1 root root  7 8月  10 18:48 new_test_file1
16811794 -rw-r--r--. 2 root root  7 8月  11 12:56 new_test_file22
16811794 -rw-r--r--. 2 root root  7 8月  11 12:56 test_file2
16811795 -rw-r--r--. 1 root root  7 8月  11 12:56 test_file3
16811797 lrwxrwxrwx. 1 root root 10 8月  11 12:57 test_file33 -> test_file3

4> 重命名软连接文件
仅更改软连接文件的文件名,源文件和软连接都能用

[root@hadoop tmp]# mv test_file33 new_test_file33
[root@hadoop tmp]# ls -li *test_file*
16811483 -rw-r--r--. 1 root root  7 8月  10 18:48 new_test_file1
16811794 -rw-r--r--. 2 root root  7 8月  11 12:56 new_test_file22
16811797 lrwxrwxrwx. 1 root root 10 8月  11 12:57 new_test_file33 -> test_file3
16811794 -rw-r--r--. 2 root root  7 8月  11 12:56 test_file2
16811795 -rw-r--r--. 1 root root  7 8月  11 12:56 test_file3

5> 修改软连接文件的源文件
重命名软连接文件的源文件,软链接文件不可用,进一步证明了软链接文件存储的是源文件的位置和信息,现在源文件更改,找不到源文件,则软链接文件报出 没有那个文件或目录错误:

[root@hadoop tmp]# mv test_file3 new_test_file3
[root@hadoop tmp]# ls -li *test_file*
16811483 -rw-r--r--. 1 root root  7 8月  10 18:48 new_test_file1
16811794 -rw-r--r--. 2 root root  7 8月  11 12:56 new_test_file22
16811795 -rw-r--r--. 1 root root  7 8月  11 12:56 new_test_file3
16811794 -rw-r--r--. 2 root root  7 8月  11 12:56 test_file2
16811797 lrwxrwxrwx. 1 root root 10 8月  11 12:57 test_file33 -> test_file3
16811796 lrwxrwxrwx. 1 root root 10 8月  10 23:53 test_file5 -> test_file1
[root@hadoop tmp]# cat test_file33
cat: test_file33: 没有那个文件或目录

2、用法二:mv 源目录 目标目录,将源目录重命名为目标目录
mv更改目录名,仅更改目录的名称,目录的属性和目录的内容未做修改

[root@hadoop tmp]# mv dafu1 new_dafu1
[root@hadoop tmp]# ls -li  | grep dafu
 2099877 drwxr-xr-x. 2 root root  6 8月   7 23:47 dafu2
 2099879 drwxr-xr-x. 3 root root 19 8月  10 19:08 dafu3
33596387 drwxr-xr-x. 2 root root 45 8月  10 19:10 dafu4
50866018 drwxr-xr-x. 2 root root 85 8月  10 18:59 new_dafu1
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值