Linux operating system - system and file

Linux operating system learning

1, Linux system

Linux system startup process

Kernel boot:
When the computer is powered on, the first is BIOS power on self-test, which starts according to the boot device (usually hard disk) set in BIOS.
After the operating system takes over the hardware, first read the kernel file in the / boot directory.

Run init:
Init process is the starting point of all processes in the system. You can compare it to the ancestor of all processes in the system. Without this process, no process in the system will start. The init program first needs to read the configuration file / etc/inittab.

Operation level:
Many programs need to be started. They are called "service s" in Windows and "daemon s" in Linux.
A major task of init process is to run these boot programs. However, different programs need to be started in different situations. For example, Apache needs to be started when it is used as a server, but not when it is used as a desktop. Linux allows different boot programs to be allocated for different occasions, which is called "runlevel". That is, at startup, determine which programs to run according to the "run level".

System initialization:
There is a line in the init configuration file: Si:: sysinit: / etc / RC d/rc.sysinit, which calls and executes / etc / RC d/rc.sysinit, while RC Sysinit is a bash shell script, which mainly completes some system initialization

Establish terminal:
After rc is executed, init is returned. At this time, the basic system environment has been set up and various daemons have been started.
init will then open six terminals so that users can log in to the system.

1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6

User login system:
Generally speaking, there are three login methods for users:
(1) Command line login
(2) ssh login
(3) Graphical interface login

Linux shutdown:
The correct shutdown process is: sync > shutdown > reboot > halt
Shutdown command: shutdown

sync Synchronize data from memory to hard disk.

shutdown Shutdown command, you can run the following command to shutdown:

shutdown –h 10 'This server will shutdown after 10 mins' This command tells you that the computer will shut down in 10 minutes and will be displayed on the current screen of the logged in user.

shutdown –h now Turn it off immediately

shutdown –h 20:25 The system will be 20 today:25 Shut down

shutdown –h +10 Turn it off in ten minutes

shutdown –r now The system restarts immediately

shutdown –r +10 The system will restart in ten minutes

reboot Is to restart, which is equivalent to shutdown –r now

halt Shut down the system, equivalent to shutdown –h now and poweroff

Whether you restart or shut down the system, first run the sync command to write the data in memory to disk.

2, Linux system directory structure

//crtl+shift+T: Open command line window
ls /    //View file directory structure

/bin: 
bin yes Binaries (Binary file) Abbreviation of, This directory holds the most frequently used commands.

/boot: 
What is stored here is startup Linux Some core files used in, including some connection files and image files.

/dev : 
dev yes Device(equipment) Abbreviation of, Stored in this directory is Linux External equipment, in Linux You access devices in the same way as you access files.

/etc: 
etc yes Etcetera(wait) Abbreviation of,This directory is used to store all configuration files and subdirectories required for system management.

/home: 
User's home directory, in Linux In, each user has its own directory. Generally, the directory name is named after the user's account, as shown in the figure above alice,bob and eve. 

/lib: 
lib yes Library(library) The directory stores the most basic dynamic connection shared library of the system, which is similar to Windows Inside DLL File. Almost all applications need these shared libraries.

/lost+found: 
This directory is generally empty. When the system shuts down illegally, some files are stored here.

/media: 
linux The system will automatically identify some devices, such as U Disk, optical drive, etc. when identified, Linux The identified device will be attached to this directory.

/mnt: 
The system provides this directory to allow users to temporarily mount other file systems. We can mount the optical drive in /mnt/ On the CD-ROM drive, and then enter the directory to view the contents of the CD-ROM drive.

/opt: 
opt yes optional(Optional) This is the directory where additional software is installed for the host. For example, you install one ORACLE The database can be placed in this directory. The default is empty.

/proc: 
proc yes Processes(process) Abbreviations for,/proc It is a pseudo file system (i.e. virtual file system), which stores a series of special files of the current kernel running state. This directory is a virtual directory, which is the mapping of system memory. We can access this directory directly to obtain system information.
The contents of this directory are not on the hard disk but in the memory. We can also directly modify some files in it. For example, we can mask the host through the following command ping Command, make others unable to ping Your machine: echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all

