Linux file system and management

Linux file system and management

A, Linux system's file system and directory structure

  Linux system file directory structure of a single inverted tree structure embodied in the following figure:

From CentOS7 start, and previous versions of the directory changes

◆ / bin soft link to the / usr / bin

◆ / sbin soft link to the / usr / sbin

◆ / lib soft link to the / usr / lib

◆ / lib64 soft link to the / usr / lib64

File system starting from the root directory, use the "/" means

◆ boot: the boot file storage directory, kernel file (vmlinuz), the boot loader (bootloader, grub) are stored in this directory

◆ / bin: all basic commands used by the user; can not be associated to a separate partition, OS will be used to start a program that is

◆ / sbin: basic commands management classes; not related to a separate partition, OS will start a program that is used

◆ / lib: When you start the program depends on the basic shared libraries and kernel module files (/ lib / modules)

◆ / lib64: on x86_64 systems dedicated to assisted shared library file location

◆ / etc: Configuration Files directory

◆ / home / USERNAME: ordinary users home directory

◆ / root: home directory administrator

◆ / media: a portable mobile device mount point

◆ / mnt: Temporary file system mount points

◆ / dev: special device file, and the file storage location
b: block device, a random access
c: character device, linear access

◆ / opt: third-party application installation location

◆ / srv: services running on the system used data

◆ / tmp: temporary file storage location

◆ / usr: Universal Shared, Read-only Data
bin: to ensure the system has fully functional and provide application
sbin:
lib: 32 bit using
lib64: there is only 64-bit system
include: headers C program (header Files)
Share: independent structured data, e.g. doc, man and other
local: installation location of the third party application
bin, sbin, lib, lib64, etc, share

◆ / proc: Kernel and process for outputting information related to the virtual file system

◆ / sys: system hardware device for outputting information on the virtual file system is currently

Storage location information security enhanced Linux, selinux related security policies: ◆ / selinux

Second, the file type under Linux

◆ - regular file

◆ d directory file

◆ b block device

◆ c character device

◆ l symbolic link file

◆ p conduit pipe file

◆ s socket file socket

Third, the three kinds of time to file atime mtime ctime

Linux systems, the file there are three time state property

1, this time three meanings:

atime: Access Time last accessed files (read or execute) or time directory;

mtime: Modofy Time last modified file contents (data) or time directory contents (file list in the directory);

ctime: Change Time last change file attributes (metadata) or directory attribute (metadata) of time;

2, how to view the file or directory atime / mtime / ctime

By stat to see all three time command

[root@centos7 data]#stat test.txt 
  File: ‘test.txt’
  Size: 0           Blocks: 0          IO Block: 4096   regular empty file
Device: 803h/2051d  Inode: 67          Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:etc_runtime_t:s0
Access: 2019-07-28 15:25:54.755150776 +0800
Modify: 2019-07-28 15:25:54.755150776 +0800
Change: 2019-07-28 15:25:54.755150776 +0800
 Birth: -
[root@centos7 data]#

Or can be separately viewed through the following command:

View atime: ls -lu filename

[root@centos7 data]#ls -lu test.txt 
-rw-r--r--. 1 root root 0 Jul 28 15:25 test.txt
[root@centos7 data]#

View mcime: ls -l filename

[root@centos7 data]#ls -l test.txt 
-rw-r--r--. 1 root root 12 Jul 28 15:29 test.txt
[root@centos7 data]#

View ctime: ls -lc filename

[root@centos7 data]#ls -lc test.txt 
-rw-r--r--. 1 root root 12 Jul 28 15:29 test.txt
[root@centos7 data]#

Four, Linux file system inode

1. What inode that?

  Understanding inode, file storage from the start.

  Files are stored on the hard disk, hard disk smallest unit of memory called a "sector" (Sector). Storage 512 bytes per sector (corresponding to 0.5KB).

  Operating system reads the hard disk, it does not read a sector, so that efficiency is too low, but a plurality of disposable continuous reading of sectors, i.e., a one-time read "block" (block). This "block" composed of a plurality of sectors, is a minimum unit of file access. Size "chunks", the most common is 4KB, namely eight consecutive sector to form a block.

  File data is stored in the "block", then it is clear that we must find a place to store meta-information file, such as the creator of the file, the file creation date, file size, and so on. This meta-information file storage area is called the inode, the Chinese translation for inode .

  Each file has a corresponding inode, which contains some of the information associated with the file. The system is to identify the file from the inode number.

2, the information contained in the inode

  inode contains attribute information (metadata) files, specifically, have the following:

    * 文件的字节数

  * 文件拥有者的User ID

  * 文件的Group ID

  * 文件的读、写、执行权限

  * 文件的时间戳,共有三个:ctime指inode上一次变动的时间,mtime指文件内容上一次变动的时间,atime指文件上一次打开的时间。

  * 链接数,即有多少文件名指向这个inode

  * 文件数据block的位置

3, inode features

  • inode will consume disk space, in the hard disk formatting, the operating system will automatically drive into two regions, a portion of the inode information used to store a portion of the file data is stored.

  • Each of the inode size, typically 128 bytes or 256 bytes. The total number of the inode is, for a given when formatting, usually per 1KB 2KB or sets a per inode.

  • Each on a separate partition disk inode number are independent of each other.

Check each hard disk partition and the total number of inode number has been used, you can use df -i command.

[root@centos7 ~]#df -i
Filesystem       Inodes  IUsed    IFree IUse% Mounted on
/dev/sda2      26214400 131432 26082968    1% /
devtmpfs         228956    391   228565    1% /dev
tmpfs            232906      1   232905    1% /dev/shm
tmpfs            232906    872   232034    1% /run
tmpfs            232906     16   232890    1% /sys/fs/cgroup
/dev/sda3      26214400      4 26214396    1% /data
/dev/sda1        524288    342   523946    1% /boot
tmpfs            232906      9   232897    1% /run/user/42
tmpfs            232906      1   232905    1% /run/user/0
[root@centos7 ~]#

Fifth, hard links, soft links and file properties difference

  • Hard links: on the same file system files with different file names (the same disk partition) the same inode number, corresponding to the same location on the same block disk file system.

  • Soft link: a symbolic link to a file that points to another file or directory, and file inode number is not the same point.

The difference between hard and soft links connected to:
(1) the nature: Hard link: the same file multiple names, soft different connection file.

(2) can not be cross-linked hard partitions, soft links.

(3) does not support hard links to directories, soft links support.

(4) the relationship: hard links are independent of one relationship, a soft link is dependent on mutual relations.

(5) inode number, the same hard links, different soft connection.

(6) the number of links. Hard links will increase or decrease, soft links unchanged.

(7) path problem: the path of the original file. Hard links relative path is the current working directory, the connection is relatively soft path is determined by the path of a soft link behind.

Guess you like

Origin www.cnblogs.com/eddie1127/p/11260402.html