Linux (medium)

Source: Internet
Author: User

Today is the first day after my resignation. I wanted to write my work summary, but there are still many things that need to be organized and learned. This is my second anxiety and confusion after graduation. Hope I can find a job early!

Now, there are a lot of things to learn about Linux. It's not that I can write three blog posts in the previous, middle, and next sections. However, I will not change the question after I get an "up" question. This article is set to "medium! If you write "Next", you may get "Next" and "Next second. ^_^, Maybe, I will not be able to write this, haha! After all, it's just a blog, and no one has an appointment, so it's quite casual. Comments should count as my greatest motivation!

 

Alias usage

In the previous section, when viewing the files in the current directory, I spoke of a ll command and said in the reply on the first floor that he is Ls-lCommand alias, not all Linux have. Alias. As the name implies, two different names refer to one person, and two different commands have the same effect. Now, you must want to know the aliases in your system. [Root @ localhost ~] # AliasAlias in the query system Alias CP = 'cp-I' Alias L. = 'LS-D. * -- color = tty' Alias LL = 'LS-l -- color = tty' Alias ls = 'ls -- color = tty' Alias mv = 'mv-I' Alias Rm = 'rm-I' Alias Vi = 'vim' Alias which = 'Alias |/usr/bin/which -- tty-only -- read-alias -- show-dot -- show-tilde' How to define an alias? If I use copy in DOS instead of CP, I can define a copy alias for CP. [Root @ localhost ~] # Alias copy = CP assigns the CP command function to copy [Root @ localhost ~] # Alias DRM = "RM-RF" defines a DRM alias using the "RM-RF" command. [Root @ localhost ~] # Unalias copy cancelling aliases Vim/VI Editor This part should be important. There are many things about VI, and it seems that there have been several books dedicated to VI. Some cool people use this editorProgramSuper fast. For most of us, it's okay to use it. Vim/VI is a powerful screen text editor, the most common text editor on Linux and Unix. It is used to create, edit, and display text files.

Vim/VI has no menu and only commands.

For ease of operation, we copy a file with content for operation. [Root @ localhost test] # copy the/etc/Services. Test file to the current directory. Vim is an enhanced version of vi. When many users prefer to use VI to edit files [Root @ localhost test] # Vim services. Test
Three Modes of VI:

Conversion of three modes: Command modeEnter a, I, O Insert mode Insert modePress ESC to enter Command mode
Command modeEnter: (colon) Edit mode Edit modeCommand Errors are returned. Command mode
Do you think it is a bit difficult? In fact, we only need to remember that after Vi enters the file, you can press the I key to edit the file. After editing, Press ESC to exit the editing mode. Three exit steps are required. : Q indicates exit (when the file is not changed) : Q! Do not save and exit (when the file changes) : WQ save and exit Specific Vim/VI operations
Understanding the following commands helps us quickly edit and use vi
Command mode: The command mode mainly uses the arrow keys to move the cursor position for text editing. The following lists common operation commands and their meanings. The top, bottom, left, right-click, and H, J, K, and l keys move the cursor. $ ------------ Move to the end of the row 0 (zero) ----- move to the beginning of the line H ---------- move to the top of the screen M ---------- move to the center of the screen L ---------- move to the lower end of the screen Gg --------- to the first line of the file G ---------- to the end of the file Pagedn ----- move one page down Pageup ----- move one page up D + direction key ----- delete text Dd ----- Delete the entire row PP ----- full-row Replication R ----- modify the character of the cursor S ----- Delete the column where the cursor is located and enter the input mode Insert mode:
You can run the following command to switch from "command mode" to "insert mode" A ------------ add text after the logo A ------------ add text at the end of the line I ------------- insert text before the cursor I ------------- start inserting text in this row O ------------ Insert a new line under the cursor O ----------- Insert a new line on the cursor ESC-------- Exit "insert mode" Edit mode:
 
The editing mode provides some auxiliary functions for text editing, such as string SEARCH, replacement, and file storage.
: Q ----- end the VI program. If the file has been modified, save the file first.
: Q! ----- Force exit the VI Program : WQ ----- Save the modification and exit the program
: Set nu ----- make the line number appear before each line of text
: Set Nonu ------ cancel the row number before each row : N ------------ to line N

Analysis of Linux boot process
This part belongs to theoretical knowledge. If you are interested, please take a look at it with me. The Linux boot process is what the startup sequence is like and what services Linux has started for us.
System guiding process:

    1. BiOS self-check
    2. Start grub/lilo
    3. Load the kernel
    4. Execute the INIT process
    5. Initialize through the/etc/inittab File
