Linux file or directory properties

Source: Internet
Author: User
Tags parent directory readable disk usage file permissions

1. File or Directory Properties
The properties of a Linux file or directory include: The file or directory's node, kind, permission mode, number of links, the user and user group to which it belongs, the time recently accessed or modified, and so on. The details are as follows:
Command: Ls-lih
Output: [[email protected] test]# Ls-lih
Total 16K
2095113 drwxr-xr-x 6 root root 4.0K 10-27 01:58 SCF
2095109 drwxrwxr-x 2 root root 4.0K 11-13 06:08 test3
2095131 drwxrwxr-x 2 root root 4.0K 11-13 05:50 test4
2095112-rw-r--r--1 root root 2.0K 11-13 06:03 log2012.log
2095120 lrwxrwxrwx 1 root root one 11-22 06:58 Linklog.log-Log2012.log
Description
First column: Inode index node number, the system reads the file first through the filename to find the inode, and then to read the contents of the file.
Second column: File types and permissions;
File type: D for directory,-indicates file
File permissions: File permissions are rw-r--r--, indicating that the file belongs to the main readable, writable, not executable, the user group belonging to the file is not writable, readable, not executable, other users are not writable, readable, not executable;
The third column: The number of hard links; number of hard links: log2012.log This file does not have a hard link; because the value is 1, it's him.
The fourth column: The file belongs to the owner: which is the file belongs to which user, it is attributed to root, that is, the first root;
Fifth column: File group: That is, for this file, it belongs to which user group, here is the root user group;
Sixth column: The size of the file or directory;
Columns seventh and eighth: last access or modification time;
Nineth column: File name or directory name

2. Inode: Index node
Inode index node. Each storage device or storage device partition (storage device is hard disk, floppy disk, USB stick, etc.) is formatted as a file system, there are two parts, one part is the inode (many), the other part is block (many), block is used to store data. The inode is the information that is used to store this data, including file size, owner, attribution user group, read and write permissions, and pointers to file entities, but Inode does not include file names, and filenames are strictly not attributes.

The Inode indexes the information for each file, so there is a value for the inode. According to the instructions, the operating system can find the corresponding file by the Inode value.
Access the file through the filename--->inode--->block.

Multiple files occupy the same inode as a linked file.
The inode corresponds to a partition space on the disk, each inode is of a size, the CentOS 5 series default inode size 128 bytes, the CentOS 6 series default Inode size 256 bytes,
3. Block: Data block
Disk read data is read by block;
A file may occupy more than one block, but each block is read, consumes one disk I/O, in order to improve disk I/O performance, you can set the block to a larger size, so that one-time reading of the data as much as possible.
A block can only hold the contents of one file, even if there is no other file content can be loaded, the rest is wasted.
Block is not bigger the better, too large to store small files (generally small files less than 1K, large files generally greater than 16K) easy to waste disk space, too small to improve disk I/O performance.

