Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the definition and specification of linux under /

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

Today, I would like to share with you the relevant knowledge about the definition and specification of linux. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look.

The file system in Linux and UNIX is a tree file structure with / root, / is the root directory in Linux and UNIX, and it is also the starting point of the file system. All the files and directories are under the / path, including / usr, / etc, / bin, / home, and so on. In the early UNIX system, each manufacturer defined the naming composition of its own file system, which was confusing and difficult to distinguish.

In order to avoid this naming confusion on Linux systems, the Linux file system hierarchy standard of FSSTND (FileSystem Standard) was introduced in 1994. Later, the UNIX team carried forward FSSTND and became the later FHS (FileSystem Hierarchy Standard).

The FHS standard makes many Linux distributions (Linux distributions) have a unified file system naming standard, to put it another way: FHS is a file system naming standard. Generally speaking, Linux distributions needs to follow the rules of FHS

Directory structure and contents

Permissions for file types

However, FHS only defines two layers of specifications. The first layer is what file data should be put in / each directory below, such as settings files under / etc, executable files under / bin and / sbin, etc.; the second layer is defined for / usr and / var directories, such as / usr/share needs to put shared data, / var/log needs to put system login files, and so on.

FHS specification

First, let's introduce the importance and significance of the root directory:

The root directory is the most important directory in the whole system, and the subsequent directories are derived based on the root directory. More importantly, the root directory is related to boot, restore and system repair, because the system boot requires a specific environment, so when there is an error in the system, the root directory must also contain programs that can repair the file system. Therefore, FHS stipulates that the partition size of the root directory should not be set too large, in fact, the smaller the better, to reduce the error rate.

FHS also stipulates that these directories should exist under the root directory.

/ home directory

The / home directory is the default consumer home folder (home directory) for the system.

/ boot directory

The / boot directory contains the static files needed to boot the operating system, such as the Linux kernel, which are critical to booting the system. The common file name for Linux Kernel is vmlinuz, but if you are using the boot program grub2, the / boot/grub2 directory will also exist.

I just finished building the Linux, which looks like this under the boot.

Never delete the / boot directory, which may cause the system to fail to boot.

/ dev directory

The / dev directory is a number of device nodes, which are devices in the Linux system or virtual devices provided by the kernel. These device nodes are also very important for the normal operation of the system. The devices under the / dev directory and subdirectories are character devices and block devices. Character devices are mice, keyboards, modems, and block devices are hard drives and floppy disk drives. Storing files in the / dev directory is equivalent to storing a device.

The more important documents are

/ dev/hda: the primary device on the primary IDE channel. When it comes to IDE/ATA hard drives, the primary channel is the channel where the first and second drives are connected to the motherboard or interface card.

/ dev/hdb: slave device on the master IDE channel.

/ dev/tty0: first virtual console. Virtual console, also known as VC, also known as virtual terminal VT, is a conceptual combination of keyboard and display for computer user interface.

/ dev/tty1: the second virtual console.

/ dev/sda: the first device on the primary SCSI and SATA channel.

/ dev/lp0: first parallel port.

Below is the directory under my Linux.

/ etc directory

