What this section says:
- 4.1 Linux system directory structure and relative/absolute path.
- 4.2 Create/Copy/delete files, RM-RF/accidents
- 4.3 commands to view the contents of a file
- 4.4 Combat: Backup and Recovery of XFS file systems
4.1 Linux system directory structure and Relative/absolute path 4.1.1 System directory structure
In the win system, the view file enters the corresponding drive letter first, then enters the file directory
In win, it is a multi-root c \ d:\ e:\
Linux has only one root directory
Using the tree command to view the Linux directory structure, this command is not installed by default and requires manual installation
[[email protected] ~]# mount /dev/sr0 /media/mount: /dev/sr0 写保护,将以只读方式挂载[[email protected] ~]# rpm -ivh /media/Packages/tree-1.6.0-10.el7.x86_64.rpm查看/tmp目录结构[[email protected] ~]# tree /tmp/
See what files are under the root:
directory function under root description :
Directory Description/At the top of the Linux system tree structure, it is the gateway to the Linux file system, all directories, files, devices are in/under/bin bin is the abbreviation of binary. Commonly used binary command directories. such as LS, CP, mkdir, cut, and so on; similar to/usr/bin, some user-level GNU tools/boot-stored system boot-related files, such as: Kernel.grub (boot loader)/dev Dev is the abbreviation for device. Device files directory, such as sound card, disk ... Everything in Linux is considered a file. Terminal devices, disks, and so on are considered file device files:/dev/sda,/dev/sda1,/dev/tty1,/dev/tty2,/dev/pts/1,/dev/zero,/dev/null,/dev/cdrom/etc Common system and Binary installation package profile default path and Server startup command directory passwd user information file shadow user password file group storage user groups Information Fstab system boot automatically mount partition list hosts set the user's own IP and hostname corresponding Information/ Home directory of the home user default storage directory/lib library file directory, library directory/lost+found only in CENTOS6 default is empty, is fsck (file system check for checking and maintaining inconsistent filesystem. If the system is out of power or if there is a problem with the disk, you can use the fsck command to check the file system to place scattered files (files with no name) when the system shuts down illegally, some files will be stored here. Under the CENTOS6 version, under the mount point of each partition, there will be some directories/mnt/media generally used to temporarily mount the storage device mount directory, such as CDROM, U disk and other directories in the CENTOS7 will be mounted to/run below/opt is a selectable meaning, Some packages will also be installed here/proc the operating system, the process (running program) information and kernel information (such as CPU, hard disk partition, memory information, etc.) are stored here. The/proc directory is a mounted directory of spoofed file system proc, Proc is not a real file system. Therefore, this directory is a virtual directory, it is the mapping of system memory, we can access this directory directly to obtain system information. That is, the contents of this directory are not on the hard disk but in memory to view our CPU information Cat/proc/cpuinfo/sys system directory, storage hardware information related files/run run directory,Storage is the system runtime data, such as the process of the PID file/srv service directory, the storage of our local services related files/sbin Most of the commands involved in system management are stored in this directory, it is the super-user root executable command storage location, Ordinary users do not have permission to execute the command under this directory, general directory sbin contains the commands are root permissions to execute the directory for temporary files, and sometimes when the user runs the program, there will be some temporary files. /tmp is used to store temporary files. /var/tmp directory and the role of the directory is similar, can not store important data, its permissions are more special [[email protected] ~]# ls–ld/tmpdrwxrwxrwt root root 12288 Oct 3 20:45/ tmp/? The sticky bit of the sticky bit (sticky bit) directory indicates that the files in this directory can only be deleted by owner and root, the log information generated when the Var system runs and the software is running, the contents of which are constantly changing, and the files that contain the changes are stored. For example, the/var/log directory is used to store the system log directory, and mail,/VAR/SPOOL/CRON/USR store applications and files,/usr/bin the application used by ordinary users/usr/sbin administrators to use the application/usr/ LIB Library file glibc (32-bit)/usr/lib64 library file glibc/lib/lib64 in the/usr/directory, this directory contains the system's most basic dynamic link sharing library, including many of the/bin/and/sbin/of the program used by the library files, directory/usr The/lib/contains more library files for user programs. function similar to DLL files in Windows, almost all applications need to use these shared libraries Note: LIB***.A is a static library lib***. So is a dynamic library static library that is loaded into a binary file at compile time the dynamic library is loaded into the process's memory space at run time. These libraries are designed to allow your program to compile and run normally similar to the win. dll file, and almost all applications need to use these shared libraries
4.1.2 Absolute path and relative path
Path: In our usual use of the computer to find the required files must know the location of the file, and the way to indicate the location of the file is the path
Absolute path: The path from/start/HOME/MK
Relative path: Starting with the current directory, a.txt./a.txt. /miao/b.txt current directory In/etc
[[email protected] ~]# cd /etc/[[email protected] etc]# ll passwd -rw-r--r-- 1 root root 2116 11月 16 14:57 passwd[[email protected] etc]# ll /etc/passwd-rw-r--r-- 1 root root 2116 11月 16 14:57 /etc/passwd
Contact information:
Learn God It Education official website: http://xuegod.ke.qq.com
Learn God it Education-linux Technical Exchange QQ Group: 722287089
Ask MK teacher qq:2659153446
4.2 Management of files
4.2.1 Creating files and folders
Command: Touch
- Function: Often used to create an empty file, if the file exists, then modify the time of the file
Supplement: three times of file
[Email protected] ~]# ll/etc/passwd #查看文件修改的时间
-rw-r--r--1 root root 2116 November 14:57/etc/passwd
[[email protected] ~]# stat/etc/passwd #查看文件属性 (including file Time properties)
File: "/etc/passwd"
Size: 2116 Block: 8 IO block: 4096 normal file
Device: 803h/2051d inode:9401663 hard Link: 1
Permissions: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root)
Last visited: 2017-11-16 14:57:39.923177258 +0800
Last modified: 2017-11-16 14:57:39.397177256 +0800
Last modified: 2017-11-16 14:57:39.409177256 +0800
Note:
Access time: Atime View content Cat A.txt
Modified: Mtime Modify the content vim A.txt
Time to change: CTime file attributes, such as permission changes. chmod +x a.sh
Syntax: Touch file name
[[email protected] ~]# cd /opt/[[email protected] opt]# touch a.txt[[email protected] opt]# touch file1 file2[[email protected] opt]# touch file{6..20} #创建file6到file20的文件[[email protected] opt]# lsa.txt file10 file12 file14 file16 file18 file2 file6 file8 rhfile1 file11 file13 file15 file17 file19 file20 file7 file9[[email protected] opt]# touch -d "20181019 21:30" xuegod.txt[[email protected] opt]# ll xuegod.txt -rw-r--r-- 1 root root 0 10月 19 2018 xuegod.txt
4.2.2 Creating a new file using VIM and redirection
Create a new file with the VIM command
[[email protected] mnt]# vim xuegod-1.txt
Create a new file with redirection
[[email protected] mnt]#echo aaa > xuegod.txt
4.2.2 Command: mkdir
Role: Create a directory
Syntax: mkdir (option) file name example:
[Email protected] opt]# mkdir Dir1
[Email protected] opt]# mkdir dir2 DIR3/HOME/DIR4
[Email protected] opt]# ls/home/
DIR4 MK
[Email protected] opt]# mkdir/tmp/a/b/c
mkdir: Unable to create directory "/TMP/A/B/C": No file or directory
[[email protected] opt]# mkdir-p/tmp/a/b/c #在创建一个目录的时候, if the upper level of this directory does not exist, add parameter-P
[Email protected] opt]# ls/tmp/a/b/
C
4.2.2 Deleting files and directories
Command used: RM
- Function: You can delete one or more files or directories in a directory, for a linked file, just delete the entire linked file, and the original file remains unchanged
- Syntax: RM (option) Processing object
- Options:
-F Force Delete, no prompt
-R Delete Directory
Example:
[[email protected] opt]# rm -rf a.txt [[email protected] opt]# rm -rf a.txt dir[[email protected] opt]# rm -rf file*rm -rf (慎用,一定要在删除以前确定一下所在目录,防止误删除重要数据)
4.2.3 Copying files
- Command: CP source file/directory directory File/directory
- Option:-r/r: Recursively handles all files in the specified directory with subdirectories
Example:
[[email protected] ~]# cp /etc/passwd /opt/ #复制文件[[email protected] ~]# cp -r /boot/grub /opt/ #复制目录
4.2.4 Moving files
[[email protected] opt]# mv passwd dir1[[email protected] opt]# mv xuegod.txt dir1/a.txt #在移动文件的时候支持改名操作
The Linux architect's high-paying entrance:
1. Learn God It Education official website: http://xuegod.ke.qq.com
2.1 Years veteran veteran of the industry MK:QQ2659153446
3. Join the Linux Technical Communication QQ Group:722287089, you can get the following benefits:
① regularly share free learning materials and videos (Tools + notes + expand Combat)
②10 senior veteran old birds online answer: Skills + Combat + Project sharing + high-paying employment
③ has the opportunity to receive 4 books of Linux cloud computing cluster architects free of charge
4.3 View files 4.3.1 command: Cat
- Syntax: Cat file name
- Function: View the contents of the file and display the contents of the whole file at once
- Example: [[email protected] ~]# CAT/ETC/PASSWD
4.3.2 Command: More
- Function: Displays the contents of a file in pagination form
- Syntax: more + file name
- Note: Press ENTER to refresh a row, press the space to refresh a screen, enter the Q key to exit
4.3.3 Command: Less
- Function: As with more functions
- Syntax: less + file name
- Description: The difference between more and less in Linux
- MORE: Does not support back, but almost no need to add parameters, the space bar is the page down, the ENTER key is down the line, in the case of no need to retreat more convenient
- Less: Supports rollover, either up (PageUp button) or down (pagedown button). , the SPACEBAR is a page down, and the ENTER key is a downward-turning line
4.3.4 Command: Head
4.3.5 command: Tailhead
- Function: Used to display the tail content in a file. Displays the end of the specified file on the screen by default 10 lines
- Syntax: tail (option) file name
Parameters:
-N Displays the contents of the number of lines at the end of the file (n is number)
-F Dynamic display of data (not closed), commonly used to view the log
[Email protected] ~]# tail-n 3/var/log/secure #查看最后3行记录
[Email protected] ~]# tail-f/var/log/secure #在一个终端执行此命令动态查看文件内容
[[email protected] ~]# ssh [email protected] #在另一个终端远程登录Linux, after successful login
[Email protected] ~]# tail-f/var/log/secure #可以动态查看到登录成功的日志
Nov 00:08:32 xuegod63 sshd[2924]: Accepted password for root from 192.168.1.63 Port 39904 ssh2
4.4 Combat: Backup and Recovery of XFS file systems
XFS provides Xfsdump and Xfsrestore tools to assist in backing up data from XFS file systems. Xfsdump back up an XFS file system in Inode order.
- CENTOS7 Choose XFS Format as the default file system, and no longer use the previous ext, still support EXT4,XFS for big data, each individual file system can support 8EB, a single file can support 16TB, not only the data volume is large, but also high scalability. You can also back up and restore through Xfsdump,xfsrestore.
Unlike traditional UNIX file systems, XFS does not need to be unloaded prior to backup, and a backup of the in-use XFS file system can guarantee the consistency of the image. The process of backing up and recovering xfs can be interrupted and then resumed without having to freeze the file system. Xfsdump
Even provides high-performance multi-threaded backup operations-it splits a dump into multiple streams, and each stream can be sent to a different destination
First of all, to understand the Xfsdump backup level of the following two, the default is 0 (that is, full backup) 0 levels of Representatives: full backup 1 to 9 levels of representatives:
Incremental backup
Extended:
- Full backup: Each time the specified backup directory is fully copied, regardless of the file under the directory has not changed;
- Incremental backup: A file that has changed before (first, second, until previous) has been backed up;
- Differential backup: Each time a file that has changed since the first full backup is backed up.
4.4.1 Environment Preparation
Lab Environment:
- System CENTOS7.2 Add a virtual hard disk (prepare a test partition) the normal use of a disk procedure is as follows: Add disk size: 20G partition? format? mount
To format the newly added hard drive:
[r[email protected] ~]# fdisk/dev/sdb #指定分区的设备欢迎使用 fdisk (util-linux 2.23.2). The changes will remain in memory until you decide to write the changes to disk. Think twice before you use the Write command. Device does not contain a recognized partition table uses the disk identifier 0x06d5a427 to create a new DOS disk label. Command (input m for help): N #创建一个新的分区Partition type:p Primary (0 primary, 0 extended, 4 free) e extendedselect (default p): P #创建一个主分区分区号 (1-4, default 1): Start sector (2048-41943039, default = 2048): Default value of 2048Last sector, + sector or +size{k,m,g} (2048-41943039, default = 419430) will be used : +1g #指定分区大小分区 1 is set to Linux type, size set to 1 Gib command (input m for help): P #打印分区表磁盘/dev/sdb:21.5 GB, 21474836480 bytes, 41,943,040 sector Uni TS = Sector of 1 * bytes sector size (logical/Physical): 512 Bytes/512 bytes I/o size (min/best): 512 Bytes/512 bytes disk label type: DOS disk identifier: 0x06d5a427 device Boot Start End Blocks Id system/dev/sdb1 2048 2099199 1048576 the linux command (input m for help) : w #保存The partition table has been altered! Calling IOCTL () to re-read partition table. Synchronizing disks. [[email protected] ~]# LS/DEV/SDB*/DEV/SDB/DEV/SDB1 uses the new partition, formats the partition,and mount [[email protected] ~]# mkfs.xfs/dev/sdb1[[email protected] ~]# mkdir/sdb1 #创建挂载点 [[Email protect Ed] ~]# mount/dev/sdb1/sdb1 #挂载准备备份测试文件 [[email protected] ~]# cd/sdb1/[[email protected] sdb1]# Cp/etc/pas SWD./[[email protected] sdb1]# mkdir test[[email protected] sdb1]# touch test/a[[email protected] sdb1 ]# tree/sdb1/[[email protected] sdb1]# tree/sdb1//sdb1/├──passwd└──test└──a
4.4.2 Backup
1. Back up the entire partition. (This function is like a snapshot of a virtual machine, the server is hacked and then quickly restored)
Xfsdump-f backup location to back up paths or device files
Note: The path to the backup cannot be written as/sdb1/here. It could be/dev/sdb1 or/SDB1.
[[email protected] sdb1]# xfsdump-f/opt/dump_sdb1/dev/sdb1xfsdump:using file Dump (drive_simple) strategyxfsdum P:version 3.1.4 (Dump format 3.0)-type ^c for status and control========== Dump label Dialog ========================== ====please Enter label for this dump session (timeout in SEC), DUMP_SDB1 specify the backup session tag session label entered: "Dump_sd B1 "---------------------------------End dialog---------------------------------xfsdump:level 0 dump of xuegod63.cn :/sdb1xfsdump:dump date:fri Nov 12:24:53 2017xfsdump:session Id:b5a25fcd-d43d-4308-bf29-142066f89d9axfsdump:sessi On label: "DUMP_SDB1" Xfsdump:ino map phase 1:constructing initial dump Listxfsdump:ino map phase 2:skipping (No Prunin G necessary) Xfsdump:ino map phase 3:skipping (only one dump stream) Xfsdump:ino map construction Completexfsdump:estima Ted Dump size:25856 bytes============== Media Label Dialog =============================please enter label for media in D Rive 0 (Timeout in sec)-&Gt SDB1 Specifies the device label, which is a description of the device to be backed up media label entered: "SDB1"---------------------------------End Dialog------------------- -------------xfsdump:creating Dump Session media file 0 (media 0, file 0) xfsdump:dumping ino mapxfsdump:dumping Directo riesxfsdump:dumping non-directory filesxfsdump:ending Media filexfsdump:media file size 24544 bytesxfsdump:dump size ( Non-dir files): 2592 bytesxfsdump:dump complete:46 seconds elapsedxfsdump:dump Summary:xfsdump:stream 0/opt/dump_s DB1 OK (Success) Xfsdump:dump status:success
2, the designated backup is free of interaction, convenient late to do scheduled backup
[[email protected] sdb1]# xfsdump -f /opt/dump_passwd /sdb1 -L dump_passwd -M media1-L :xfsdump 纪录每次备份的 session 标头,这里可以填写针对此文件系统的简易说明-M :xfsdump 可以纪录储存媒体的标头,这里可以填写此媒体的简易说明
3. Specify that only one directory in the partition is backed up
参数:-s 文件路径 只对指定的文件进行备份,-s指定时,路径写的是相对路径(-s可以是文件或目录)[[email protected] sdb1]# xfsdump -f /opt/dump_grub2 -s grub2/grub.cfg /boot -L dump_grub2 -M boot-sda1
4. View backup information and content
备份成功后,我们就可以在/var/lib/xfsdump/inventory目录下看到生成的档案信息[[email protected] opt]# xfsdump -I(字母大写i)测试恢复:先删除之前创建的内容[[email protected] sdb1]# lspasswd test[[email protected] sdb1]# pwd/sdb1[[email protected] sdb1]# rm -rf ./*
4.4.3 File System Recovery
Syntax: xfsrestore-f Specifies the location of the recovery file specifies the path to the recovered file
[[email protected] opt]# xfsrestore -f /opt/dump_sdb1 /sdb1
View recovery Status
[[email protected] ~]# ls /sdb1/
Restore individual files as follows:
[[email protected] ~]# mkdir /var/test/ [[email protected] ~]# xfsrestore -f /opt/dump_grub2 -s grub2/grub.cfg /var/test/[[email protected] ~]# xfsrestore -f /opt/dump_grub2 -s grub2 /var/test/ #恢复目录
Note:
When using Xfsdump, be aware of the following limitations:
1、xfsdump 不支持没有挂载的文件系统备份!所以只能备份已挂载的!2、xfsdump 必须使用 root 的权限才能操作 (涉及文件系统的关系)3、xfsdump 只能备份 XFS 文件系统4、xfsdump 备份下来的数据 (档案或储存媒体) 只能让 xfsrestore 解析5、xfsdump 是透过文件系统的 UUID 来分辨各个备份档的,因此不能备份两个具有相同 UUID 的文件系统
4.4.4 Incremental Backup
Concept
- Incremental backup means that after a full or last incremental backup, each subsequent backup needs only to back up the files that were added or modified compared to the previous one. This means that the object of the first incremental backup is the addition and modification of the file that is produced after the full preparation, and the second incremental backup object is the addition and modification of the file resulting from the first incremental backup, and so on.
Advantages and Disadvantages
- Pros: There is no duplicate backup data, so the amount of data backed up is small and the backup takes a short time.
- Cons: Data recovery is relatively cumbersome, it requires the content of the last full backup and all incremental backups to be fully successful, and they must be reversed one by one in the order of time from full backup to sequential incremental backup, and therefore may prolong recovery time
Actual Combat: Incremental backup File system
Prepare a backup directory for backup
[[email protected] sdb1]# tree /sdb1/sdb1/├── passwd└── test └── a
First full preparation of the above content
[[email protected] sdb1]# xfsdump -f /opt/test-full /sdb1 -L test-full -M media0
Add some content, and then make a 1th incremental backup
[[email protected] ~]# touch /sdb1/1.txt /sdb1/2.txt[[email protected] ~]# tree /sdb1//sdb1/├── 1.txt├── 2.txt├── passwd└── test└── a [[email protected] sdb1]# xfsdump -l 1 -f /opt/test-back1 /sdb1 -L test-bak1 -M media0-l <level> 做一个等级为1的备份
Add the content again and then make the Level 2 incremental
[[email protected] sdb1]# touch /sdb1/test/a.txt /sdb1/test/b.txt[[email protected] ~]# tree /sdb1//sdb1/├── 1.txt├── 2.txt├── passwd└── test ├── a ├── a.txt└── b.txt [[email protected] sdb1]# xfsdump -l 2 -f /opt/test-back2 /sdb1 -L test-bak2 -M media0[[email protected] ~]# rm -rf /sdb1/* #删除所有数据
Restore now, to recover all the data, including the newly added files, how to recover?
Steps:
1. Restore full backup first
- 2, Situation 1: Restore the last incremental backup (if two incremental backups are 1 levels, you only need to restore the last increment.)
3, Situation 2: If you do is the first time is 1, the second is a 2-level preparation, then you need to restore the full backup first, then the 1 level of preparation, and finally 2 levels of preparation)
[Email protected] ~]# xfsrestore-f/opt/test-full/sdb1/
[Email protected] ~]# xfsrestore-f/opt/test-back2/sdb1/#故意先恢复back2, view
[Email protected] ~]# tree/sdb1/#查看, found no 1.txt, 2.txt
/sdb1/
├──passwd
└──test
├──a
├──a.txt
└──b.txt
[Email protected] ~]# xfsrestore-f/opt/test-back1/sdb1/
[Email protected] ~]# tree/sdb1/
In this case, the data recovery was successful.
The Linux architect's high-paying entrance:
1. Learn God It Education official website: http://xuegod.ke.qq.com
2.1 Years veteran veteran of the industry MK:QQ2659153446
3. Join the Linux Technical Communication QQ Group:722287089, you can get the following benefits:
① regularly share free learning materials and videos (Tools + notes + expand Combat)
②10 senior veteran old birds online answer: Skills + Combat + Project sharing + high-paying employment
③ has the opportunity to receive 4 books of Linux cloud computing cluster architects free of charge
Public Number:
MK Teacher Number:
Summarize:
- 4.1 Linux system directory structure, relative/absolute path.
- 4.2 Create/Copy/delete files, RM-RF/accidents
- 4.3 commands to view the contents of a file
- 4.4 Combat: Backup and Recovery of XFS file systems
Basic management of centos7.5-files and XFS file system backup Recovery