File attribute components (8 parts in total)
ll -i /etc/hosts 16778299 - rw-r--r--. 1 root root 158 6 July 2013 /etc/hosts 1)In file properties inode(index node): Inodes locate data storage locations faster==Catalogue of books 2)File type information:- Ordinary file d Catalog file l Soft link file 3)File permission settings: r read w write x Executable - No permission The system data permission is granted to three persons: the file owner--User group owned by master file--Other users of group files 4)Number of hard links in the file:??? 5)User information of the file 6)User information of the group to which the file belongs 7)File size information 8)Modification time of file
1. Detailed introduction to file attributes
(1) File type introduction
- The file type information does not change with the file extension name
Description of documents by type: - Ordinary files: (f / -) binary files compressed data files text files
- Catalog file: (d)
- Link file: (l) soft link file
File type identification method: file
file command: can identify directory script configuration compression
Supplementary extension 1: display absolute information of file path: which whereis
[root@centos-server ~]$which timedatectl /usr/bin/timedatectl [root@centos-server ~]$which sed /usr/bin/sed
which command to view the command file path range:
[root@centos-server ~]$which sed /usr/bin/which: no sed in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
The PATH environment variable specifies the PATH range where the command file is saved
[root@centos-server ~]$echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
You can modify the PATH environment variable temporarily or permanently
[root@centos-server ~]$PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local" [root@centos-server ~]$which sed /usr/local/sed [root@centos-server ~]$PATH="$PATH:/usr/local"
=============================================================
yum #Install software command yun install -y #Install software yum erase #Uninstall software programs yum provides #Which package does the retrieval command file belong to yum search #Which package does the retrieval command file belong to
=============================================================
Supplementary extension 2: quickly locate the file to be found: locate
When searching the specified file information, you need to retrieve the database file first Update or create database files updatedb After the database file is updated, find the file to define the path where the file is located
Supplementary extension 3: quick find data information command: find
Command syntax structure: the path range of find and the conditions for finding data
Method 1: find data by name
find /opt -name "What to find" #You can find exactly or vaguely (* match) -i ignore the case of the file name
Method 2: find data according to file type
>>Recursively find all directory type data [root@centos-server /opt]$find /etc -type d|wc -l #Recursively find all directory type data 751 >>Find data by directory level find /etc -maxdepth 1 -type d|wc -l find /etc -mindepth 1 -type d|wc -l #-Type find data by type
Illustration explanation: the video is about 23:00-26:00
Method 3: search by file size
Find data unit information: `c' for bytes `k' for Kilobytes (units of 1024 bytes) `M' for Megabytes (units of 1048576 bytes) `G' for Gigabytes (units of 1073741824 bytes) Find less than how much data find /ytt/ -size -700k Find data larger than how much find /ytt/ -size +700k
Method 4: search according to time information
>>Indicates how many days ago the information was [root@centos-server ~/ytt]$find /ytt/ -mtime +60 >>Indicates the number of days of information [root@centos-server ~/ytt]$find /ytt/ -mtime -60
find command extension:
01.How to find data information by minute 02.How to find the data condition of multiple conditions one type of file condition two size greater than 10 M Condition 3 data 10 days ago 03.How to exclude the specified directory from searching /
Supplementary extension 4: data compression and packaging command tar
(1)How to package data: tar zcvf /Compressed file save path/Compressed file information needs compressed data information 01 02 03, etc Packed compressed data relative path: tar zcfv ./ytt.tar.gz/ ./etc ./ytt_now.txt z ---use gzip Compress and pack data c ---Create a compressed package file v ---Displays the data compression process f ---Identify compressed packet information and path information tar zcvf /backup/ytt.tat.gz /etc/ /ytt/ /var/log/messages tar:Removes the beginning from the member name"/" ---Compressed data information. If an absolute path is used, it will be compressed/Directory information removal Explanation: remove/The root directory information is mainly used to avoid that the decompressed data will overwrite the data information in the original directory (default setting) To view compressed package data information: tar tf /backup/ytt.tar.gz t ---The list shows the data information in the compressed package, but the compressed package will not be decompressed (2)Decompress data information tar zxvf x --- Extract compressed packet data information tar zxvf ytt.tar.gz -C /data --- Save the decompressed data in the specified path. The default is the current data Supplement: find Delete partial data information of the directory Method 1: exclude the location directory find /ytt/ -mindepth 1 !-name "*.tar.gz" Command parameter information file or directory (parameter) ---script find /ytt/ -mindepth 1 ! -name ".tar.gz"|xargs rm -rf xargs ---After the pipe symbol, it means that the results generated by the commands in front of the pipe symbol are converted into parameter information and handed over to xargs Subsequent commands are processed Method 2: delete some data find /ytt/ -mindepth 1 !-name "*.tar.gz" -delete Method 3: delete some data find /ytt/ -mindepth 1 !-name "*.tar.gz" -exec -rm rf {} \;
Compress or decompress data: why remove the / directory in front of the data information
First course: Environmental preparation: Create important profiles by information: cat /conf/ytt.conf ytt123 The second process: compress and save backup data information $ tar zcfPv /backup/ytt.tar.gz /conf/ytt.conf #Parameter P means that the root sign is not removed during compression /conf/ytt.conf $ tar tf /backup/ytt.tar.gz tar:Deletes the beginning of a hit from a member"/" /conf/ytt.conf --- View data not removed / information The third process: modify and edit the original configuration file $ cat /conf/ytt.conf ytt 123 456 789 The fourth process: decompress the data information (do not remove the root directory) tar xPf /backup/ytt.tar.gz #Parameter P means that the root is not removed during decompression View that the original data information is overwritten cat /conf/ytt.conf ytt 123 Conclusion: do not remove the previous/If so, the original data will be overwritten by the decompressed data. Note: if you need to overwrite data, you need to add parameters when compressing and decompressing P Use with caution!
Compressing data eliminates unwanted
tar zxcf /yyt/ytt.tar.gz /ytt/ --exclude=/ytt/ytt02.txt --Exclude single data tar zxcf /yyt/ytt.tar.gz /ytt/ --exclude-from=/ytt/paichu.txt --Exclude multiple data
@How to add new compressed data to an existing compressed package
@How to realize batch compression of different data information
Compress and save the files starting with h in the etc directory
=============================================================
Command supplement
du #View the comprehensive capacity of all data in the directory du -sh #Summarize the view directory size and display it in a human readable manner stat #You can view the detailed properties of the file xargs -nx #Divide the specified information into groups
=============================================================
(2) File user information
- User information concept: User: can manage corresponding data users, and can manage corresponding process users == UID User group: multiple people can manage a data file at the same time, and deliberately set and adjust the permissions of multiple people at the same time The system identifies the user group according to the user group number == GID - System user classification: System super administrator root 0 Have absolute control over the system System virtual user nobody 1-999 Can manage processes/Data information Unable to log in to the system/Cannot have home directory Ordinary users centos 1000+ auxiliary root User management system - Must be root Assign special rights to users
(3) File permission information:
r=4 w=2 x=1 -=0 Value information corresponding to permission symbol Conclusion: under normal circumstances, the file data permission has 9 bits ==3 Special permission bit
(4) File time attribute information
File time type:
Access time (atime): access time – the time when the file was viewed and opened
Modify time (mtime): modification time – the time when the file data content is changed
Change time (ctime): change time – the time when the file attribute information changes
Time related command: date
- View time information View the display time as required $ date "+%y-%m-%d %d %H:%M:%S" 2021-1-3 Jan 09:25:30 $ date "+%F" 2021-1-3 $ date"+%T" 09:26:06 To view past or future times: date -d "-1 day" #Show how many days in the past date -d "+19234 day" #Displays the time in the next few days 12 At 00:00 on December 31, backup the data the day before (December 30)-generate hosts-12 March 31 cp /etc/hosts /backup/hosts-$(date +%F) backups-generate hosts-12 June 30 -Time can be modified: date -s "2020-12-31 12:12:12" --- Complete adjustment time information
expand:
01. How to find data information by time
-mmin find /ytt -mmin -2
02. How to find data of multiple conditions
find /ytt -type d -a -name "ytt*" #-a and sets multiple conditions. Yes and find /ytt -type d -name "ytt*" -o -name "*.sh" #-o or set multiple conditions, yes or relationship find /ytt -mindepth 2-type f --- You don't have to see 01.txt file find /ytt -maxdepth 5 -type f --- You don't have to see 06.txt file find /ytt -mindepth 2 -maxdepth 5 -type f
03. How to exclude the specified directory from searching
/ytt/01/ytt.txt /ytt/02/ytt.txt /ytt/03/ytt.txt find /ytt -path "/ytt/01/*" -type f #Find the information under the directory Exclusion method 1: find /ytt -path !"/ytt/01/*" -type f #Exclude directory changes without searching Exclusion method 2: find /ytt -path "/ytt/01/*" -prune -o -type f -print #-prune stands for pruning
(5) File connection concept: soft connection and hard link
- Soft link file: Concept introduction: used to store path information pointing to source files (file shortcuts) Application scenario: it provides convenience for operating file data 1)Command file: ln -s Source file information soft link file information 2)configuration file: ln -s /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/ifcfg-eth0 3)It is convenient for developers to load service programs: /application/redis-4.0.6 --- Development code file /application/redis ln -s /application/redis-4.0.6 /application/redis Features: soft link files can create soft links to files or directories; After the source file is deleted, the linked file will become invalid - Hard link file: Concept introduction: equivalent to the entry to access files Application scenario: prevent accidental deletion of files 500 G--Database backup file PS: It is very important to create a hard link to this kind of file to prevent accidental deletion and loss xxx.conf --- cp Features: Hard link files can only be created for files, not directories After the source file is deleted, the hard link file still exists When a directory is created, there will be two hard links by default, one is the directory itself and the other is in the directory. A directory is created. If there are subdirectories (in subdirectories) .. Indicates the upper level directory itself), excluding the two default hard links, the remaining number indicates the number of subdirectories
(6) File inode information
inode: Index node Concept introduction: it is used to store file data attribute information and pointer information (pointing to the location of data storage) Birth process: a corresponding number of disks will be created when formatting the disk indoe ll -id #View inode number and attribute information block: Storage data block Concept introduction: real storage of data information Birth process: the corresponding number will be created when formatting the disk block
Graphic understanding:
01. When will the disk space be full
1)In disk space block Not enough --- A large number of data files (large size) have been stored 50 G 49G df #You can directly see the number of partition block s 2)In disk space inode Not enough --- A large number of data files (small files) have been stored 50 G 10G df -i #View available inode s du -sh #View the size of the capacity in the disk
02. How to obtain data information: principle of reading or writing data
Firstly, according to the path information, the attribute information of each path node and the data content in the directory are obtained ll -id Secondly, according to the path information, finally obtain the file information, and obtain the file according to the file attribute setting block Finally, you can view the complete content of the data
03. How to delete data information completely:
1)The number of hard links in the file is 0, and there is no difference inode Called 2)The file was not called by the program nginx -- access.log ps -ef #View process