/root: 
This directory is the user home directory of the system administrator, also known as the super authority.

/sbin: 
s namely Super User I mean Superuser Binaries (Super user binary) Here is the system management program used by the system administrator.

/selinux: 
 This directory is Redhat/CentOS Unique directory, Selinux Is a security mechanism, similar to windows Firewall, but this mechanism is complex. This directory is used to store selinux Relevant documents.

/srv: 
 This directory stores some data to be extracted after the service is started.

/sys: 

This is Linux2.6 A big change in the kernel. 2 is installed in this directory.6 A new file system in the kernel sysfs . 

sysfs The file system integrates the following three kinds of file system information: for process information proc File system, device specific devfs File system and for pseudo terminal devpts File system.

The file system is an intuitive reflection of the kernel device tree.

When a kernel object is created, the corresponding files and directories are also created in the kernel object subsystem.

/tmp: 
tmp yes temporary(temporary) This directory is used to store some temporary files.

/usr: 
 usr yes unix shared resources(shared resource) This is a very important directory. Many applications and files of users are placed in this directory, similar to windows Lower program files catalogue

/usr/bin: 
Applications used by system users.

/usr/sbin: 
Super users use more advanced management programs and system daemons.

/usr/src: 
The default placement directory of kernel source code.

/var: 
var yes variable(variable) In this directory, there are constantly expanding things. We are used to putting those directories that are often modified under this directory. Including various log files.

/run: 
Is a temporary file system that stores information since the system was started. When the system restarts, the files in this directory should be deleted or cleared. If you have on your system /var/run Directory, it should point to run. 

In the Linux system, there are several directories that are important. You should pay attention not to delete or change the internal files at will.
/etc: as mentioned above, this is the configuration file in the system. If you change a file in this directory, the system may not start.

/bin, /sbin, /usr/bin, /usr/sbin: This is the default directory where the execution files are placed. For example, ls is in the / bin/ls directory. It is worth mentioning that / bin, /usr/bin are the instructions for system users (except for users other than root), while / sbin, /usr/sbin are the instructions for root.

/Var: This is a very important directory. There are many programs running on the system, so each program will have a corresponding log, and these logs will be recorded in this directory, specifically in the / var/log directory

3, Basic properties of Linux file

Linux system is a typical multi-user system. Different users are in different positions and have different permissions.
In order to protect the security of the system, the Linux system makes different provisions for different users to access the same file (including directory file).
In Linux, we usually use the following two commands to modify the users and permissions of files or directories:

chown (change owner) :  Modify the user and group to which you belong.
chmod (change mode) :  Modify the user's permissions.

Authorize the user through chown, and set the permission to open the door for the user through chmod
In Linux, we can use the ll or ls – l command to display the attributes of a file and the users and groups to which the file belongs

Bit 0 determines the file type, and bits 1-3 determine that the owner (the owner of the file) has the permission of the file.
Bits 1, 4 and 7 indicate read permission. If r character is used, there is read permission; if - character is used, there is no read permission;
Bits 2, 5 and 8 indicate write permission. If w character is used, there is write permission; if - character is used, there is no write permission; Bits 3, 6 and 9 indicate the executable permission. If it is represented by x character, it has the execution permission; if it is represented by - character, it has no execution permission.

For the root user, in general, the permission of the file does not work on it.

change file properties

1. chgrp: change the file group

chgrp [-R] Group name file name

-R: Recursively changing the file group means that when changing the group of a directory file, if the - R parameter is added, the group of all files in the directory will be changed.
2. chown: change the file owner or the file group at the same time

chown [–R] Owner name file name
chown [-R] Owner name: the name of the owner group and the file name

Enter the / root directory (~) to install The owner of log is changed to bin account:

Install Change the owner and group of log back to root:

chmod: change 9 attributes of the file

There are two ways to set Linux file attributes, one is number and the other is symbol. There are nine basic permissions for Linux files, namely owner / group / others. Each of the three identities has its own read/write/execute permissions.
The permission character of the file is: - rwxrwxrwx, the nine permissions are grouped in three! Among them, we can use numbers to represent each authority

