3.1 Linux File information
Inode and directory entries
1, what are inode and directory entries
The minimum storage unit for a file on the hard disk is called a sector, and each sector stores 512 bytes. When the operating system reads the hard disk, it does not read one sector at a time, but reads multiple sectors at once, that is, one time to read a block, the size of the block is the most common is 4K, that is, eight consecutive sectors to form a block.
File data is stored in blocks, then and obviously, there must also be a place to store meta information for the file. For example, the creator of the file, the date the file was created, the length of the file, and so on, the area where the file meta information is stored is called the Inode (Index node).
The file name is not stored in the inode, but is saved in the directory entry, and the file name is associated with the corresponding inode.
2,inode size
The inode also takes up disk space, so when the hard disk is formatted, the operating system automatically divides the hard disk into two areas, one data area, the file data, and the other is the Inode area, which holds the information contained in the Inode.
The size of each inode node is typically 128 bytes or 256 bytes, and the total number of Inode bytes is specified at the time of formatting, typically one inode per 1KB or 2KB. Suppose that in a 1GB drive, each inode node has a large size of 128 bytes, each 1KB
If you set up an inode, the Inode table will be up to 128MB in size, accounting for 12.8% of the entire drive. Use the DF command to see the total number of inode and the number of adaptations per hard disk partition.
# df-i
File system Inode Used (i) available (i) used (i) percent mount point
/dev/mapper/vg_server-lv_root
3276800 94445 3182355 3%/
TMPFS 256881 5 256876 1%/dev/shm
/DEV/SDA1 128016 127973 1%/boot
/dev/mapper/vg_server-lv_home
2990080 2990068 1%/Home
---------------------------------------------------------------------
To see the size of each inode, you can use the following command:
# dumpe2fs-h/dev/sda1 |grep "Inode size"
DUMPE2FS 1.41.12 (17-may-2010)
Inode size:128
---------------------------------------------------------------------
Since each file must have an inode, it is possible that the inode has been exhausted, but the hard disk is not yet full, and no new files can be created on the hard disk.
3,inode Number:
Each inode has a number, the Linux system uses the inode number to identify different files, the Linux system does not use the file name, and the inode number to identify the file, for the system, the file name is the inode number is easy to identify the alias. On the surface of the user to open the file by filename, in fact, the system inside this process is divided into three steps: first the system to find the file name corresponding inode number, followed by inode number to obtain the inode information, and finally based on information to find the block of file data, and then read the data.
Use the Ls-i command to view the inode number for the file name:
# ls-i Test.log
3019507 Test.log
---------------------------------------------------------------------
3.2 Use the Stat command to view file information.
Use the Stat command to view file information such as Inode, permissions, time attributes, file size, owner, number of links, and file type.
#stat KKK
File: "KKK"
size:4096 blocks:8 IO block:4096 Directory
device:fc02h/64514d inode:2228225 Links:2
Access: (0755/drwxr-xr-x) Uid: (0/root) Gid: (0/root)
ACCESS:2017-07-17 20:07:20.463000814 +0800
MODIFY:2017-07-17 20:06:49.095997672 +0800
CHANGE:2017-07-17 20:06:49.095997672 +0800
CD Change Working directory path
Absolute path starts with/(root) and then loops the desired directory under
Relative path starts from current directory
CD ~: Go to the user's home directory
--------------------------------------------------------------------
CD-: Returns the directory where it was before entering this directory
--------------------------------------------------------------------
Cd.. : Return to Parent directory
--------------------------------------------------------------------
Cd.. /.. : Returns to the top level two directory
---------------------------------------------------------------------
Touch: Create an empty file and change the file time.
---------------------------------------------------------------------
mkdir: Create directory:
-P: Create more than one directory at a time.
---------------------------------------------------------------------
#du-A/boot|sort-rn|head-5
45791/boot
16124/boot/initramfs-2.6.32-358.el6.x86_64.img
15816/boot/initramfs-2.6.39-400.17.1.el6uek.x86_64.img
4011/boot/vmlinuz-2.6.39-400.17.1.el6uek.x86_64
3951/boot/vmlinuz-2.6.32-358.el6.x86_64
---------------------------------------------------------------------
Sort
-N Sorts by the size of the numeric value.
-R is sorted in reverse order.
---------------------------------------------------------------------
Head
The head is used to display the beginning of the file to the standard output, and the default head command prints the first 10 lines of its corresponding file.
Head-n the number of rows displayed.
---------------------------------------------------------------------
Tail
The last 10 lines of the file are viewed by default.
Tail-5 viewing the last 5 lines of a document
---------------------------------------------------------------------
LS lists directory and file information
Number of file properties files The group file size file name to which the owner belongs
DRWX------2 Guest users 1024x768 2121:05 Mail
-rwx--x-x 1 root root 89080 7 22:41 tar
-rwxr-xr-x 1 Root bin 5013 9:32 uname
-rwxr-xr-x 1 Root bin 308364 7:43 zsh
-rwsr-x---1 root bin 9853 155:46 su
Example, the last access time of a file (after the most recent time), sorting the files and subdirectories in the/root directory
#ls-ltr/root
Total Dosage 32
Drwxr-xr-x. 2 root root 40967 month 1713:29 desktop
Drwxr-xr-x. 2 root root 40967 month 1713:29 music
Drwxr-xr-x. 2 root root 40967 month 1713:29 downloads
Drwxr-xr-x. 2 root root 40967 months 1713:29 documents
Drwxr-xr-x. 2 root root 40967 months 1713:29 images
Drwxr-xr-x. 2 root root 40967 month 1713:29 video
Drwxr-xr-x. 2 root root 40967 month 1713:29 templates
Drwxr-xr-x. 2 root root 40967 month 1713:29 public
-rw-r--r--1 root root 0 July 19:49 oracle-release
3.3 Introduction to Linked files:
The LN command is provided under the Linux system for file linking. File links are mainly divided into hard links and soft links.
1, Hard link: Because files under Linux are identified by an index node (inode), a hard link can be considered a pointer to a pointer to a file index node, and the system does not redistribute the inode for it. Each add a hard link, the number of links to the file is added 1.
You can use the: ln command to create a hard link
For example:
ln file01 hardfile01 to build file01 hard links
Insufficient:
Although hard links save space and are the traditional way for Linux systems to integrate file systems, there are shortcomings:
(1) No link can be established between files in different file systems
(2) Only Superuser can create a hard link for a directory.
When you cancel a hard link, you can use unlink to cancel any one, no effect on other files
Example: Unlink file01
2, soft links overcome the lack of hard links, no file system restrictions, any user can create a symbolic link to the directory.
LN-S ABC CDE establishes the soft connection of ABC
Linux Command Learning-the third day