BiOS self-check After the computer is powered on, the BIOS first conducts self-check, that is, the so-called post (power on selftest ), then, read the boot block from the hard disk, floppy disk, or CDROM according to the boot sequence set in the BIOS ". In PC, boot Linux starts from the BIOS address 0xffff0. The first step of BIOS is power-on self-check (post ). Post checks the hardware. The second step of BIOS is to enumerate and initialize the local device. Given the different usage of BIOS functions, BIOS consists of two parts: PostCodeAnd runtime services. After the post is completed, it is cleared from the memory, but the service is still kept in the memory during the BIOS runtime, which can be used by the target operating system. To Boot an operating system, the BIOS searches active and bootable devices in the order defined by the CMOS settings during runtime. The boot device can be a floppy disk, a CD-Rom, a partition on the hard disk, a device on the network, or even a USB flash memory. Generally, Linux boot is from the hard disk. The primary Boot Record (MBR) contains the primary boot loader. MBR is a 512-byte sector located in the first sector of the disk (0-way, 0-way, 1-sector ). When the MBR is loaded into RAM, the BIOS will hand over the control to the MBR. Extract MBR Information To view the MBR content, run the following command: # Dd If =/dev/hda of = MBR. Bin BS = 512 COUNT = 1 # OD-Xa MBR. Bin This dd Command needs to be run as the root user. It reads the content of the first 512 bytes from/dev/hda (the first IDE disk) and writes it to MBR. BIN file. The OD command prints the contents of the binary file in hexadecimal format and ASCII format. Start grub/lilo Grub and lilo are both boot loaders. In the simplest way, the boot loader will guide the operating system. When the machine directs its operating system, the BIOS reads the first 512 bytes (known as the Master Boot Record (MBR) on the boot media )). In a single MBR, only one operating system boot record can be stored. Therefore, when multiple operating systems are required, problems may occur. Therefore, more flexible boot loader is required. Comparison between grub and Lilo As described at the beginning of this article, all boot loaders work in a similar way to achieve a common purpose. However, there are many differences between Lilo and GRUB: * Lilo does not have an interactive command interface, but grub does. * Lilo does not support network boot, but grub does. * Lilo physically stores information about the operating system locations that can be booted in MBR. If you have modified the Lilo configuration file, you must rewrite the first-stage boot loader of lilo to MBR. Compared with grub, this is a more dangerous option, because wrong configuration of MBR may make the system unable to boot. If grub is used, if the configuration file is incorrectly configured, it is only forwarded to the grub command line interface by default. Security tips: For security, anyone who can access the boot disk/CD can bypass all the security measures mentioned in this article by using grub. conf or Lilo. conf without security settings. Especially when grub is used, it is a serious security vulnerability because it can be guided to the single-user mode. One easy way to solve this problem is to disable boot through CD and floppy disk in the BIOS of the machine, and ensure that a password is set for the bios so that others cannot modify these settings. Load the kernel After the kernel image is loaded into the memory, the kernel stage begins. The kernel image is not an executable kernel, but a compressed kernel image. Generally, it is a zimage (compressed image, smaller than KB) or a bzimage (larger compressed image, larger than KB). It is compressed using zlib in advance. In front of this kernel image is a routine that implements a small amount of hardware settings, decompress the kernel contained in the kernel image, and then put it into the high-end memory, if an initial RAM disk image exists, it will be moved to the memory and marked for future use. The routine then calls the kernel and starts the kernel boot process. Manual guidance in grub In the grub command line, we can use the initrd image to boot a specific kernel. The method is as follows: [Root @ localhost hzh] # vi/etc/grub. conf view the configuration file of grub. conf Grub> kernel/bzImage-2.6.14.2 [Linux-bzimage, set = 0x1400, size = 0x29672e] Grub> initrd/initrd-2.6.14.2.img [Linux-initrd @ 0x5f13000, 0xcc199 bytes] Grub> boot Uncompressing Linux... OK, booting the kernel. If you do not know the name of the kernel to boot, you only need to use the slash (/) and press the tab key. Grub displays the list of kernel and initrd images. Execute the INIT process The INIT process is the starting point of all processes in the system. After the kernel completes the kernel boot, it loads the INIT program in the current thread (process) space. Its Process number is 1. The INIT process is the initiator and controller of all processes. In any UNIX-based system (such as Linux), The INIT process ID (PID) is always 1. If there is a problem with init, the rest of the system will collapse. The INIT process has two functions. The first role is to play the role of ending the parent process. Because the INIT process will never be terminated, the system can always be sure of its existence and take it as a reference when necessary. If a process is terminated before the end of all its child processes, the init must be used as a reference. At this time, all child processes that have lost their parent processes will use init as their parent processes. Run the PS-AF command to list the processes whose parent process ID (ppid) is 1. The second role of init is to run the corresponding program when entering a specific runlevel to manage various running levels. This function is defined by the/etc/inittab file. Initialize through the/etc/inittab File Init performs system initialization Based on the/etc/inittab script, such as setting the keyboard, Font, loading module, and network. For redhatlinux, the execution sequence is:
 