r:4
w:2
x:1
The scores of three permissions (r/w/x) of each identity (owner/group/others) need to be accumulated
owner = rwx = 4+2+1 = 7
group = rwx = 4+2+1 = 7
others= — = 0+0+0 = 0

The syntax of chmod is as follows:

 chmod [-R] xyz File or directory

xyz: refers to the permission attribute of numeric type just mentioned, which is the sum of rwx attribute values.
-R: make recursive continuous changes, that is, all files in the secondary directory will be changed

If you want to If all permissions of bashrc file are set and enabled, the command is as follows:

The 777 is also commonly used to lock and unlock files

Symbol type changes file permissions

User: user
group: group
Others: others
We can use U, G and O to represent the permissions of three identities.

a stands for all, that is, all identities. Read and write permissions can be written as r, w, x

4, Linux file and directory management

Absolute path:
The path is written from the root directory /, such as: / usr/share/doc.

Relative path:
The path is not written from /. For example, when / usr/share/doc wants to go under / usr/share/man, it can be written as: cd... / man. This is the writing method of relative path.

ls(English spelling: list files): List directory and file name
cd(English spelling: change directory): Switch directory
pwd(English spelling: print work directory): Show current directory
mkdir(English spelling: make directory): Create a new directory
rmdir(English spelling: remove directory): Delete an empty directory
cp(English spelling: copy file): Copy files or directories
rm(English spelling: remove): Delete file or directory
mv(English spelling: move file): Move files and directories, or modify the names of files and directories

ls (list directory)

-a: All files are listed together with hidden files (files starting with). Commonly used)
-d: List only the directory itself, not the file data in the directory (common)
-l: Long data string listing, including file attributes, permissions and other data; (common)

cd (switch directory)


cd... Return to the previous directory

cp (copy file or directory)
cp is to copy files and directories.

cp [-adfilprsu] Source file(source) Target file(destination)

Options and parameters:

-a: Equivalent to - pdr. For pdr, please refer to the following instructions; (common)

-d: If the source file is a link file attribute, copy the link file attribute instead of the file itself;

-f: To force, if the target file already exists and cannot be opened, remove it and try again;

-i: If the destination file already exists, you will first ask about the progress of the action (commonly used) when overwriting

-l: Create a hard link link link file instead of copying the file itself;

-p: Copy it together with the attributes of the file instead of using the default attributes (commonly used for backup);

-r: Recursive continuous replication is used for directory replication behavior; (common)

-s: Copy it into a symbolic link, that is, a "shortcut" file;

-u: If destination is older than source, upgrade destination!

Use the root identity to transfer the files under the root directory Copy bashrc to / tmp and name it bashrc

mv (move files and directories, or change names)
Syntax:

mv [-fiu] source destination
mv [options] source1 source2 source3 .... directory

-f: force means that if the target file already exists, it will not be queried but directly overwritten;
-i: If the destination file already exists, you will be asked whether to overwrite it!
-u: Update (if the target file already exists, it will be upgraded)
Copy a file, create a directory, and move the file to the directory

5, User and user group management

To add a new user account, use the useradd command. The syntax is as follows:

useradd Option user name

Options:
-c comment specifies an annotative description.
-d directory specifies the user's home directory. If this directory does not exist, you can create a home directory by using the - m option at the same time.
-g user group specifies the user group to which the user belongs.
-G user group, which specifies the additional group to which the user belongs.
-The s Shell file specifies the login Shell of the user.
-u user number specifies the user number of the user. If the - o option is also available, the identification numbers of other users can be reused

user name:
Specify the login name of the new account.

Delete account:

userdel Option user name

The common option is - R, which is used to delete the user's home directory. userdel -r sam

Modify account number:

usermod Option user name

summary

The Linux instruction should be used and reviewed frequently

Keywords: Linux Operation & Maintenance server

Added by river001 on Thu, 10 Feb 2022 17:21:13 +0200