Linux File System parsing and related commands, linux parsing related commands
Introduction
A file system is a logical set of all files in a partition or disk.
File SystemIncludeAndFile dataAndStructure of the file systemAll files, directories, soft connections, and file protection information seen by Linux users and programs are stored.
There are few differences in the file system between different Linux releases, mainly because of the different system management tools and software package management methods, the file directory structure is basically the same.
There are multiple types of file systems, such:
- Ext2: common file systems in early linux;
- Ext3: an upgraded version of ext2 with the log function;
- RAMFS: memory file system, fast;
- Iso9660: optical disc or optical disc image;
- NFS: A Network File System invented by SUN. It is mainly used for remote file sharing;
- MS-DOS: MS-DOS file system;
- FAT: The file system used by Windows XP;
- NTFS: The file system used by the Windows NT/XP operating system.
Partitions and directories
The file system is located in the disk partition. One hard disk can have multiple partitions or only one partition. One partition can only contain one file system.
There is a big difference between Linux and Windows. Windows File structure is a parallel tree structure with different disks (partitions) at the top, such as C, D, E, and F.
LinuxThe file structure of isA single tree structure with the root directory "/",Other directories must be in the root directory..
Every time we install the system, we will partition. The relationship between disk partitions and directories in Linux is as follows:
- Any partition must be mapped to a directory to perform read/write operations ".
- The mounted directory can be the root directory or another level-2 or level-3 directory. Any directory can be a mount point.
- Directories are logically differentiated. Partitions are physically differentiated.
- The root directory is where all Linux Files And Directories are located. You need to mount a disk partition.
Is a common ing between directories and partitions:
Why partition and how to partition?
- Different data can be managed in different partitions to reduce risks.
- Large Hard Disk search range, low efficiency.
- /Home,/var,/usr/local are often independent partitions, because operations are often performed and fragments are easily generated.
For ease of locating and searching, each directory in Linux generally stores specific types of files. The following table lists common directories of various Linux Release versions:
| Directory |
Description |
| / |
Root directory, which can only contain directories, but cannot contain specific files. |
| /Bin |
Stores executable files. Many Commands correspond to a program in the/bin directory, such as ls, cp, and mkdir. The/bin directory is valid for all users. |
| /Dev |
Hardware driver. For example, sound card, disk drive, and files such as/dev/null,/dev/console,/dev/zero,/dev/full. |
| /Etc |
It mainly includes system configuration files, user and user group configuration files. |
| /Lib |
It mainly contains shared library files, similar to Windows DLL files; sometimes it also contains kernel-related files. |
| /Boot |
System Startup files, such as Linux kernel and boot program. |
| /Home |
User working directory (main directory), each user will allocate a directory. |
| /Mnt |
Temporarily mount the file system. This directory is generally used to store the Mount directory of the mounted storage device, such as the cdrom directory to mount the CD-ROM. |
| /Proc |
When the operating system is running, the process (Program in progress) information and kernel information (such as cpu, hard disk partition, memory information, etc.) are stored here. The/proc directory is the mounted directory of proc, which is not a real file system. |
| /Tmp |
Temporary File directory, which will not be saved after the system is restarted. |
| /Usr |
Files in the/user directory are mixed, including management commands, shared files, and library files, which can be used by many users. |
| /Var |
It mainly contains variable-length files, which often read and write data, such as log files and files in the print queue. |
| /Sbin |
Similar to/bin, it mainly contains executable files, but generally it is required by system management, not all users need it. |
Common file management commands
You can use the following command to manage files:
| Command |
Description |
| Cat filename |
View the file content. |
| Cd dirname |
Change the directory. |
| Cp file1 file2 |
Copy a file or directory. |
| File filename |
View the file type (binary, text, etc ). |
| Find filename dir |
Search for files or directories. |
| Head filename |
Display the beginning of the file, opposite to the tail command. |
| Less filename |
View all the content of the file, which can be displayed by page, which is more powerful than the more command. |
| Ls dirname |
Traverse files or directories in a directory. |
| Mkdir dirname |
Create a directory. |
| More filename |
View all the content of the file, which can be displayed by page. |
| Mv file1 file2 |
Move or rename a file. |
| Pwd |
Displays the current user directory. |
| Rm filename |
Delete an object. |
| Rmdir dirname |
Delete a directory. |
| Tail filename |
Display the end of the file, opposite to the head command. |
| Touch filename |
Create an empty file when the file does not exist and modify the file timestamp when the file exists. |
| Whereis filename |
View the file location. |
| Which filename |
If the file is defined in the environment variable PATH, the file location is displayed. |
Df command
Disk Partitions are frequently used for management.Df(Disk free) command,Df-k CommandYesUsed to view disk space usage (in kilobytes)For example:
$df -kFilesystem 1K-blocks Used Available Use% Mounted on/dev/vzfs 10485760 7836644 2649116 75% //devices 0 0 0 0% /devices$
The meaning of each column is as follows:
| Column |
Description |
| Filesystem |
The path name of the device file corresponding to the file system (usually the partition on the hard disk ). |
| Kbytes |
The number of data blocks (1024 bytes) contained in a partition. |
| Used |
Used space. |
| Avail |
Available space. |
| Capacity |
Percentage of used space. |
| Mounted on |
File System mount point. |
For some directories (such as/devices), the kbytes, used, and avail columns are 0 and the use column is 0%. These are special (or virtual) file systems, even if they are in the root directory, it does not occupy hard disk space.
You can combine the-h (human readable) option to format the output information, making it easier to read.
Du command
You can run the du (disk usage) commandUsed to view the space usage of a specific directory.
Du commandThe data blocks occupied by each directory are displayed.. Depending on the system, a data block may be 512 bytes or 1024 bytes. Example:
$du /etc10 /etc/cron.d126 /etc/default6 /etc/dfs...$
Combined with the-h option, the information can be displayed more clearly:
$du -h /etc5k /etc/cron.d63k /etc/default3k /etc/dfs...$
Mount a File System
MountYesMaps a hardware device (such as a hard disk, a USB flash drive, or a CD) to an existing Directory.. To access a file in a device, you must mount the file to an existing Directory and access the storage device by accessing the directory.
In this way, a unified interface is provided for users to block the details of hardware devices. Linux regards all hardware devices as files, and operations on hardware devices are equivalent to operations on files.
Note: The Mount directory may not be empty, but the contents in the directory will not be available after mounting.
You need to know that the formats of the file systems used by CD, floppy disk, and other operating systems are different from those used by linux, to mount a file system, check whether Linux supports the format of the file system to be mounted.
To view the hardware devices mounted to the current system, run the mount command:
$ mount/dev/vzfs on / type reiserfs (rw,usrquota,grpquota)proc on /proc type proc (rw,nodiratime)devpts on /dev/pts type devpts (rw)$
Generally,/mnt is a temporary Mount directory, such as attaching a CD-ROM, a remote network device, or a floppy disk.
You can also useMount command to mount the File System, Syntax:
mount -t file_system_type device_to_mount directory_to_mount_to
For example:
$ mount -t iso9660 /dev/cdrom /mnt/cdrom
Mount the CD-ROM to the/mnt/cdrom directory.
Note: file_system_type is used to specify the file system type, which can be left unspecified. in Linux, the file system type is automatically and correctly selected.
After mounting the file system, you can use commands such as cd and cat to operate the corresponding file.
You can useUmount command to uninstall the File System. For example, uninstall cdrom:
$ umount /dev/cdrom
However, most modern Linux systems have the automatic Mount/unmount function, and the unmount command is rarely used.
User and group quota
Quota of users and groups allows administrators to allocate a fixed disk space for each user or group.
The administrator can allocate disk space in two ways:
- Soft limit: if the user exceeds the specified space, there will be a grace period, waiting for the user to release the space.
- Hard limit: no grace period exists. operations are immediately prohibited if the specified space is exceeded.
The following command can be used to manage a quota:
| Command |
Description |
| Quota |
Displays disk usage and quota of each user group. |
| Edquota |
Edit the quota of users and groups. |
| Quotacheck |
View the disk usage of the file system, and create, check, and repair the quota file. |
| Setquota |
Set the quota. |
| Quotaon |
Enable the user or group quota function. |
| Quotaoff |
Disable the user or group quota function. |
| Repquota |
Print the quota of the specified file system. |
Thank you! Thank you for your patience!