This article mainly introduces, Linux directory standard, directory and file common operation commands, file system three parts
Linux directory standard: FHS
The Linux server we used, although there were many different distributions, had some similarities in their file directories. Linux directory configuration is based on the FHS standard. The FHS recommends that the root directory be partitioned separately, especially from the installed application, so that the file system where the root directory resides is less prone to problems.
The FHS standard mainly defines the contents of the three directories: 1: root / 2:/usr 3:/var. Common directories and files in the three directories are listed as follows. For details, refer to the FHS official documents:
1. Directories that must exist under the root directory/and their functions
- /bin: the system executable files are stored here, such as commonly used: CD cp find chmod chown and other commands
- /boot: stores the files used for system startup
- /dev: Devices and interface devices are stored as files in this directory, which also includes: stdin standard input: stderr standard output: stdout
- /etc: main configuration files of the system, such as user accounts and passwords, startup files of various services, etc
- /lib: the system function library
- /media: directory for mounting temporary devices such as floppy disks, CDS, and DVDS
- / MNT: Temporarily mount some additional directories
- /opt: indicates the directory where the third-party auxiliary software is stored
- /run: some information after the system has started
- /sbin: command used during startup
- / SRV: the location where data is stored after some network services are started
- / TMP: stores temporary files
- /usr: Level 2 has more directory requirements
- /var: The second layer has more directory requirements
Two: /usr directory must exist
- /usr/bin/: a command that can be used by all users. Centos7 has put all the commands that users can use here, and the root directory /bin is linked here
- /usr/lib/ : The root directory lib links to this directory
- /usr/local/ : software downloaded by the system administrator to the local computer
- /usr/sbin/: The root directory of sbin is linked to this
- /usr/share: places read-only data files that can be shared, such as help documents and instructions
3. /var directory: mainly stores some frequently changed files, such as MySQL, Redis database files
- /var/cache/ : Some cache generated while the application itself is running
- /var/lib/: data file used during application execution
- /var/log/ : specifies the directory for storing log files
- /var/run/ : PID after some programs start is placed in this directory, linked to the /run directory
Common operation commands for directories and files
File directory view: ls [-alst] a: all files and hidden files L: Detailed display information including file attributes and permissions S: sort by file capacity T: Sort by time Switching directories: CD Directory Displays the current directory: PWD Create directory: mkdir Delete directory: Rmdir Directory replication: cp [-rip] source file target file r: recursive replication I: If the target file already exists, ask whether to overwrite p: Copy with the file (permission, user, time), usually used on backup delete: rm [-fr] Directory/file f: Forcibly delete r: When deleting a directory, delete it recursively. Move: mv [Wi-Fi] Source file Target file F: Forcibly move it. I: If the destination file already exists, ask whether to overwrite itCopy the code
View file contents:
Display all file contents: cat [-n] File n: print line number View the first N lines of a file: head [-n value] File n: first N lines, 10 lines by default View the last n lines of a file: tail [-n value] File n: first N lines, 10 lines by default Create file: Touch [-m] file m: modified file mtime (last modified time)Copy the code
To package a tar file:
Package and compression: the tar [z | - | j - j] [CV] [-f the packaging file name] need to compress the directory/file decompression: the tar [z | - j | - j] [xv] [-f need to unzip the files] - C directory to view: Tar [z | - | j - j] [TV] [-f need to look at the compressed file] z, j, j represents three compression methods, respectively is: z: Gzip j:bzip2 j: xz bzip2 compression ratio is usually better than gzip, xZ compression ratio is better than bzip2, but xZ compression efficiency is very low, very small files take a long time to generate compression package. Gz /home: tar -zxv -f file1.gz -c /homeCopy the code
Find related commands
Which [-a] command a: List all the commands found in the PATH directory, by default only the first lookup command is listed: 'whereis [-l] File or directory name' l: Lists how many directory lookup commands have been found: Local [-ir] File/directory I: ignore case difference r: File/directory can be written regular expression search command: find [directory] [option] [action] eg: Find / -user xingzhou All files belonging to user xingzhou find / -name xingzhou Searches for the file named xingzhou find / -name Find / -mtime 0 Files modified within 24 hours find / -mtime 3 Files modified within 24 hours on the day 3 days ago find / -mtime -3 Files that have been modified less than or equal to three days find / -mtime +3 Files that have been modified greater than or equal to four days ago Note: The find command is used to search for files directly from disks. Whereis just looks for a specific directory in the system, and local looks from the system database, so these two commands are faster. However, the file storage information database of the system is not updated in real time, so the file results of the local query may not be that accurate.Copy the code
The file system
Summary:
Operating system The file system was invented to manage and use disks. Linux commonly used file systems are ext2, ext3, and ext4, which are indexed file systems. An indexed file system indexes the contents of files stored on disk. The purpose of indexing is, of course, to find the contents of files faster. An indexed file system usually has three types of blocks to hold different data: the superblock, the inode block, and the data block. The superblock stores the properties of the file system, inodes, and information about the total number, usage, and remaining data blocks. Inode: records the properties of a file, and records the data blocks (which can be considered as the index of a file system) where the file content is stored. The details of how blocks are divided vary from filesystem to filesystem, but the principle is the same. Centos7 starts with the XFS file system by default. The XFS file system is a journalised file system. More suitable for some high capacity disk and large file storage. Use: Before using the disk, you need to “mount” the disk. Mounting is to establish the connection between the disk and the directory.
The mounting command is mount
Mount all disks using the /etc/fstab configuration: mount -a
View the current mount information: mount
Mount a directory:
Mount [-t file system] LABEL= "directory mount [-t file system] LABEL=" directory mount [-t file system] LABEL= "directory mount --bind directory 1 directory 2: If directory 1 is mounted to directory 2 instead of the file system, directory 1 and directory 2 are linked to the same inode.Copy the code
Cancel mount:
Umount [-fnl] Device file name/directory f: Forcibly cancel n: unmount the device without updating the /etc/mtab file l: unmount the file system immediatelyCopy the code
Several view commands:
Df [-ahi] [directory/file] a: lists all file systems, including /proc (the directory will be explained later) h: displays in a readable form I: Display the number of inodes, not the disk capacity du [-sham] File/directory s: displays the total number of files and directories. H: displays the capacity of files and directories in the readable capacity. A: lists the capacity of all files and directoriesCopy the code
The /proc directory is a process file system. The contents in the proc directory are stored in memory and do not occupy disks. For details, see
Swap (memory swap)
When we run the free command, we will see a column of Swap, Swap is a special partition, called memory Swap partition, when the system memory is insufficient, can be used as memory. In fact, for the vast majority of Internet server development scenarios, the memory configuration of the machine is often sufficient, and then you can use cGroups to allocate appropriate memory, swap may not be so necessary.
If there is a service scenario, do not pursue speed, as long as the process does not hang slowly can run, this kind of case can set swap.
To check whether the performance is affected after swap is enabled, run the vmstat 2 command to check the si so. The larger the si so value is, the more severe the performance impact is.
conclusion
In fact, about the “Linux directory and disk” need to learn there are many places, here only listed some common knowledge points, need to understand the system, you can learn through the official website, source code, technical books and other ways.