backup file

Today, when programming, I accidentally delete the source file and delete the source file. If the file under Linux is deleted, it will never be found again. Therefore, when writing large files, you should have a good habit of backing up files.

 

Before reading this blog again, it is recommended to take a look at the blog: Linux file links in the file system of Linux system structure (3) .

 

Operation: Use the ln command to create a hard link to the file to realize real-time backup of the file.

 

1. Create a backup folder: mkdirbackup

2. Create a file under ./c/0505/: vi test.c, and enter 123456789 in the file

3. Create a hard link file of test.c in the backup folder: ln ../c/0505/ test.c test_back.c , the content of test.c test_back.c is the same as the content of test.c .

4. Modify the content of test.c under ./c/0505/ to abcdefg

5. At this time, the content of test_back.c under ./backup/ is also automatically changed to abcdefg

6. Delete test.c under ./c/0505/

7. At this time, test_back.c under ./backup/ still exists, and the content is still abcdefg

 

That's the pros and cons of hard links.

 

 


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325410606&siteId=291194637