Linux basic operation notes
Linux File System has a tree structure to organize files. The top of the number is the root directory/, the node is the directory, and the last node is the included data file. We can perform various operations on files, such as opening and reading/writing. The partition File System of storage devices aims to organize a large amount of data into persistent storage devices, such as hard disks and disks. These storage devices are different from the memory. Their storage capabilities are persistent and will not disappear due to power failure. The storage capacity is large, but the reading speed is slow. Data is stored in a partition. A typical Linux partition contains the following parts: The first part of the partition is the Boot block ), it is mainly used for computer boot. After linux is started, MBR is loaded first, and then MBR is loaded from the startup zone of a hard disk. This program is responsible for loading and starting the operating system. For ease of management, Linux reserves a boot zone in a partition even if the operating system is not installed in it. After the startup zone, the Super block is used ). It stores information about the file system, including the type of the file system, the number of inode, and the number of data blocks. Then there are multiple inodes, which are the key to implementing file storage. In Linux, a file can be divided into several data blocks, each of which corresponds to an inode. This inode contains multiple pointers pointing to each data block of the file. When the operating system needs to read files, it only needs to correspond to the inode "map" and collect scattered data blocks to get our files. The last part is the block data blocks that truly stores data. When Linux wants to open a file, it only needs to find the inode corresponding to the file, and then collect all the data blocks along the pointer to form the data of a file in the memory. In a complex way, you can use a linked list. Each data quickly has a pointer pointing to the next data block belonging to the same file. The advantage is that you can use scattered free space, the disadvantage is that file operations must be performed in a linear manner. If you want to access them randomly, you must traverse the table to guide the target location. Listing detailed file information in a folder ls indicates a list, focusing on displaying the file name and related attributes. The option "-al" indicates listing the detailed permissions and attributes of all objects. Floralin @ ubuntu :~ $ Ls-al1) the first column indicates the file type and permission (permission): the first character d is the directory, and when-is the file, if it is [l], it indicates a link file. If it is B, it indicates an interface device (random access device) that can be stored in the device file ), if it is c, it indicates the serial port device in the device file, such as the keyboard and mouse (one-time reading device ). The following characters are a group of three parameters, which are a combination of three parameters: rwx. [r] indicates read and [w] indicates write), [x] indicates executable ). The first group is the permissions of the file owner, the second group is the permissions of the same group, and the third group is the permissions of other non-local groups. 2) The second column indicates how many file names are linked to this node. 3) the third column indicates the owner account of the file. 4) The fourth column indicates the group to which the file belongs. 5) the fifth column indicates the size of the file. The default unit is bytes 6. The sixth column indicates the file's file creation date or the last modification date. The folder floralin @ ubuntu :~ /Desktop/linux_study $ mkdir testfloralin @ ubuntu :~ /Desktop/linux_study $ lstest Delete the empty folder floralin @ ubuntu :~ /Desktop/linux_study $ rm testrm: cannot remove 'test': Is a directoryfloralin @ ubuntu :~ /Desktop/linux_study $ rmdir testfloralin @ ubuntu :~ /Desktop/linux_study $ ls change file attributes and permissions chgrp: change file group chown: change file owner chmod: change file permissions, SUID, SGID, SBIT and other features change the file group floralin @ ubuntu :~ /Desktop/linux_study $ sudo chgrp users linux_study change the file owner floralin @ ubuntu :~ /Desktop/linux_study $ sudo chown root linux_study change File Permission floralin @ ubuntu :~ /Desktop/linux_study $ sudo chmod 755 linux_study: Change the File Permission to 755: owner r + w + x, group: r + x, and $ cat filename: show File $ cat file1 file2: connect to show file1 and file2 $ head-1 filename: show the first line of the file $ tail-5 filename: show the last line of the file $ diff file1 file2: display the number of rows, words, and characters in the differential statistics file of file1 and file2. floralin @ ubuntu :~ /Desktop/linux_study $ wc test2 6 15 71 test2 display date $ date + "% Y-% m-% d _ % T" with YYYY-MM-DD_HH: MM: SS format display date and time (for details about the format, refer to $ man date) $ date -- date = "05:30:00" display network excuses and corresponding IP addresses from 05:30:00. Ifconfig can be used to set the network interface: floralin @ ubuntu :~ /Desktop/linux_study $ ifconfig run the eth0 interface floralin @ ubuntu :~ /Desktop/linux_study $ sudo ifup eth0
Disable the eth0 interface floralin @ ubuntu :~ /Desktop/linux_study $ sudo ifdown eth0
Display wireless network interface floralin @ ubuntu :~ /Desktop/linux_study $ iwconfig displays the route table. Route can be used to modify the routing table floralin @ ubuntu :~ /Desktop/linux_study $ iwconfig current network connection status floralin @ ubuntu :~ /Desktop/linux_study $ netstat send the ping packet to the IP address floralin @ ubuntu :~ /Desktop/linux_study $ ping 10.21.171.15 send a DHCP request to the DHCP host to obtain the IP address and other settings. floralin @ ubuntu :~ /Desktop/linux_study $ sudo dhclient use the wget download url to point to the resource floralin @ ubuntu :~ /Desktop/linux_study $ sudo dhclientDNS query, find the ip address floralin @ ubuntu: ~ corresponding to the domain Name domain :~ /Desktop/linux_study $ sudo dhclient package and compress large files. After the so-called File compression technology, the disk usage can be reduced to reduce the file capacity. Linux supports many compression commands, and different commands use different compression technologies. Of course, files cannot be compressed or decompressed together, different compressed files are usually differentiated by the extension of the suffix. Gzip or bzip2 compression testfloralin @ ubuntu :~ /Desktop/linux_study $ gzip test unzip testfloralin @ ubuntu :~ /Desktop/linux_study $ gzip-d test package command: tar [root @ linux ~] # Tar-cvf/tmp/etc.tar/etc <= package only, do not compress! [Root @ linux ~] # Tar-zcvf/tmp/etc.tar.gz/etc <= compressed with gzip [root @ linux ~] # Tar-jcvf/tmp/etc.tar.bz2/etc <= After packaging, compress the/tmp/etc.tar.gz file with bzip2 and decompress it under/usr/local/src [root @ linux ~] # Cd/usr/local/src [root @ linux src] # tar-zxvf/tmp/etc.tar.gz what the linux Process basic computer can actually do is actually very simple, for example, the sum of the two numbers in the club, and the address in the memory. These basic computer actions are called commands ". The so-called program is a collection of these commands. Through the program, we can let the computer complete complex operations. Most programs are stored as executable files. The difference between a process and a program is a specific implementation of the program. A process is a process of executing a program. Query the running process: floralin @ ubuntu :~ $ Ps-eo pid, comm, cmd-egeneration table lists all processes.-o pid, comm, cmd indicates that we need pid, comm, and cmd information. Each row represents a process, and the information in the three columns represents, the unique PID of each process, COMMAND is the abbreviation of the Process, CMD is the program corresponding to the process and the parameters included in the runtime (for the use, is a part of the kernel function, dressed as a process, easy to manage the operating system ). How to create a process in fact, when the computer is started, the kernel only establishes an init process. linux kernel does not directly create a new process system call. All processes are created through the fork mechanism. (Fork, the new process needs to be copied through the process itself ). When the fork process is running, linux creates a new memory space in the memory for the new process, and copies the content in the old process space to the new space, the two processes run simultaneously. You can run the pstree command to display the entire process tree: when a child process ends, the parent process is notified to clear the memory occupied by the child process and leave the exit information in the kernel. The parent process uses the wait system to call the child process when the child process ends. This wait function can retrieve the exit information of the sub-process from the kernel and clear the space occupied by this information in the kernel. However, if the parent process is terminated earlier than the child process, the child process will become an orphan (orphand) process. The orphan process is passed to the init process, and the init process becomes the parent process of the process. The init process is responsible for calling the wait function when the child process ends. There are several processes in the kernel of the linux signal process, and each process does not allow people outside the process to enter. This is a protection mechanism for each process, but sometimes it needs to break the closed protection, to exchange information with processes. In this way, a communication method is required. The transmitted signal is rough and can only be an integer. However, the signal is easy to manage and use only because of the small amount of information transmitted. Signals are often used in system management-related tasks, such as notifying the process to terminate, abort, or recover. They can also be managed by the kernel. Query the PID of a process through ping, and then send a signal to a process through the kill command: $ kill-SIGCONT 9575 to send the SIGCONT signal to the ping process. All signals in signal processing use the default operation of the corresponding signal, but it is not absolute. When the process decides to execute the signal, there are several possibilities: 1) Ignore. The signal is cleared, and the process itself performs any special operations. 2) default. Each signal corresponds to a certain default operation. For example, the SIGCONT mentioned above is used to continue the process. 3) custom operations. It is also called the signal acquisition. The preset operations in the process correspond to the signal.