Linux system file attributes, linux system attributes
1. Hard link concept
Hard link refers to the link through the index node (Inode), in the Linux (ext2, ext3) file system, the file stored in the disk partition is assigned a number no matter what type it is. This number is referred to as 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 allowed to direct multiple file names to the same index node (Inode. In this case, a file is called a hard link. One of the functions of a hard link is to allow a file to have multiple valid path names (multiple entries), so that you can create a hard link to an important file, to prevent "accidental deletion" of source data (many hardware storages, such as the snapshot function in netapp storage, apply this principle and add a snapshot with a hard link .) Why does a hard link to a file prevent accidental deletion?
Because the principle of the file system (ext2) is that as long as the file index node has one or more links. Deleting only one of the hard links does not affect the index node and other links. Only when the last link of the file is deleted, in this case, if new data is stored on the hard disk or the system checks the disk with fsck, the data blocks and directory links of the deleted files will be released, the space is occupied and overwritten by new data. In this case, the data can no longer be retrieved. That is to say, in the linux system, the condition for deleting a file (the directory is also a file) Is that all the hard links related to it are deleted;
Tip: a hard link is equivalent to another file entry.
2. view the number of hard links
The numbers of hard links are displayed in red, indicating the number of hard links;
Note: hard links cannot be created for directories.
Create a hard link to view the changes.
The Inode nodes of the created hard-link files are the same.
3 soft links
Software links are equivalent to ipvs shortcuts
The soft link file in Linux is a special file. In a soft link, a soft link file is actually a text file, which contains the location information of the soft link pointing to another source file. Therefore, by accessing this "shortcut", you can quickly locate the source object pointed to by the soft link.
The created soft links have different inode nodes.
4. Summary: 4.1 hard link summary:
1) Check 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 takes effect for the file. Hard links cannot be used for directories.
3) Multiple hard-link files with the same file have the same inode node.
4) deleting a hard-link file of a file will not affect other hard-link files. Data will be deleted only when all hard-link files and source files are deleted.
5) when all the hard-link files and source files are deleted and new data is stored, the data will also be recycled when the file space is occupied or the disk fsck checks.
6) hard links are multiple entries of a file.
7) Unlike copying, hard-linked files direct to the same source file. Therefore, any changes to hard-linked files directly affect each hard-linked file. EquivalentTime Synchronization.
8) hard links cannot be created in directories.
4.2 soft link summary:
1) Soft link is equivalent to windos shortcut
2) The inode values of soft links and source files are different.
3) You can create soft links to files or directories in different partitions.
4) PassReadlinkCommandView the actual source file corresponding to the soft link file
5) Deleting soft link source files directly affects soft links
6) soft links and source files areDifferent types of filesIs also a different file.
7) Although the directory cannot create a hard linkWhen viewing the attribute, you can also see that the line displaying the number of hard links is not 1, But greater than 1Number;The reason is that each time a directory is created, it automatically creates a hard link for itself (which allows you to view hidden files) and creates a sub-directory under each directory, add hard link count to 1(No files are added ).
This is valid only when a subdirectory is created under the directory. If a subdirectory is created under the subdirectory, it is invalid (the principle is that there is a ".. "corresponds to the hard link of the previous directory)
5 Linux System File Deletion and restoration principles:
1. A file consists of two parts: I _link and I _count.
2. I _link indicates the number of hard links, and I _count indicates the number of processes that call the file.
3. When I _link is 0 (delete all hard links and source files) and is not called by other processes, the file will be deleted.
4. When I _link is 0 but is called by other processes, the I _count value is not 0, and the file can be restored.
So whether the file is deleted is determined by the two counters I _link and I _count.
5.1 Case Study of full failure of Web server disk:
References: http://oldboy.blog.51cto.com/2561410/612351
5.2 case: simulate a fault environment where the Web server disk is full
1) install httpd in yum
[Root @ baiguin ~] # Yum-y install httpd
2) Change the access log path of the httpd. conf configuration file
[Root @ baiguin ~] # Sed-I "s @ # CustomLog/app/log/access_log combined @"/etc/httpd/conf/httpd. conf
3) create a simulated Disk
[Root @ baiguin ~] # Dd if =/dev/zero of =/dev/sdc bs = 8 K count = 10
Read records of 10 + 0
Records 10 + 0 writes
81920 bytes (82 kB) Copied, 0.000898885 seconds, 91.1 MB/second
[Root @ baiguin ~] # Ll/dev/sdc
-Rw-r -- 1 root 81920 September 24 16:02/dev/sdc
[Root @ baiguin ~] # Mkfs. ext3/dev/sdc
4) view mounting
[Root @ baiguin ~] # Mount/dev/sdc/app/log/
Mount:/dev/sdc is not a block device (maybe try '-o loop '?)
[Root @ baiguin ~] # Mount-o loop/dev/sdc/app/log/
[Root @ baiguin ~] # Df-h
/Dev/sda1 485 M 76 M 384 M 17%/boot
/Dev/sdc 73 K 14 K 55 K 21%/app/log
5) Start http and view
[Root @ baiguin ~] #/Etc/init. d/httpd start
[Root @ baiguin ~] # Ll/app/log/
-Rw-r -- 1 root 4524 September 24 16:11 access_log
Drwx ------ 2 root 12288 September 24 16:04 lost + found
6) Open the webpage multiple times to fill the disk, delete the log file, and check whether the disk is full.
The disk is not reduced after deletion.
7) Use lsof | grep del to check the File Usage
8) restart the httpd service to release the logs being written and view the logs.
Production scenario: the best solution
1) delete the file and restart the service.
2) Clear the content in the file without restarting the service.
3) do not delete files occupied by processes on the current day. Delete previous files.
6. files of the file time type 6.1 GNU/Linux have three types of timestamps:
You can run the stat command to view the time of the file.
6.2 view the file timestamp using the ls Command Parameters
1) The default ls (ls-lt) is used to display the last modification time.
2) The ls-lc displays the status change time.
3) The last access time is displayed through ls-lu.
6.3 changing Timestamp
1) Touch an existing file changes the three timestamps of the file.
2) viewing a file changes the access time of the file (and other modifications to the file attribute will change the timestamp accordingly)
6.4 Use ls to display long file formats
1) Use the ls-Time-style = long-isoCommand
[Root @ baiguin ~] # Ls-l -- time-style = long-iso wang.txt
-Rw-r -- 1 root 46Wang.txt
2) use ls-Time-style = full-isoCommand
[Root @ baiguin ~] # Ls-l -- time-style = full-iso wang.txt
-Rw-r -- 1 root 4610:43:13. 081973883 + 0800 wang.txt