Block general size is 1k,2k,4k, boot partition is 1 k, normal partition is 4K (CentOS 6 series)
Disk space depends on the inode and block two items, and any one is full and the disk is full.
EXT3/EXT4 file system, a file is created to occupy at least one inode and one block, and the inode for different files is different.
4.
View File system Inode Total and Remaining amount with df-i
View disk usage with Df-h
View the size and number of inode and block with dumpe2fs [file]
File Deletion recovery Ext3grep
5, enterprise environment operating files, should be backed up and operated, to be able to restore, can not be restored, should be tested in the test environment before operation.
The general production environment of the enterprise block is set to 4K (CentOS 5 and 6 series), the CentOS 7 series exception.
The inode is sufficient in the enterprise environment and the block consumes fast. Too many small files in the enterprise scenario can cause the inode to be insufficient.
6, file type, find-type view file type, Linux only the following 7 file types, no other ....
In Linux, everything is a file. Including ordinary files, directories, character device files, block device files, symbolic link files, pipeline files and so on.
1. Normal file (-): View file types through file [files]
2. Catalogue (d)
3. Character device file (c)
4. Block device file (b)
5. Socket file (s) [after we turn on the MySQL service, the Mysql.sock file generated under/var/lib/mysql/, the file disappears after the MySQL service is turned off]
6. Pipeline (p): Mainly used to solve multiple programs simultaneously accessing the same file generated errors.
7. Symbolic link file (L): shortcut to File
Normal file (-): View file types through file [files]
Plain text files (ASCII), content can be read directly, such as configuration files, can be read directly by Cat.
Binary (binary), the command program in Linux belongs to this file,
Data format files, such as data records for Linux users logged in/var/log/wtmp, are data format files that can only be read with the last command.
Catalog files: Distinguishes files and directories by Ls-f, followed by directories. Dengtest.txt java/test tomcat/
Character device file: A character device file that represents a serial port of an interface device, such as a modem. denoted by "C". Crw-rw-rw-1 Root TTY 5, 0 APR 6 19:35/dev/tty
Block device files: an interface device that stores data for system access, such as a hard disk drive. denoted by "B". Brw-rw-rw-1 Root TTY 5, 0 APR 6 19:35/DEV/SDA
Typically use Mknod to create a character or block device file and delete it with RM.
Set of interface files: typically used for network connections
7. File extension:
. tar,.zip represents a compressed file,
The. SH represents the Shell file,
The. PY represents a Python language file,
. PL represents a Perl language file,
. html. php. jsp. Do represents a Web page file
. conf represents a configuration file
. RPM indicates RPM installation package file
8. File permissions
9. File link

9.1 In Linux, link files are broken into hard links and soft links (symbolic links symbolic link or soft link),
9.2 When no parameters are executed, the Execute ln source file Link file creates a hard link by default, executes ln-s to create a soft link, and the soft link file type is L.
9.3 Hard links through the inode link file.
9.4 In Linux, when multiple file names point to the same index node, such files are mutually hard-linked files.
9.5 Hard links are equivalent to another file entry, and a file with more than one hard link prevents the file from being mistakenly deleted. Delete only the hard link file and the source file, the file is not deleted, only delete all the hard link files and source files, the file entity will be deleted, the occupied disk space is reclaimed by the system.
9.6 for a static file (process not called), the number of hard links is 0 o'clock, indicating that the file was deleted.
9.7 Soft link is equivalent to a shortcut, the soft link file is essentially a text file, which contains the source file storage path. Delete source files, soft links still exist, but unable to access the contents of the source file, display red on white flashing failure status.
9.8 Soft links and source files are different types of files, also different files, and the inode is not the same.
9.9 Delete the hard link file on the source files and soft link files have no effect, delete the source file, no effect on the hard link file, the soft link will be displayed invalid.
9.10 The snapshot function of many hardware devices is to take advantage of the principle of hard links
10. Directory Links
10.1 You cannot create a hard link for a catalog, but you can create a soft link.
10.2 A hard link to a directory cannot span the file system.
10.3 Each directory has a hard link ".", and a hard link corresponding to the parent directory "...".
10.4 Create a subdirectory in the parent directory, the number of links to the parent directory plus 1 (subdirectories will have: Point to the parent directory), create a file in the parent directory, and the number of links in the parent directory is unchanged.
11. File Deletion principle

Linux is deleted through the number of link control files, only if there is no link to the file, the file will be deleted, generally each file has two link counters:
I_count: Reference counter, the file is referenced by a process, the number of i_count increases, can be considered as the current number of users of the file;
I_nlink: Number of hard links (which can be understood as reference counters for disks), creating a hard link corresponding to the i_nlink will increase for the RM command, the actual reduction of the disk reference count I_nlink. When both I_nlink and I_count are 0 o'clock, the file is deleted (the deletion refers to the deletion of the file name to the Inode, but the block data blocks on the disk are not deleted).

Linux file or directory properties

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.