/Etc/rc. d/rc. sysinit # The first script executed by init
/Etc/rc. d/rc. sysinit mainly performs the same initialization in each running mode, including:
Set the initial $ PATH variable.
Configure the network.
Enable swap for the virtual memory.
Set the Host Name of the system.
Check the root file system for necessary repairs.
Check the quota of the root file system.
Quota of users and groups opened for the root file system.
Reload the root file system in read/write mode.
Clear the mounted file system table/etc/mtab.
Input the root file system to mtab.
Prepare the system for Loading modules.
Find related files of the module.
Check the file system for necessary repairs.
Load all other file systems.
Clear several/etc files:/etc/mtab,/etc/fastboot, and/etc/nologin.
Delete the lock file of uucp.
Delete outdated subsystem files.
Delete an obsolete PID file.
Set the system clock.
Enable switch.
Initialize the serial port.
Load the module.
/Etc/rc. d/rcX. d/[Ks]
Terminate the service starting with "K" and start the service starting with "S. For each running level, there is a corresponding sub-directory in the/etc/rc. d sub-directory. The sub-directories at the running level are named as rcX. D. X indicates the number at the running level. For example, all the Command Script programs of running level 3 are saved in the/etc/rc. d/rc3.d subdirectory. In the sub-directories of each running level, the/etc/rc is created. d/init. d sub-directory command script program symbolic links, however, these symbolic links do not use the command script program in/etc/rc. d/init. the original name in the D sub-directory. If the command script program is used to start a service, its symbolic link name starts with the letter S. If the command script program is used to close a service, the name of the symbolic link starts with K. In many cases, the execution sequence of these script programs is very important. If you do not configure the network interface first, you cannot use DNS to resolve the host name! In order to arrange their execution sequence, a two-digit character is followed by the letter S or K, and a small value is followed by a large value. For example,/etc/rc. d/rc3.d/s50inet will be executed before/etc/rc. d/rc3.d/s55named. Stored in/etc/rc. d/init. the Command Script programs in the D sub-directory and on the symbolic link are real practitioners who have completed the operations to start or stop various services. When/etc/rc. d/RC runs through each specific sub-directory of the running level, it calls each command script program for execution in order of numbers. It first runs the command script program with the letter K headers, and then runs the command script program with the letter S headers. The stop parameter is passed for the command script program that starts with letters K. Similarly, the start parameter is passed for the command script program that starts with letters S. Run/etc/EC. d/rc. Local In RedHat Linux, the Operating Modes 2, 3, and 5 all set/etc/rc. d/RC. local is the last in the initialization script, so you can add some commands that need to be executed before logging on to this file. In the days when the Linux system is maintained, the system administrator must modify the script for starting or shutting down the system. If the modification takes effect only when boot is started, and the modification is not significant, you can simply edit the/etc/rc. d/rc. Local script. This command script program is executed at the last step of the boot process. Run the/bin/login program The login program will prompt the user to enter the account and password, then encode and confirm the correctness of the password. If the two are the same, initialize the environment for the user and give control to shell, wait for the user to log on. The Linux Startup Process ends many times. Modify the hardware and software time of the Local Machine For beginners, it is not particularly important to modify the system's hardware and software time. The software (system time) Time is well modified, and the hardware (CMOs time) Time does not know how to modify it. If you are not interested, you can ignore it.

[Root @ localhost hzh] # Date: view the Software Clock of the Local Machine [Root @ localhost hzh] # hwclock [Root @ localhost hzh] # hwclock -- Help -- Set set the RTC to the time given with -- Date -- Hctosys set the system time from the hardware clock -- Systohc set the hardware clock to the current system time
If there is a time error, we can use the above command to modify it. [Root @ localhost hzh] # hwclock -- hctosys sets the system time to correspond to the hardware time. [Root @ localhost hzh] # hwclock -- systohc sets the hardware time to correspond to the system time.
If both times are incorrect, we can set the time by ourselves. [Root @ localhost hzh] # hwclock -- set -- Data = "month/day/year hour: minute: second"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.