Learning operating system practice - Linux operating system from entry to improvement
Linux operating system introduction:
2. Linux operating system Linux system learning is a clear line, and the content is progressive, including:
(1) Basic use of Linux system (from the perspective of ordinary users)
(2) Application and system programming (from the perspective of developers) )
(3) Kernel and Application (Kernel Developer's Perspective)
(4) Service Management (Network Manager's Perspective) The operating system principle is understood as a dark line, and the content echoes the operating system theory course, including:
(1) The understanding and use of the operating system
(2) The core functional modules of the operating system (programming of processes, memory, communication, files, etc.)
(3) The structure and operating mechanism of the operating system
Linux operating system： Chapter 1 Getting to Know the Linux System
1. Linux is a set of free-to-use and freely disseminated UNIX-like operating systems. It is a multi-user, multi-tasking, multi-threading, and multi-CPU operating system based on POSIX and NIX.
2. Linux inherits the design idea of UXIX with the network as the core and is a multi-user network operating system with stable performance.
3. The logo is a cute penguin
4. GNU Project: Linux is only a kernel of the operating system, without the GNU software environment (such as bash, shell ), Linux will be difficult to do
5. Openness: Linux follows the world standard specifications, especially the Open System Interconnection (OSI) international standard. All hardware and software developed in accordance with the OSI international standard are compatible with each other and can be easily interconnected.
6. Multi-user, multi-task: the computer executes multiple programs at the same time, and each program runs independently of the other
7. Linux system generally has 4 main parts: kernel, shell, file system, and applications
8.Shell: It is the user interface of the system, which provides an excuse for users to interact with the kernel. The shell accepts commands entered by the user and sends them to the kernel for execution. is a command interpreter that can also be used as a programming language.
9. http://www.kernel.org Download the latest version of the Linux kernel stable
10. An operating system with only a kernel and no application software cannot be used, so many companies have developed a graphical interface based on the Linux kernel, coupled with much more powerful application software.
11. Linux operating system： An operating system kernel plus a graphical interface plus application software, such a complete software environment is collectively referred to as a release version.
12. Linux kernel + various free software = complete operating system
13. Virtual Machine (Virtual Machine) refers to a complete computer system VMware Workstations (VMware) that is simulated by software and has complete hardware system functions and runs in a completely isolated environment.
14. Linux operating system： The installation location is an important step in the installation process. The hard disk partition on the virtual machine uses part of the hard disk space to simulate the physical machine. You can choose "Automatically configure partition", and the installation program will automatically allocate disk space and SWAP space according to the size of the disk and memory, and create appropriate partitions. Boot partition, a swap partition, the root partition
15. The boot process of Linux operating system is generally divided into four stages: BIOS boot boot stage, GRUB boot boot stage, kernel stage and No. 1 user process initialization stage. (Before CentOS7, the user process No. 1 was called the init process, and after CentOS7, it was called the systemed process)
process initialization: The systemd process is the first process running on a Linux system (PID is 1), it comforts the system and starts all services that the init ( /etc/init.d ) process has ever started, reads the configuration file that loads the operating system in the target runlevel.target .
Note: By default, there are two main targets, namely multi-user.target (character interface) and graphical.target (graphical interface)
17. Terminal under GUI .
18. Ctrl + C , terminal command
exit or Ctrl+D, exit
reboot, reboot the system
shutdown shut down the system
19.[ root@localhost ~]# Prompt # stands for super user (administrator)
[ user@localhost ~]$ Prompt $ represents normal user
20. Generally installed through yum or rpm package management. RPM is an open package management system that can run on Linux systems that use rmp packages, and can install, uninstall, update and upgrade software; yum installation can automatically check the dependencies between software packages and install them at one time All dependent packages, but yum installation requires more reliable repositories.
21.yum clean all, clear the cache list
22. The default root filesystem is read-only only in single-user mode
23. "Virtual machine snapshot" is a timely copy of the virtual machine disk file (VMDK) at a certain point, saving the data state of the virtual machine at the current point
Chapter 2 Shell Commands
1.Shell is a special program of Linux, which is the interface between the kernel and the user. It is the sum of the command language, command interpreter and programming language. Shell is a command language interpreter, it has its own built-in Shell command set, and can also be called by other applications in the system. When the user successfully logs in to the Linux system, the dialogue and interaction process with the Shell starts. At this time, whenever a command is typed, it will be interpreted and executed by the Shell.
2. The tree-shaped directory structure is adopted, and all the files in the system are hierarchically organized by the directory, starting from the root directory, all directories are derived from the root directory, and the Linux system regards the device as a device. Files, devices and files are processed using a unified interface. The top layer of the tree structure is the root directory, which is represented by "/"
3./lib , the library directory, which stores system and application library files
/ mnt , mounted on a directory, another common mount point for removable media devices
/ etc , the system configuration file directory
/ usr , the user binary directory, where a large number of user-level GNU tools and data files are stored
4. Common directory operations include directory creation, deletion, entry, switching, and viewing the current directory
pwd shows the absolute path of the current working directory
mkdir create directory -p creates a nested multi-level directory structure
cd change working directory path
ls list directory and file information -d file attributes -F display file type
rmdir removes empty directories
5. Absolute path: refers to the path from the root directory (/) to the current directory (file)
Relative path: refers to the path from the current directory to its subdirectories (files)
. represents the current directory
…represents the directory one level above the current directory location
Represents the home directory ( home.directory ), which is the directory where you log in
7.ls -la displays detailed information about all files and subdirectories in the current directory, including hidden files
8. r is readable, w is writable, and x is executable
9.touch to create empty file, change file time
cp copies files and directories
mv file and directory rename, move file and directory path
10.rm -rf *.* means forcibly delete many files in the current directory. Use administrator rights with caution. All files recorded in the root directory and their related directories will be deleted.
11.find is used to find a file or directory
The switch command is mainly used to search the location of binary files, executable files or shell command lines
cat display text file, link file content
12. When viewing a large file, use the more command. Use Ctrl+f (or space bar) to display one screen down; Ctrl+b up...
13. The link file command is the ln command, which creates a link between files. This operation is actually to give a file already in the system another name that can be used for access
14. The linked object can be a file or a directory. A hard link is created by default without parameters, and a directory cannot create a hard link; -s creates a soft link (symbolic link)
15. Delete hard links: The content of the file actually still exists, but it points to the past through the hard link file
Delete soft link: The symbolic link file still exists, but since the source file has been deleted, the content of the linked file cannot be viewed. Soft links are similar to shortcuts
16.tar, also known as a packaging tool, can compress and decompress files
tar usually means to use the tar command to pack data but not compress it
tar.gz means to use the tar command to pack the file and compress it with gzip
17. In Linux systems, three standard files are usually automatically opened when executing a Shell command: standard input file (stdin)/standard output file ( stdout ) and standard error output file (stderr)
18. The symbol for input redirection is "<", and the general command format is "command < file name"
Input redirection refers to outputting the execution result of a command to a specified file instead of directly displaying it on the screen
19. ① When the Shell encounters the ">" operator, it will judge whether the file on the right exists. If it exists, it will be deleted first, and a new file will be created; if it does not exist, it will be created directly. Regardless of whether the command on the left is executed or not, the file on the right will become empty.
②">>" operator, judge the file on the right, if it does not exist, create it first, and open the file by adding
20. Pipeline operation:
There are two ways to use the output of a program or command as the input of another program or command, one is to combine the two commands or programs through a temporary file; the other is the pipeline function provided by Linux. This method is better than the previous method.
A pipe can connect a series of commands, which means that the output of the first command is piped to the second command as the input of the second command, and the output of the second command is used as the input of the third command. , and so on.
21.more split screen command
22. In the Linux operating system, users are divided into roles. Different roles have different user rights and completed tasks. User roles are identified by UID (User ID), each user has a different UID. Linux user types are divided into 3 categories: super users, ordinary users and system users
Super user: also known as root user, UID is 0, has the highest authority of the computer system. All system settings and modifications can only be performed by superusers
23. User account file / etc /passwd
GID: Indicates the group to which the user belongs
User password file / etc /shadow, which only superusers have permission to read
24. Group Accounts: Basic Group (Private Group, Primary Group) Additional Groups (Public Group, Secondary Group)
25. The most commonly used configuration file in group accounts is / etc /group, which is used to save the basic information of group accounts and can display which group or groups the user belongs to
Add an ordinary user to the root group, then the user can browse the files in the root user's home directory; if the root user releases the read, write and execute permissions of a file, all users in the root group can modify the file.
26.useradd add user
userdel delete user
usermod modify user account
groupadd add user group
passwd set user password
27.su and sudo : There are generally two ways to change the identity: (1) Use su to directly change the identity to root, but this command requires the password of root, and the general user needs the password of the root administrator, which can be changed from ordinary user to management Member user (2) When multiple people manage a host at the same time, for the confidentiality of the root password, the sudo command can be used to switch user identities
28. When root executes sudo , no password is required
The user can temporarily obtain partial authority of root by entering his own password through the sudo command, so he does not need to know the password of root to ensure the security of the system.
By default, ordinary users cannot use sudo and need to compile the configuration file / etc / sudoers . Use visudo to compile / etc / sudoers , where visudo needs to be executed as root
29. After using the visudo command, the / etc / sudoers configuration file was opened through vi . Add a line "user ALL=(ALL)ALL" to the configuration file, so that the user user can use the sudo command, after adding, save and exit, visudo will automatically check the syntax inside / etc / sudoers to avoid user input of wrong information
30. What kind of authority a user has on a file needs to be decided jointly by the access authority and the attribution (ownership).
chmod set basic permissions
u, g, o, and a represent the owner, group, other users, and all users, respectively
+, -, = add, remove, set permissions
31. Programs are executable codes and data stored in media such as hard disks, CDs, etc., and are statically stored codes. A process is a program code that runs in the CPU and memory, and is a dynamically executed code. When a large number of users access Web pages at the same time, the httpd program may create multiple processes to provide services
32.ps View the process, you can monitor the work of the background process
34.-f Display all information about the process
35. Process state: R means progress state, S means sleep state; T means suspend or terminate state machine; Z means dead state
PRI: the priority of the process
36.top is a dynamic display process that continuously refreshes the current state through user keys
37. Each process in the system has a process number, which is used for system identification and scheduling. There are two main ways to start a process: manual start and scheduled start
38.Ctrl + Z: Suspend the current process, that is, call it into the background and stop execution
Ctrl+C : Interrupt the command being executed
kill, used to terminate the process with the specified PID number, generally used in conjunction with the ps command
39.cal, display calendar information
date, display and set the system date and time, only super users have permission to use the date command to set the date and time, ordinary users can only use the date command to display the date and time
40. Scheduled tasks: If you want to trigger a job at a fixed time, you need to create a scheduled task. Scheduled tasks are divided into one-time scheduled tasks and periodic scheduled tasks.
41.Tab, auto-completion command
The history command can view the executed commands
alias Set the alias. There cannot be spaces at both ends of the equal sign. The string needs to be quoted. The alias is set to take effect permanently.
42. The man command is used to obtain the help documentation of the Linux system
Unlike the man command, the help information of the info command is easier to read
Chapter 3 Using the VI Compiler
1. VI is a full-screen text compiler used in UNIX systems, and VIM is an enhanced version of VI
Using the VI compiler can easily complete system configuration files, programming, text compilation, etc.
2. In VIM, there are also some enhanced functions, such as undoing multi-line input, parameter highlighting, command-line compilation and support for multi-window and multi-buffering of graphical VI (GVIM), etc.
3. The VI compiler has three operating modes: command mode, insert mode, and bottom line mode
By default it is in command mode after starting the VI
4. Command mode → Insert mode ( keys such as a, i, o )
Insert Mode → Command Mode (ESC key)
Command Mode → Bottom Line Mode (: key)
5.: wq save the file modification and exit. or ":X" can also
:recover recover files
6.:set nu: display line number
vimtutor A copy of the VIMtutor tutorial
Chapter 4 Shell Scripting
1. In addition to being a command interpreter, Shell can also be used as a programming language to automate processing in the form of script files
3. In the string enclosed in single quotes , the backslash also becomes a normal character, and the escape character function is lost
4. Variables in Shell are weakly typed and do not need to declare types
5. Variables are divided into three categories: environment variables, predefined variables and user variables according to their usage.
Environment variables are similar to global variables in high-level programming languages, but most environment variables are dedicated, such as PATH, HOME, etc., which are part of the system environment and do not need to be defined.
Shell predefined variables are provided by the system. Unlike environment variables, users cannot modify them. Such variables are used to make judgments in programs.
User variables are also called local variables and local variables. They can be used and modified arbitrarily in the Shell program. When assigning a value to a variable, there must be no spaces on either side of the equal sign.
6. Print variables through the echo keyword and read variables through the read keyword
7. The file judgment statements in Shell are usually divided into three categories: file testing, numerical comparison and string comparison
8. ; acts as a command separator, if no ";" is added, a newline is required
9. until the loop ends when the condition is met
10. A function is a statement block that completes a relatively independent function. Whether or not parameters are required is determined by the definition and function of the function
11. The function needs to be declared before calling the function. The shell script is executed line by line and will not be precompiled. The function must be declared before using the function
12. Echo content
13.&>/dev/null means that no matter the correct or wrong output is redirected to an empty device, that is, no information is output. /dev/null means an empty device
Chapter 5 Compilation and Development under Linux
1. When users use the operating system, there are mainly three forms: graphical interface, command interface, and programming interface
2. GCC (GNU Compilation Tools Collection), GNU is a UNIX-like operating system composed of applications, system libraries, development tools, and other programs
3. GCC was born before the Linux kernel program, it can be said that it contributed to the birth and development of the Linux kernel
4. Free software means that users are free to run, copy, distribute, learn, improve and distribute the software. "Free software" is mostly released under the GNU General Public License (GNU GPL). Free Software's Free is not free, it deserves "free speech not free drinks", and how the software is priced does not affect whether it is classified as free software
5. The network settings can be set to automatically obtain an IP address in bridging or NAT mode, and the local physical entity can be connected to the Internet, then the virtual machine can be connected to the Internet
6. Both GCC and g++ are part of the GCC compilation suite. The basic attribute of GCC is to compile the C language. Although GCC supports multi-language compilation, in fact, it mainly acts as a compiler selector. The compilation of other languages is done through GCC passes to the corresponding compiler implementation. GCC compiling C++ code is just a shell action, the real compilation work needs to be transferred to g++, and the linking of C++ dynamic library is also through g++
7. GCC calls preprocessing, compilation, and connection tools respectively to automatically complete the compilation of the program
8. #include < stdio.h >
9. The dynamic library and static library under Linux system are .so and .a files respectively, and under Windows are .dll and .lib files. Static library files must be linked into the application at compile time, and the index and implementation of the library functions called are in it. The advantage of static compilation is that there is no need to suspend the dynamic library when the program is running; the disadvantage is that the application program is relatively large, and the flexibility of the dynamic library is lost. After the program is modified, it needs to be recompiled and released.
20. Unlike the static library, the dynamic library is called only during the runtime when the file is dynamically linked. When the application is compiled and linked, the functions and data in the library are not copied to the executable file but are passed through the description of the static library. When compiling and loading, the program code is linked with the function code called in the dynamic library file, thereby saving memory resources. Both library files are distributed with the application, otherwise, an error will be generated when the application is run
21. GDB is a debugger program used to debug executable files under the command line. Note that not all executables can be debugged,
23. The system call is the interface layer for the user process to enter the kernel
24. Before reading and writing a file, be sure to perform an open file operation. The purpose of the open operation is to find the file location and register it in the system, so as not to repeatedly find where the file is during each read and write operation.
25.gets() is to read characters from the standard device and store them in the memory space pointed to by the parameter s. Until the newline character or the end of the file is read, the call successfully returns the s pointer, and the return of NULL indicates that an error has occurred. gets() cannot know the size of the string s, and the writing of read data can easily cause security problems of buffer overflow. It is generally recommended to use fgets () instead.
26. stdin (standard input) and stdout (standard output) are typical representatives of "line buffering". The input and output characters are first stored in the buffer, and the real I/O operation is performed when a newline character is encountered, and the buffer is cleared.
26. When calling scanf to get input, the function does not read the carriage return, and also leaves it in the buffer
getchar removes extra carriage returns in the buffer
27. The operating system is essentially system-level software running on hardware. When the computer is powered on, the basic input/output program in the motherboard chip starts a prairie fire, triggering the boot program to enter the memory for execution, and then The boot program then boots the operating system program from the hard disk into the memory.
28. In simple terms, a process is an execution of a program in memory, and the information that manages and controls the process forms an important data structure that marks where the process is - process control block
29. The new process and the original process generated by fork have their own execution routes, but there is a parent-child relationship
30. The main purpose of introducing threads is to improve the concurrency or parallelism of multi-program execution (on multi-processor machines), thereby improving processing efficiency. A thread can be simply defined as an execution line within a process, and multiple lines share the resources of the process to which they belong
31. When there is mutual exclusion and cooperation between multiple processes , synchronization control is required to ensure that the logic of the execution result is correct. When multiple threads share resources and cooperate, there are also synchronization problems.
32. If each thread in a process modifies the data in the global memory at the same time, and the operation function does not use a synchronization mechanism to prevent the data from being destroyed in shared use, the program execution is not program-safe.
33. The essence of the semaphore is " a counter + a mutex + a waiting queue"
34. A pipe is actually a special temporary or permanent file, which is a shared file that connects a reading process and a writing process to realize inter-process communication.
35. Named pipes communicate by providing a buffer corresponding to a pipe file with a path name on both sides of the communication. Even if the multiple processes that need to communicate are not related, as long as they have access to the pipe file, they can communicate with each other through the pipe
36. The memory space should be fully utilized, and the address mapping should be formed according to the mechanism of allocating memory
Chapter 6 The Linux Kernel and Applications
1. An operating system is essentially software, a collection of system programs
2. The kernel is the most important component of the operating system and is used to manage all hardware and software resources in the computer. The installed Linux operating system generally does not need to compile the kernel. The new kernel will revise the bugs of the kernel and add many new features; when users want to use these new features, or want to customize a more efficient one according to their own system , a more stable kernel, you need to recompile the Linux kernel.
3. There are three main ways to upgrade the kernel: (1) Upgrade from the kernel source code (2) Manually install the new version of the Lernel RPM file (3) Upgrade through yum
4. Save the driver in the form of a template, you can not directly put the driver into the kernel, which is beneficial to control the size of the kernel
5. The whole process of the module is a dynamically loadable kernel module, which allows the kernel module to be dynamically loaded or unloaded after the system is started to enable or disable certain functions of the system
6.lib: function library
7. If it is a foreign module, you must execute the depmod command
Chapter 7 Typical Services on Linux
1. There are three ways to configure the host IP: graphical interface configuration, command line command configuration, and direct modification of the configuration file
2.System tools/settings/network to open the network connection settings window
3. Check IP linux (ifconfig), windows (ipconfig)
4. Network adapter network card MAC address
5. vi / etc / sysconfig /network-scripts/ifcfg-ens33
ststemctl restart network service, restart the network service to make the configuration take effect immediately
6. => TAB key
7. The APR address resolution protocol is used to map the IP address to the corresponding physical address (that is, the MAC address that is often said). By looking at the APR table, you can view the MAC address of the connected LAN device.
8. WWW service is based on the Internet, allowing users to access the hypertext file resources linked to each other on another computer through the Internet. It is essentially a service based on the network. A service that provides resource sharing in the form of web pages, also often referred to as Web services
9. There are three basic elements of early WWW services: HTML file resources organized by the server side, Uniform Resource Locator URLs for specifying resource locations, and the protocol specification HTTP followed when the client and server communicate with each other.
10. Four basic elements of URL (transmission protocol, server address, port number, path)
systemctl start vsftpd starts the FTP service
systemctl stop vsftpd stops the FTP service
systemctl restart vsftpd restarts the FTP service
13.SSH service: password-based security authentication, key-based security authentication
14.systemctl enable target; start service
15.systemctl start target to open the firewall
Alibaba Cloud's mission has really benefited me a lot
Knowledge Base Team
Knowledge Base Team
Knowledge Base Team
Knowledge Base Team
Explore More Special Offers
50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00