Linux System file Properties-hard connect, soft Connect

Source: Internet
Author: User

1 Hard Link concepts

A hard link is a link through an index node (inode) in a Linux (EXT2,EXT3) file system in which a file saved in a disk partition is assigned a number, which is called the Index node number (inode index) or inode. That is, the number of the file in the system.

In a Linux file system, it is normal and permissible for multiple filenames to point to the same index node (Inode). A file of this kind is called a hard link, one of the functions of a hard link is to allow a file to have multiple valid pathname (multiple portals) so that users can establish hard links to important files to prevent "accidental deletion" of source data (many hardware storage such as the snapshot feature in NetApp storage applies this principle, Adding a snapshot adds one more hard link. Why does a file establish a hard link to prevent accidental deletion?

Because the file system (EXT2) principle is, as long as the file's index node has one and more links. Delete Only one of the hard links, does not affect the index node itself and other links, only if the last link of the file is deleted, at this time if there is new data to be stored on the hard disk or the system through the disk check with fsck, the deleted file data block and the directory of the link will be released, The space is occupied and overwritten by new data. At this point, the data can no longer be retrieved, that is, in the Linux system, delete files (directory is also a file) condition is related to all the hard links are deleted;

Tip: A hard link is equivalent to another entry in a file

2 Viewing the number of hard links

The red display below this figure shows the number of hard links, indicating that there are several hard links;

Note: The catalog cannot create hard links

Create a hard link to see the changes.

Create hard-link files whose inode nodes are the same.

3 Soft Links

Software links equivalent to WinDOS shortcuts

The soft-link file in Linux is a special file. In a soft link, a soft link file is actually a text file that contains the location information content of a soft link pointing to another source file, so you can quickly navigate to the source file entity that the soft link points to by accessing the shortcut.

The soft links are created, and their inode nodes are not the same.

4 Summary: 4.1 Hard Links Summary:

1) View the number of hard links through the Ls–li parameter

2) The same file can have multiple hard links at the same time, but only for the file, hard links cannot be used in the directory.

3) same file with multiple hard-link file inode nodes

4) Delete a hard-link file of a file, will not affect the other hard-linked files, only delete all hard-linked files and source files, the data will be deleted.

5) When all hard-link files and source files are deleted, the new data will occupy the space of this file, or the disk fsck check, the data will be recycled.

6) Hard links are multiple portals of a file.

7) Unlike replication, hard-linked files point to the same source file, so making changes in any hard-link file directly affects each hard-link file. Corresponds to constant synchronization .

8) directory does not support creating hard links

4.2 Soft Links Summary:

1) Soft links equivalent to WinDOS shortcuts

2) different inode values for soft links and source files

3) You can create a soft link to a file or directory on a different partition

4) View the source file corresponding to the soft link file via the readlink command

5) Deleting a soft link source file will directly affect the soft link

6) Soft links and source files are different types of files and are also different files.

7 Although the directory cannot create a hard link, the LS when viewing a property, you can also see that the line showing the number of hard links is not 1 , but more than 1 the number; The reason for this is that each time a directory is created, it automatically creates a hard link for itself (to see hidden files), and every subdirectory created in the directory causes the number of hard links to be added by 1 (the created file does not increase).

This only works if the subdirectory is created under the directory, and if the subdirectory is created under subdirectories, it is invalid (the principle is that the sub-directory can be found by Ls–al. A hard link to the previous directory)

5 Linux System file deletion and restore principle:

1. A document consists of two parts, I_link and I_count, respectively.

2. I_link is the number of hard links; I_count is the number of calls to the file process

3. When I_link is 0 o'clock (that is, all hard links and source files are deleted) and is not called by another process, the file is deleted.

4. When I_link is 0 o'clock, but is called by another process, I_count is not 0, the file can be restored.

So whether the file is really deleted, see I_link and I_count two counters decide.

5.1 Web server disk full failure case analysis:

Reference: http://oldboy.blog.51cto.com/2561410/612351

5.2 Case: Simulating a Web server disk full failure environment

1) Yum installation httpd

[Email protected] ~]# yum-y install httpd

2) Change the httpd.conf profile access log path

[Email protected] ~]# sed-i [email protected] #CustomLog/app/log/access_log [email protected]/app/log/access_log [EMA Il protected] "/etc/httpd/conf/httpd.conf

3) Create an emulated disk

[[email protected] ~]# dd If=/dev/zero OF=/DEV/SDC bs=8k count=10

Recorded 10+0 read-in

Recorded the writing of 10+0.

81920 bytes (KB) Replicated, 0.000898885 sec, 91.1 mb/s

[Email protected] ~]# LL/DEV/SDC

-rw-r--r--1 root root 81920 September 16:02/DEV/SDC

[Email protected] ~]# MKFS.EXT3/DEV/SDC

4) Mount View

[Email protected] ~]# mount/dev/sdc/app/log/

Mount:/DEV/SDC is not a block device (maybe try '-O loop '?)

[Email protected] ~]# Mount-o loop/dev/sdc/app/log/

[Email protected] ~]# df-h

/DEV/SDA1 485M 76M 384M 17%/boot

/DEV/SDC 73K 14K 55K 21%/app/log

5) Start HTTP and view

[[email protected] ~]#/etc/init.d/httpd start

[Email protected] ~]# ll/app/log/

-rw-r--r--1 root root 4524 September 16:11 access_log

drwx------2 root root 12288 September 16:04 lost+found

6) Open the page multiple times, fill the disk, and delete the log file to see if the disk is still full.

Found disk not reduced after deletion

7) by Lsof | grep del View File usage

8) Restart the HTTPD service to release the log being written and view

Production scenario: the best solution

1) Delete the file and restart the service.

2) Empty the contents of the file without restarting the service.

3) Do not delete the day of the process occupied by the file, delete the previous.

6 file Time type 6.1 gnu/linux files have 3 types of timestamps:

Three times the file can be viewed via the stat command

6.2 Viewing file timestamps by each parameter of the LS command

1) The last modified time is displayed by the default LS (LS-LT)

2) The state change time is shown through LS–LC

3) The last access time is shown through Ls–lu

6.3 Several cases of changing timestamps

1) Touch an existing file will change the file's three timestamp

2) When viewing a file, it will change the access time of the file (as well as some other modifications to the file properties, the timestamp will change accordingly)

6.4 Show file time long format with LS two method

1) –time-style=long-iso command via LS

[Email protected] ~]# ls-l--time-style=long-iso wang.txt

-rw-r--r--1 root root 2014-09-25 10:43 wang.txt

2) via LS –time-style=full-iso command

[Email protected] ~]# ls-l--time-style=full-iso wang.txt

-rw-r--r--1 root root 2014-09-25 10:43:13. 081973883 +0800 Wang.txt

Http://www.cnblogs.com/wangbaigui/p/4409955.html

Linux System file Properties-hard connect, soft Connect

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.