The / etc directory is reserved for the local configuration files of the computer, and the main configuration files of the system are placed under this directory, such as account password, service start and stop, generally speaking, the general user under this directory only has read permission, and only root users have the right to modify (on the question of permissions, you can read the author's last article to finish reading this Linux permission, through! )

Several important files under / etc are

/ etc/modprobe.d kernel driver module

/ etc/passwd stores user passwords

/ etc/fstab stores mount information

/ etc/issue storage system boot is what is displayed

Do not store binaries in the / etc directory. Binaries are best placed in / sbin and / bin.

There are two important files in the / etc directory. / etc/x11 is used to store X Window system configuration files, such as xorg.conf,/etc/opt, which is mainly used to store third-party collaboration software / opt.

/ lib directory

There are many function libraries in the system, and the / lib directory is like a repository for the libraries needed to execute the binaries in / bin and / sbin, and these shared library images are particularly important for the system boot and executing commands in the root file system.

/ media directory

Media is the English language of media, which means that mount points and subdirectories for removable media such as USB, DVD, CD-ROM, and Zip disks can be stored under / media.

/ mnt directory

If you want to mount some extra devices temporarily, you can put them in the / mnt directory. In fact, in the earliest days, / mnt is used for the same purpose as / media, but later, with / media, this directory is used for temporary mount.

/ opt directory

The / opt/ directory provides storage space for most application packages, and a package that places files in the / opt/ directory creates a directory with the same name as the package. In turn, the directory holds files that would otherwise be scattered across the file system, providing an easy way for system administrators to determine the role of each file in a particular package.

For example, if sample is the name of a specific package located in the / opt/ directory, then all files are placed in the directory in the / opt/sample/ directory, such as / opt/sample/bin/ for binaries and / opt/sample/man/ for the man pages.

/ proc directory

The / proc directory itself is a virtual file system (virtual filesystem). The data it places is in memory, such as system core information, travel information, network status of peripheral devices, and so on. Because the data in this directory is in memory, it does not take up disk space.

The more important files in this directory are / proc/cpuinfo, / proc/dma, / proc/interrupts, / proc/net/.

/ sbin directory

The / sbin directory stores executables used by root users. The executable in / sbin is used at startup to manage the system and perform system recovery operations. In addition to the binaries in / bin, / sbin contains the binaries needed to start, recover, and repair the system.

The / sbin directory contains arp, clock, halt, init, grub, ifconfig, route, shutdown, etc.

/ tmp directory

Under this directory are temporary files that are erased when the system is restarted.

/ sys directory

This directory is actually very similar to / proc, which is also a virtual file system that records information about the core and system hardware. This directory also does not take up disk space.

/ usr directory

The / usr directory is a directory that needs to be talked about. Many readers mistakenly think that / usr is an acronym for user. In fact, usr is an acronym for Unix Software Resource. FHS suggests that software developers should reasonably place their data in a subdirectory of this directory and not create a software-independent directory.

All system default software will be placed under / usr, so this directory is somewhat similar to the combination of C:\ Windows\ + C:\ Program files\ in Windows. Generally speaking, this directory will take up more disk capacity after the system is installed. The subdirectory of / usr is recommended to have the following contents

* / usr/bin/* all the instructions that ordinary users can use are placed in this directory. Starting with CentOS 7, the instructions under / usr/bin are the same as those under the / bin directory.

* / usr/lib/* basically has the same function as / lib, so / lib is linked to this directory.

/ usr/local system administrator in the local download software is recommended to install to this directory, easy to manage.

/ usr/sbin is not required for the normal operation of the system, the most common is the service instructions of some network server software, but the basic function is similar to / sbin, so currently / sbin is linked to this directory.

/ usr/share shared file placement area, where there are also subdirectories / usr/share/man, / usr/share/doc,/usr/share/zoneinfo

/ usr/games the place where game-related data are placed

The places where header and include are placed in programming languages such as / usr/include Cplink + are also directly linked.

/ usr/src general source code is recommended here. Src means source, while the core source code is recommended under the / usr/src/linux directory.

/ run directory

The early FHS stipulated that the information generated after the system was booted should be placed in the / var/run directory, while the new version of FHS should be standardized under / run.

/ var directory

If / usr is a directory that takes up a large amount of disk capacity during installation, then / var is a directory that gradually consumes disk capacity after the system is running. / var mainly includes cache, login files and directories generated by some software running, including program files, such as MySQL database files, etc. Common directories include

/ var/cache application cache directory

/ var/crash system error message

/ var/log logging

Identity data of / var/run process

/ var/tmp temporary file directory

/ var/lock file lock record

/ srv directory

Srv can be regarded as the abbreviation of service, which is the data directory that these services need to access after some network services are started, such as WWW and FTP.

CentOS 7 is different from previous versions in directory arrangement, which has been roughly described above. Here is a summary. The big difference is that many directories that should have been in the root directory are moved to / usr, and then link settings are made. These contents include

/ bin-> / usr/bin

/ sbin-> / usr/sbin

/ lib-> / usr/lib

/ lib64-> / usr/lib64

/ var/lock-> / run/lock

/ var/run-> / run

In order to make it easier for you to see what these directories do, I drew a picture by hand, and the relationship between these directories is very much like a tree, so this directory is also called a directory tree.

The directory tree is already very clear, so there is nothing more to say.

Absolute path and relative path

Like other systems, paths in Linux are also divided into absolute paths (absolute) and relative paths (relative), which are written according to the following:

All paths starting from the root directory are absolute, such as / boot, / usr/local and so on in the directory tree above.

Relative to the current file path is written as a relative path, such as … / var/log directory

It should be noted here that the relative path is moved by the relative position of your current path, for example, if you are currently in the / boot directory, you want to move to the / usr/src directory

Absolute path representation: / usr/src

Relative path representation:... / usr/src

There are also two special directories to note here:

. Represents the current directory, or you can use. / to indicate

... : represents the upper level of the directory, can also use … / to represent

About the choice between absolute path and relative path: when the file path is very long, it is recommended to use the relative path, because you do not have to write all the paths like the absolute path, but use it directly. / that's fine.

But from the correctness of the file path, the absolute path is better than the relative path.

If you are writing a program to manage the system, be sure to use the absolute path, because the absolute path will find the specified file no matter where your file path is, while the relative path may not find the file after the file is moved.

Directory-related instructions

Next, let's talk about a few instructions related to directories.

Cd

Cd is the abbreviation of change directory. This instruction can switch the current working directory. There are four ways to switch.

Cd / pathname # means to switch to the specified working directory cd. / # means to switch to the current working directory (without any switching) cd.. # means to switch to the upper level directory of the current working directory cd ~ # means to return to the current user directory

Let's demonstrate the operation of these four cd switching modes.

As you can see, we use cd / usr/local to switch to the instruction directory; use cd. / do not change any directory (wasted two seconds); use cd... Switch to one level above the current working directory; use cd ~ to switch to the default working directory of the currently logged-in user.

What needs to be noticed here is cd ~. If you use cd directly, the switching effect is the same as cd ~, that is to say, "cd ~ = cd".

Pwd

There is also an instruction pwd, which is our most commonly used instruction, and it is used almost as often as cd, because a cd instruction is often followed by a pwd instruction, so you can see how important the pwd instruction is.

Pwd is an acronym for Print Working Directory, which is an instruction to print out the current directory.

But pwd is not necessarily only used to display the current working path, it can also be used to display the file path under the specified working directory.

But this instruction doesn't seem to work, because we already know the path in the working directory, so why print it out?

Mkdir

Mkdir is used to create a new directory, which is an acronym for make directory, which is generally followed by two parameters.

-m: set the permissions of the file directly, regardless of the default file creation permissions

-p: recursively create a directory

The following is the operation to create a file directory using mkdir

As shown in the figure above, we created an empty directory called test1 under the / tmp file directory and printed out the current working directory.

If you want to create a directory that you don't want other users to access, you can use the following command

Mkdir-m 711 test2

The ls-ld in the figure above lists the details of the file directory, and you can see that the file permissions are at the top of the details.

Creating directories one by one is too troublesome, and now we want to create these directories quickly, for example, we want to create the directory format / test1/test2/test3/test4, we use the following code

Linux will suggest that we can't use this way of creation.

At this point, we need the appearance of the parameter-p, which allows us to create a directory recursively, as shown below.

It's just that the use of-p is not recommended because it is easy to type wrong words.

Rmdir

Rmdir is used to delete empty directories, and its use is very similar to mkdir. Mkdir-p is used to create directories recursively. Similarly, rmdir-p can also recursively delete directories. As shown in the following figure

It should be noted here that rmdir only deletes an empty directory, which also means that if there is content in the directory, it cannot be deleted, so how to delete it? You can delete it directly using rm-r.

Mv

You can change the name of a directory using mv. For example, we created a directory called test. Later, we felt that this directory could not reflect its owner. If we wanted to change its name, we could change it using the mv instruction.

After understanding the basic directory operations, let's consider the question: why can we display content by executing ls instructions in various directories? Shouldn't ls be used only under its storage path?

First of all, we need to understand the concept of a PATH. PATH is an environment variable. When we execute an instruction, the system will first search for executable files named ls under each PATH according to the settings of PATH. If there are multiple executable files, then the priority search will be executed first.

These are all the contents of the article "what are the definitions and specifications of linux?" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report