The impact of renaming files on hard links and soft links under Linux __linux

Source: Internet
Author: User

The command MV for renaming a file or folder under Linux can be renamed and moved to a file or folder.

Example: Rename directory A to B

MV A B

Example: Move the/a directory down to/b, and rename to C

mv/a/b/c

In fact, in the text mode to rename the file or directory is also very simple, we only need to use MV command on it,

For example, if we were to rename a file named ABC to 1234, we could write it this way: MV ABC 1234, but note that

If there is a 1234 file in the current directory, we will overwrite it with this file.

Note that moving a file changes the file name, but keeping the same index node and timestamp, moving a file that has a soft link to it can be problematic, with a hard link.

root@wl-ms-7673:/home/wl/Desktop/shell/test# Touch test1
root@wl-ms-7673:/home/wl/desktop/shell/test# ls
test1
root@wl-ms-7673:/home/wl/Desktop/shell/test# ln test1 test2
root@wl-ms-7673:/home/wl/Desktop/shell/test# ls-il
total dosage 0
3161381-rw-r--r--2 Root 0  March  6 21:09 test1
3161381-rw-r--r--2 root root 0  March  6 21:09 te St2
root@wl-ms-7673:/home/wl/Desktop/shell/test# ln-s test1 test3 root@wl-ms-7673:/home/wl/
desktop/shell/test# ls- Il
total dosage 0
3161381-rw-r--r--2 root root 0  March  6 21:09 test1
3161381-rw-r--r--2 root root 0  March  6 21:09 test2
3161398 lrwxrwxrwx 1 root 5  March  6 21:10 test3
-> test1 root@wl-ms-7673:/ home/wl/Desktop/shell/test# mv test1 test4
root@wl-ms-7673:/home/wl/Desktop/shell/test# ls-il
total dosage 0
3161381- rw-r--r--2 Root 0  March  6 21:09 test2
3161398 lrwxrwxrwx 1 root root 5  March  6 21:10 test3-> Test1
3161381-rw-r--r--2 root 0  March  6 21:09 test4
root@wl-ms-7673:/home/wl/Desktop/shell/test# 



Test2 is a hard link to test1, mobile test1 test3 test2 and test3 still maintain the same index node, and soft link test3 point to the test1 that no longer exists at this time.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.