This article mainly introduces thirty thousand words, 100 questions! Linux knowledge summary! As well as related experience skills, article about 160077 words, 243 page views, thumb up number 7, worth reference!
This article has organized the latest Linux interview questions, nearly 30 thousand words, about 100 questions, share so far, hope to help you.
An overview of Linux
1. What is Linux
Linux is a set of free use and free dissemination of Unix-like operating system, is a multi-user, multi-task based on POSIX and UNIX, support multi-thread and multi-CPU operating system. It can run major UNIX tools, applications, and network protocols. It supports both 32-bit and 64-bit hardware. Linux inherits the design idea of UNIX taking network as the core and is a stable multi-user network operating system.
2. What is the difference between UNIX and Linux?
Linux and UNIX are both powerful operating systems and widely used server operating systems. There are many similarities. Some people even mistakenly think that UNIX and Linux are the same.
1. Open-source Linux is an open source operating system, you don’t need to pay, you can use; Unix is a traditional commercial piece of software that protects the intellectual property of its source code and requires a paid license to use it.
2. Cross-platform Linux operating system has good cross-platform performance and can run on a variety of hardware platforms; The cross-platform performance of UNIX operating system is weak, and most of them need to be used with hardware.
3. Visual interface Linux in addition to command line operations, there is a window management system; UNIX is just a command-line system.
4. Hardware environment Linux operating system has low requirements on hardware, and the installation method is easier to master. Unix has strict hardware requirements and is difficult to install.
Linux is widely used by individuals and businesses alike. Unix’s user base is relatively narrow, mostly used by large enterprises with high security requirements, such as banks, telecom departments, or UNIX hardware manufacturers, such as Sun.
Compared with UNIX operating system, Linux operating system is more popular with the majority of computer enthusiasts, the main reason is that Linux operating system has all the functions of UNIX operating system, and can achieve all UNIX features on ordinary PC computers, open source and free features, more easy to use!
3. What is the Linux kernel?
The core of the Linux system is the kernel. The kernel controls all hardware and software on a computer system, allocating hardware when necessary, and executing software as needed. System memory management application management hardware device management file system management
4. What are the basic components of Linux?
Like any other typical operating system, Linux has all these components: the kernel, shell, and GUI, system utilities, and applications. What gives Linux an advantage over other operating systems is that each aspect comes with additional functionality, and all the code can be downloaded for free.
5. Linux architecture
Broadly speaking, the Linux architecture can be divided into two parts:
User Space: User Space also includes User Applications and C Library.
Kernel Space: The Kernel Space also includes the System Call Interface, the Kernel, and the architecture-dependent Kernel Code.
Why is the Linux architecture divided into user space and kernel space?
1. Modern CPUs implement different operating modes, in which different CPUs can execute different instructions and access different registers. 2. From the perspective of CPU, Linux divides the system into two parts in order to protect the kernel security.
User space and kernel space are two different states of program execution. We can complete the transfer from user space to kernel space in two ways: 1) system call; 2) Hardware interrupts.
6. What are the basic differences between BASH and DOS?
The main differences between the BASH and DOS consoles are in three aspects:
1. The BASH command is case-sensitive, while the DOS command is not. 2. Under BASH, / character is the directory delimiter and \ is the escape character. Under DOS, / is used as a command parameter delimiter, and \ is a directory delimiter. 3. OS follows the convention in naming files, that is, an 8-character filename followed by a dot, with a 3-character extension. Bash does not follow such conventions.
7. Linux boot process?
1. The host power up and self-check, load BIOS hardware information. 2. Read the MBR boot file (GRUB, LILO). 3. Boot the Linux kernel. 4, Run the first process init (process number is always 1). 5. Enter the corresponding run level. 6, Run the terminal, enter the user name and password.
8. What is the default runlevel of Linux?
To turn it off.
Single user mode.
Character interface in multi-user mode (no network support).
Multiuser mode for the character interface.
Not allocated for use.
Multiuser mode for the graphical interface.
Restart.
9. What kind of interprocess communication does Linux use?
- Pipe (PIPE), stream pipe (S \ _PIPE), named pipe (FIFO).
- Signal (signal).
- Message queue.
- Shared memory.
- Semaphore.
- Sockets.
10. What system log files does Linux have?
Of greater importance is the /var/log/messages log file.
This log file is a summary of many process log files that show any attempted or successful intrusions. In addition, if there is a centralized collection of ELK logs in Fatfriend’s system, it will also be collected.
11. Is it helpful to have multiple desktop environments installed on a Linux system?
Usually, a desktop environment, such as KDE or GNOME, is sufficient to run without problems. Although the system allows you to switch from one environment to another, it is always a priority for the user. Some programs work in one environment but not in another, so it can also be considered a factor in choosing which environment to use.
12. What is swap space?
Swap space is a space used by Linux to temporarily hold programs that are running concurrently. This happens when RAM does not have enough memory to hold all the programs that are being executed.
13. What is a root account
The root account is like a system administrator account, allowing you complete control of the system. This is where you can create and maintain user accounts, assigning different permissions to each account. This is the default account every time you install Linux.
14. What is LILO?
LILO is the boot loader for Linux. It is mainly used to load the Linux operating system into main memory so that it can start running.
15. What is BASH?
Bash is short for Bourne Again SHell. It was written by Steve Bourne as an alternative to the original Bourne Shell (represented by /bin/sh). It combines all the features of the original Bourne Shell, as well as other features, to make it easier to use. Since then, it has been adapted as the default shell for most systems running Linux.
16. What is CLI?
The command-line interface (English ** : Command-line Interface **, abbreviation] : CLI) was the most widely used user interface before the popularity of graphical user interfaces. It usually did not support the mouse. The user typed commands through the keyboard, and the computer received the commands and executed them. It is also called the Character User Interface (CUI).
The command-line interface (CLI) is generally considered less user-friendly than the graphical user interface (GUI). Because command-line interface software usually requires the user to remember the commands of the operation, but, because of its own characteristics, command-line interface can save the resources of the computer system than the graphical user interface. With commands memorized, the command line interface is often faster than the graphical user interface. Therefore, the graphical user interface operating system, retain the optional command-line interface.
17. What is GUI?
Graphical User Interface (GUI) is a Graphical display of computer operation User Interface.
A graphical user interface (GUI) is a human-computer interface display format that allows users to use an input device, such as a mouse, to manipulate on-screen ICONS or menu options to select commands, invoke files, launch programs, or perform some other everyday tasks. A graphical user interface has many advantages over a character interface that performs routine tasks by typing text or character commands through a keyboard.
**18. What are the advantages of open source? ** Open source allows you to distribute software (including source code) for free to anyone who is interested. One can then add functionality and even debug and correct errors in the source code. They can even make it work better and then feel free to redistribute the enhanced source code again. This ultimately benefits everyone in the community.
19. What is the importance of the GNU project?
This so-called free software movement has many advantages, such as the freedom to run programs and learn and modify them as you want. It also allows you to redistribute copies of your software to others, as well as to freely improve your software and release it to the public.
II. Disks, directories and files
1. Simple Linux file system?
In the Linux operating system, all resources managed by the operating system, such as network interface cards, disk drives, printers, I/O devices, ordinary files, or directories, are treated as one file.
That said, there is an important concept in Linux systems ** : everything is a file **. It was an expression of the UNIX philosophy, and Linux was rewritten from UNIX, so the concept has been passed on. On UNIX systems, all resources are treated as files, including hardware devices. UNIX systems treat each piece of hardware as a file, often called a device file, so users can access the hardware by reading or writing to the file.
Linux supports five file types, as shown in the figure below: file types
2. What is the directory structure of Linux?
This question is not usually asked. More is the actual use, need to know.
The Linux file system has a distinct hierarchy, like an upside-down tree, with its root directory at the top: the Linux directory structure
Common directory description:
- /bin: stores binary executable files (ls,cat,mkdir, etc.), where common commands are generally found;
- /etc: store system management and configuration files;
- /home: The root directory where all the user files are stored is the base point of the user’s home directory. For example, the home directory of user is /home/user, which can be represented by ~user.
- **/usr ** : To hold system applications /opt: The location where additional installed optional application packages are placed. In general, we can install Tomcat and so on here;
- /proc: The virtual file system directory, which is a map of system memory. This directory can be accessed directly to obtain system information;
- /root: the home directory of the superuser (system administrator) (privileged class o);
- /sbin: Holds binary executables, accessible only by root. This is where the system-level administrative commands and programs used by the system administrator are stored. Such as ifconfig, etc.;
- /dev: for storing device files;
- / MNT: The mount point where the system administrator installs a temporary file system. This directory is provided to allow users to temporarily mount other file systems.
- /boot: store various files used for system boot;
- **/lib ** : holds library files related to system operation;
- / TMP: Used to store various temporary files, is a public temporary file storage point;
- /var: A file that holds data that needs to be changed at run time. It is also an overflow area for some large files, such as log files for various services (system startup logs, etc.). And so on;
- / Lost + Found: This directory is usually empty, leaving behind “homeless” files (.chk on Windows) that have been shut down improperly.
3. What is an inode?
In general, inodes are not asked in interviews. But inode is an important concept that is fundamental to understanding UNIX /Linux file systems and hard disk storage.
Understanding inodes starts with file storage.
Files are stored on a hard disk. The smallest unit of storage on a hard disk is called a Sector. Each sector stores 512 bytes (equivalent to 0.5KB).
When an operating system reads a hard disk, it does not read one sector at a time, which is inefficient. Instead, it reads multiple sectors in a row at once, or a “block” at a time. This “block”, consisting of multiple sectors, is the smallest unit of file access. The size of a block is 4KB, or eight sectors in a row to form a single block.
The file data is stored in “blocks”, so obviously we have to find a place to store metadata about the file, such as the creator of the file, the date the file was created, the size of the file, and so on. The area where the file’s meta information is stored is called an inode, which translates as an inode.
Each file has a corresponding inode, which contains some information about the file.
Describe how the Linux file system converts the logical and physical structure of a file through I nodes.
Generally speaking, interviewers don’t ask this question.
Linux uses the inode node table to convert the logical and physical structure of a file.
· The inode node is a 64-byte long table, which contains information about the file, including important information such as the size of the file, the owner of the file, the access permission of the file, and the type of the file. The most important thing in the inode node table is the disk address table. There are 13 block numbers in the disk address table, and the file will read each block in the order that the block numbers appear in the disk address table. · The Linux file system connects the inode node to the file name. When the file needs to be read, the file system looks for the item corresponding to the file name in the current directory table, so as to obtain the corresponding inode node number of the file. The physical blocks of the scattered files are connected into the logical structure of the files through the disk address table of the inode node.
4. What are hard links and soft links?
1) Hard links
Since files under Linux are identified by inodes, a hard link can be thought of as a pointer to a file inode, for which the system does not reassign inodes. For each hard link added, the number of links in the file is increased by 1.
Shortages: 1) It is not possible to establish links between files on different file systems; 2) Only superusers can create hard links for directories.
2) Soft links
Soft links overcome the shortcomings of hard links, there are no file system restrictions, any user can create a symbolic link to the directory. As a result, it is now more widely used and has greater flexibility, even allowing files to be linked across different machines and networks.
Shortages: because the linked file contains the path information of the original file, so when the original file is moved from one directory to another directory, and then visit the linked file, the system will not find it, while the hard link does not have this defect, you can move it as you like; It also requires the system to allocate extra space for new inodes and paths to save the original files.
In a real world scenario, soft links are basically used. The differences are summarized as follows:
· Hard links cannot cross partitions. Software chains can cross partitions. · A hard link points to an inode node while a soft link creates a new inode node. · If hard linked files are deleted, the original file will not be deleted; if soft linked files are deleted, the original file will be deleted.
5. What is RAID?
The basic idea behind RAID is to group several relatively inexpensive hard drives together into a group that can match or even exceed the performance of a single, expensive, massive disk. RAID is usually used on a server computer, using exactly the same hard disk to form a logical sector, so the operating system will treat it as just one hard disk.
RAID is divided into different levels, each with different tradeoffs in terms of data reliability and read and write performance. In practical application, you can choose different RAID schemes according to your actual needs.
Of course, since many companies use cloud services, it is difficult to get access to the concept of RAID, more likely to be plain cloud disk, SSD cloud disk.
Third, security
1. What security work does a Linux system need to do after initializing the environment?
1. Add normal user login, disable root login, change SSH port number.
Modifying the SSH port is not necessarily absolute. Of course, if you want to expose the external network, it is recommended to change. l
2. Server login with key, password login is prohibited.
3. Open firewall, close SELinux, and set corresponding firewall rules according to business requirements.
4. Install Fail2ban, a software that prevents SSH from breaking violence.
5. Only the export IP of the company’s office network can log in the server (depending on the actual needs of the company).
You can also install software such as a VPN, which is only allowed to connect to the server.
6. The number of modification history command records is 10.
7, only allow the need for the server can access the external network, other all prohibited.
8, do a good job of software protection. 8.1 Set up the nginx\_waf module to prevent SQL injection. 8.2 Start the Web Service using WWW User and change the owner and group of the site directory to WWW.
2. What is a CC attack? What is a DDoS attack?
CC attack, is mainly used to attack the page, simulate a number of users keep visiting your page, so that your system resources are exhausted.
A DDoS attack, known in Chinese as a distributed denial of service attack, refers to a combination of computers using server technology as an attack platform to launch a DDoS attack on one or more targets.
Attack, that is, through a large number of legitimate requests to occupy a large number of network resources, in order to achieve the purpose of paralyzing the network.
How do I prevent CC and DDoS attacks?
Prevention CC, DDoS attack, these can only be done with hardware firewall flow cleaning, the attack flow into the black hole.
The traffic cleaning part is mainly to buy anti-attack services from ISP service providers. Generally, there is spare traffic in the computer room. We usually buy services, after all, the attack will not last for a long time.
3. What is website database injection?
Because programmers vary in skill and experience, most programmers write code without making judgments about the validity of user input data.
The application has a security risk. The user can submit a piece of database query code, according to the results of the program, to get some of the data he wants to know, this is called SQL injection.
SQL injection is accessed from a normal WWW port and appears to be no different from a normal Web page access. If the administrator does not have the habit of looking at the logs, the intrusion may go unnoticed for a long time.
How to filter and prevent? Database web side injection of this, you can consider using nginx\_waf for filtering and prevention.
Shell
1. What is a Shell script?
A Shell script is a text file that contains one or more commands. As system administrators, we often need to use more than one command to complete a task, we can add all these commands in a text file (Shell script) to complete these daily work tasks.
– What is the default login Shell?
On the Linux operating system, “/bin/bash” is the default login Shell, which is assigned at user creation time.
Use the CHSH command to change the default Shell. An example is as follows:
## CHSH < username >-s < new shell> ## CHSH thinkwon-s /bin/sh
– How do I write comments in a Shell script?
Comments can be used to describe what a script can do and how it works. Each line of comments begins with a #. Examples are as follows:
#! /bin/bash ## This is a command echo "I am logged in as $USER"
2. The grammatical level
– What types of variables can be used in Shell scripts?
In Shell scripts, we can use two types of variables:
System Define Variables: System variables are created by the system itself. These variables are usually composed of uppercase letters and can be viewed with the set command.
User-defined variables: User-defined variables are generated and defined by the system user. The value of the variable can be seen by using the command “echo $< variable name >”.
– $? In Shell script What is the purpose of the tag?
When writing a Shell script, if you want to check the success of the previous command, use $? You can check the end state of the previous command.
· If the end state is 0, the previous command was executed successfully. Such as:
root@localhost:~## ls /usr/bin/shar
/usr/bin/shar
root@localhost:~## echo $?
0
· If the end state is not 0, the command failed to execute. Such as:
root@localhost:~## ls /usr/bin/share
ls: cannot access /usr/bin/share: No such file or directory
root@localhost:~## echo $?
2
– What are the special variables in the Bourne Shell(bash)? The following table lists the special variables set by the Bourne Shell for the command line.
Built-in variable to explain script name on command line $0 $1 first command line argument $2 second command line argument... . ... $## Number of command line arguments $* All command line arguments, separated by Spaces
– How to cancel variable or variable assignment? The unset command is used to cancel a variable or cancel variable assignment. The syntax is as follows:
## unset < variable name >
– How is the if syntax nested in Shell scripts?
If [condition] then command 1 command 2 . Else if [condition] then command 1 2... Else command 1 command 2... . fi fi
– How to compare two numbers in a Shell script? Use test commands (-gt, etc.) in if-then to compare two numbers. Such as:
#! If [$x-gt $y] then echo "x is greater than y" else echo "y is greater than x" fi
– Syntax for case statements in Shell scripts? The basic syntax is as follows:
Case variable in value 1) command 2... . Last order!! Value 2) command 1 command 2... The last command; esac
For loop syntax in Shell scripts? The basic syntax is as follows: –
For variable in loop list do command 1 command 2... Finally command done
While loop syntax in Shell scripts?
· Like the for loop, the while loop repeats its command block as long as the condition holds. · Unlike a for loop, a while loop iterates until its condition is not true.
Basic grammar:
While [condition] do command... done
What is the basic format of the -do-while statement?
A do-while statement is similar to a while statement, but the conditional statement is checked before the command is executed. . Here is the syntax for using a do-while statement:
Do {command} while (condition) 1 2 3 4
– What does the break command do in a Shell script?
A simple use of the break command is to exit a loop in execution. We can break out of the loop using the break command in the while and until loops.
– What does the continue command do in a Shell script?
The continue command differs from the break command in that it only breaks out of the iteration of the current loop, not the entire loop. The continue command is useful in many cases, such as when an error occurs but we still want to continue executing a large loop.
– How to make the script executable?
Use the chmod command to make the script executable. Here’s an example: chmod a+x myscript.sh.
#! What does /bin/bash do? #! /bin/bash is the first line of the Shell script, known as the shebang line. Here the # symbol is called hash, and! Is called a bang. It means that the command is executed through /bin/bash.
– How to debug Shell scripts?
Use the -x’ number (sh-x myscript.sh) to debug Shell scripts. Another option is to use the -nv parameter (sh-nv myscript.sh).
– How to redirect standard and error output to the same location at the same time?
## ls /usr/share/doc > out.txt 2>&1 ## ls /usr/share/doc &> out.txt
– How do I test files in Shell scripts?
The test command can be used to test files. Basic usage is shown in the table below:
Returns true-e if the file exists and is a directory. Returns true-f if the file exists and is plain. Returns true-r if the file exists and is readable. Returns true-s if the file exists and is not empty. Returns true-w if the file exists and is writable. Returns true-x if the file exists and is executable
– How to define functions in Shell scripts?
A function is a block of code that has a name. When we define the code block, we can call the function name in our script, and the block will be executed. An example is as follows:
$ diskusage () { df -h ; [function] function name [()] {command; [return int;] }
How do I let the Shell get input from the terminal on a script?
The read command reads data from the terminal (using the keyboard). The read command takes the user’s input and places it in the variable you give it. Examples are as follows:
## vi /tmp/test.sh
#!/bin/bash
echo ‘Please enter your name’
read name
echo “My Name is $name”
## ./test.sh
Please enter your name
ThinkWon
My Name is ThinkWon
– How to perform arithmetic operations?
There are two ways to perform arithmetic operations:
Expr: ## expr 5 + 2 $\[expression \] : test=$[16 + 4]; Test = $16 + [4].
Four, programming problem
1. If a file is a character device file, copy it to /dev directory.
#!/bin/bash
read -p "Input file name: " FILENAME
if [ -c "$FILENAME" ];then
cp $FILENAME /dev
fi
2. Add a new group Class1, and then add 30 users belonging to this group with the username STDXX, where xx is from 01 to 30?
#! /bin/bash groupadd class1 for((i=1; i<31; i++)) do if [ $i -le 10 ]; then useradd -g class1 std0$i else useradd -g class1 std$i fi done
3. Write a Shell program to realize the function of automatically deleting 50 accounts, whose names are stud1 to stud50?
#! /bin/bash for((i=1; i<51; i++)) do userdel -r stud$i done
4. Write a sed command to modify the contents of the/TMP /input.txt file.
Requirements: · Delete all blank lines. · In a line, insert “AAA” before “11111” and “BBB” after “11111” if it contains “11111”. For example, change the line with content 0000111112222 to 0000AAA11111BBB2222.
[root@~]## cat -n /tmp/input.txt 1 000011111222 2 3 000011111222222 4 11111000000222 5 6 7 111111111111122222222222 8 [root@~]## sed '/^$/d'/TMP /input.txt 000011111222 000011111222222 [root@~]## sed 's#\(11111\)#AAA\1BBB#g' /tmp/input.txt 0000AAA11111BBB222 0000AAA11111BBB222222 AAA11111BBB000000222 AAA11111BBBAAA11111BBB11122222222222 22AAA11111BBB111 112222222 1122
Five, actual combat war
1. How to select the Linux operating system version?
Generally speaking, desktop users prefer Ubuntu; The server is preferred by RHEL or CentOS, and CentOS is preferred by both.
According to specific requirements:
· If security requirements are high, choose Debian or FreeBSD.
· SUSE is available for users who need to use database advanced services and email network applications.
· Feddora is a beta and pre-release version of RHEL and CentOS for new technologies and features.
· [Key] According to the current situation, the vast majority of Internet companies choose CentOS. Now more commonly used is the 6 series, now the market occupies about half. Another reason is that CentOS is more focused on the server domain and has no copyright restrictions.
CentOS 7 series, also slowly use will be more.
2. How to plan a Linux host? What are the steps?
1. Determine what the machine is for, such as Web, DB, or Game Server.
Machines are configured differently for different purposes.
2, after determining how the system needs to be installed, which system to install by default, how to do partition.
3, what parameters need to optimize the system, what users need to create, and so on.
**3. Could you please tell me how to deal with the user’s feedback that the website visit is slow? ** – What are the factors that lead to slow site visits?
1, the server outlet bandwidth is not enough
The export bandwidth purchased by the server itself is relatively small. Once the concurrent quantity is large, it will cause the outlet bandwidth to each user is small, and the access speed will be slow naturally. Cross-carrier networks result in reduced bandwidth. For example, the company website on the telecom network, then the customer side of the connection is Great Wall broadband or Unicom, which may also lead to the reduction of bandwidth.
2, the server load is too large, resulting in the response is not coming
You can start by analyzing the system load and using either the w command or the uptime command to view the system load. If the load is high, use the top command to check the CPU, MEM, and so on. Either the CPU is busy or there is not enough memory. If both of these are normal, then use the SAR command to analyze the network card traffic, analysis is not under attack. Once the cause of the problem is analyzed, take corresponding action to solve it, such as deciding whether to kill some processes, or ban some access, etc.
3. Database bottleneck
If there are more slow queries. Then it is up to the developer or DBA to assist with SQL statement optimization. If the database is slow to respond, consider adding a database cache, such as Redis. Then, you can also set up a MySQL master slave, with one MySQL server responsible for writing and several others for reading from the database.
4. The website development code is not optimized
For example, SQL statements are not optimized, causing database reads and writes to be time-consuming.
– How to check the slow website access?
1, first to determine whether the client side or the server side of the problem. When receiving feedback from users that the visit is slow, they immediately visit the site to see, if their side of the visit is fast, the basic conclusion is that the user side of the problem, you need to be patient to explain to customers, to help customers solve the problem.
Don’t just come up and look at the server side. Be sure to start at the source and work your way down.
2, if the access is slow, then you can use the debugging function of the browser to see what a data load consumption time is too much, is the picture loading is slow, or some data loading is slow.
3, for the server load. Look at the consumption of server hardware (network, CPU, memory). If it is the purchase of cloud host, such as Ali cloud, you can log in Ali cloud platform to provide various aspects of monitoring, such as CPU, memory, bandwidth usage.
4, if found that the hardware resource consumption is not high, then you need to check the log, such as looking at the MySQL slow query log, to see if a SQL statement query is slow, resulting in slow website access.
– How to fix it?
1, if the export bandwidth problem, so long to increase the export bandwidth. 2, if the slow query is more, then the developer or DBA to assist in SQL statement optimization. 3, if the database response is slow, consider adding a database cache, such as Redis and so on. Then you can set up a MySQL master slave. One MySQL server is responsible for writing, and several others are responsible for reading from the database. 4. Apply for purchasing CDN service and load user access. 5. If the access is still slow, it needs to be optimized from the overall architecture. Do special role dedicated, multiple servers provide the same service.
4. What are the methods of Linux performance tuning?
1, Disabling Daemons (closing Daemons). 2, Shutting down the GUI. 3. Changing kernel parameters 4, Kernel parameters. Tuning the processor subsystem subsystem 6, Tuning the memory subsystem Tuning the file system Tuning the file system 8. Tuning the network subsystem subsystem
VI. File management commands
1. The cat command
The cat command is used to connect files and print them to a standard output device.
CAT has three main functions:
1. Show the entire file at once:
cat filename
2. Create a file from the keyboard:
cat > filename
You can only create new files, not edit existing files.
3. Merge several files into one file:
cat file1 file2 > file
-b prints all line numbers for non-empty lines -n
– the instance:
(1) Input the contents of log2012.log file with line number
cat -n log2012.log log2013.log
(2) append the contents of log2012.log and log2013.log files to log.log by adding line numbers (no blank lines)
cat -b log2012.log log2013.log log.log
(3) Use here doc to generate a new file
cat >log.txt <<EOF
>Hello
>World
>PWD=$(pwd)
>EOF
ls -l log.txt
cat log.txt
Hello
World
PWD=/opt/soft/test
(4) Reverse listing
tac log.txt
PWD=/opt/soft/test
World
Hello
2. The chmod command
Linux/ UNIX file call permissions are divided into three levels: file owner, group, and others. Chmod allows you to control how files are invoked by others.
Use to change access to Linux system files or directories. Use it to control access to files or directories. This command can be used in two ways. One is a literal representation that includes letters and operator expressions. The other is a numerical setting that includes numbers.
Each file or directory has three groups of access rights, each group is represented by three digits, respectively for the owner of the file read, write and execute rights; Read, write, and execute rights of users in the same group as the owner; Read, write, and execute permissions for other users in the system. It can be found using ls-l test.txt.
Take the file log2012.log as an example:
-rw-r--r-- 1 root root 296K 11-13 06:03 log2012.log
The first column has 10 positions, and the first character specifies the file type. In the general sense, a directory is also a file. If the first character is a dash, it is a non-directory file. If it’s D, it’s a directory. Starting from the second character to the tenth character, there are nine characters in a group of three characters, which respectively represent the permissions of three groups of users to files or directories. The permission character is underlined for empty permission, R for read-only, W for write, and X for executable.
Common parameters:
-c When changes occur, the report processes information -r processes all files in the specified directory and its subdirectories
Scope of authority:
U: current user of the directory or file g: current group of the directory or file o: users or groups other than the current user or group of the directory or file a: all users and groups
Permission code:
R: read permissions, w: write permissions, x: execute permissions, 1 - : delete permissions, s: special permissions, 0
– Example: (1) Add all user executable privileges to the file t.log
chmod a+x t.log
(2) revoke all the original permissions, and then make the owner have readable permissions, and output processing information
chmod u=r t.log -c
(3) Assign the owner of file the rights to read, write and execute (7), the group of file the rights to read and execute (5), and other users the rights to execute (1)
Chmod 751 t.log-c (or: chmod u= RWX,g=rx,o=x t.log-c)
(4) Add readable permissions to all files in test directory and its subdirectories
chmod u+r,g+r,o+r -R text/ -c
3. The chown command
Chown changes the owner of the specified file to the specified user or group. The user can be either a username or a user ID. A group can be a group name or a group ID; Files are Spaces separated by a list of files to change permissions. Wildcards are supported.
-C displays information about the changed section -R handles the specified directory and subdirectories
– the instance:
(1) Change the owner and group and display the change message
chown -c mail:mail log2012.log
(2) Change the file group
chown -c :mail t.log
(3) change the folder and subfile directory owner and group to Mail
chown -cR mail: test/
4. The cp command
Copy the source file to the target file, or copy multiple source files to the target directory.
Note: Command line copying, if the target file already exists, will prompt for overwriting. In shell scripts, if you do not add -i, you will not prompt for overwriting!
-i prompt -r copy the directory and all the items in the directory -a copy the same time as the original file
– the instance:
(1) Copy a.txt to test directory, keep the original file time, if the original file has a prompt whether to overwrite.
cp -ai a.txt test
(2) Suggest a link (shortcut) for a.txt
cp -s a.txt link_a.txt
5. The find command
Used to find files in the file tree, and make the corresponding processing.
Command format:
find pathname -options [-print -exec -ok ...]
Command parameters:
Pathname: find The path to the directory that the pathname: find command looks for. For example. Is used to represent the current directory, and/is used to represent the system root directory. -print: find outputs the matching file to standard output. The -exec: find command executes the shell command given by this argument on the matched file. The corresponding command has the form 'command' {} \; , note {} and \; The space between. -ok: This is the same as -exec, but the shell commands given by this parameter are executed in a more secure mode, with a prompt for the user to decide whether to execute each command before it is executed.
Command options:
-name finds file by file name -perm finds file by file permissions -user finds file by file owner -group finds file by the group to which the file belongs. -type Find a file of a certain type, such as: B-block device file D-directory C-character device file L-symbolic link file P-pipe file F-ordinary file
– the instance:
(1) Find files that have been modified within 48 hours
find -atime -2
(2) Find the file ending in.log in the current directory. . Represents the current directory
find ./ -name '*.log'
Select * from ‘/opt’ where ‘777’ is allowed
find /opt -perm 777
(4) Find files greater than 1K
find -size +1000c
(5) Find a file equal to 1000 characters
find -size 1000c
The -exec parameter is followed by the command command, which terminates with; Is the end of the command, so the semicolon after the command is indispensable, considering that the semicolon will have different meanings on different systems, so the front is used with a backslash. The {} curly braces represent the filename previously found by find.
6. The head command
Head is used to display the beginning of the file to standard output. The default head command prints the first 10 lines of the corresponding file.
Common parameters:
-n< number of rows > shows the number of rows (plural rows denotes the number from last forward)
Example:
(1) Display the first 20 lines in the 1.log file
head 1.log -n 20
(2) Display the first 20 bytes of 1.log file
head -c 20 log2014.log
(3) Show the last 10 lines of t.log
head -n -10 t.log
7. Use less
Less is similar to more, but with less you can browse through files at will, while more can only move forward, not backward, and less doesn’t load the entire file before viewing.
Common command parameters:
-i ignores case when searching -n shows line number of each line -o < filename > saves less output in specified file -s shows continuous empty behavior on a line/string: function to search down "string"? String: function to search up "string" n: repeat the previous search (with/or? N: reverse-repeat the previous search (with/or? About) -x < Numeral> Display the "Tab" key as the specified number Space B Turn Back a Page D Turn Back a Half Page H Display Help Interface Q Exit Less Command U Scroll Forward a Half Page Y Scroll Forward a Line Spacebar Scroll Forward a Line Enter Scroll Forward a Page [pagedown] : Pageup: To turn the pageup
Example:
(1) PS view process information and display it by less page
ps -aux | less -N
(2) View multiple files
less 1.log 2.log
You can use n to see the next one, and p to see the previous one.
The ** function of the ln command is to establish a synchronous link for the files in another location. When the problem is needed in different directories, there is no need to create the same file for each directory. The link created by ln reduces the disk consumption.
Link classification: software links and hard links
Soft links:
1. Soft links exist in the form of paths. Similar to shortcuts in the Windows operating system 2. Soft links can span file systems, hard links cannot 3. A soft link can link to a file name that does not exist
Hard links:
1. Hard link, in the form of a copy of the file. But it doesn’t take up real space. 2. Hard links to directories are not allowed 3. Hard links can only be created on the same file system
Note:
First, the ln command keeps the synchronization of each linked file, meaning that no matter what you change, all the other files will change the same. The second: Ln links and points of soft and hard links two kinds, soft links is ln -s source file object files, it will only be in the position of your selected to generate a file of the mirror, not take up disk space, hard links the target file ln source files, no parameters – s, it will be in the position of your selected to generate a file with the same size and source files, Files change synchronously whether they are soft or hard linked. The ln directive is used to link files or directories. If more than two files or directories are specified at the same time, and the final destination is an existing directory, all the previously specified files or directories will be copied to that directory. If you specify more than one file or directory at the same time and the final destination is not an existing directory, an error message appears.
Common parameters:
-B delete, overwrite previously created link -S soft link (symbolic link) -V shows detailed processing
Example:
(1) Create a soft link to the file and display the operation information
ln -sv source.log link.log
(2) Create a hard link to the file and display the operation information
ln -v source.log link1.log
(3) Create soft links to directories
ln -sv /opt/soft/test/test3 /opt/soft/test/test5
9. The locate command
Locate is able to find files quickly by searching the system’s built-in document database, which is updated by the updateDB program, which is called periodically by the cron daemon. By default locate is faster at searching the database than it is by searching the entire disk. What’s worse is that locate may not be able to find files that were recently created or renamed. UpdateDB runs once a day in the inner set. Setup values can be updated by modifying the crontab (etc/crontab).
Locate is similar to find in that it can be used with commands such as *,? And other regular matching search
Common parameters:
-l num (number of lines to display) -f excludes specific file systems such as proc -r uses the regular expression as a search condition
Example:
(1) Find all files related to PWD (include PWD in filename)
locate pwd
(2) Search all files starting with sh in etc directory
locate /etc/sh
(3) Find the file ending with reason in /var directory
Locate -r '^/var.*reason$' Denotes one character, * denotes multiple tasks; .* denotes any number of characters)
**10. More command ** function is similar to cat, more will be page by page for users to read, and the most basic command is to press the space key to the next page to display, press the B key to back page to display.
Command parameters:
+n starts at line n -n defines screen size for line n +/pattern Search for pattern before each file is displayed, then start after the first two lines of pattern -c clears the screen from the top, then displays -d prompt "Press space to continue, Disable the ringing function -L ignores the Ctrl+ L character -P paging a file by clearing the window instead of scrolling, similar to -C -S displays successive blank lines as one line -U removes underlines from the file's contents
Common operation commands:
Enter down n lines, need to be defined. Default is 1 line Ctrl+F Scroll down Space Bar Scroll down Ctrl+B Returns Last Screen = Output Line Number of Current Line: F Output File Name and Line Number of Current Line V Invoke VI Editor! The command invokes the Shell and executes the command q to exit more
Example:
(1) Display the contents of the file from line 3 onwards
more +3 text.txt
(2) In the listed file directory details, with the help of a pipeline to display 5 lines at a time
ls -l | more -5
Press space to display the next five lines.
11. The mv command
Move the file or modify the file name according to the second parameter type (such as directory, move the file; If it is a file, re-command the file.
When the second argument is a directory, the first argument can be multiple files or directories separated by Spaces, and then move the multiple files specified by the first argument to the directory specified by the second argument.
Example:
(1) Rename the file test.log to test1.txt
mv test.log test1.txt
(2) the file log1. TXT, log2. TXT, log3. TXT moved to the root of the test3 directory
mv llog1.txt log2.txt log3.txt /test3
(3) Rename the file file1 to file2. If file2 already exists, then ask whether to overwrite it
mv -i log1.txt log2.txt
(4) Move all the files in the current folder to the next level directory
mv * .. /
12. The rm command
Deletes one or more files or directories in a directory. RM does not delete directories if the -r option is not used. If you use RM to delete a file, you can usually still restore the file to its original state.
Rm [options] file...
(1) Delete any.log files, ask for confirmation one by one before deleting:
rm -i *.log
(2) delete test subdirectory and all files in subdirectory delete, and do not need to confirm one by one:
rm -rf test
(3) Delete files beginning with -f
rm -- -f*
13. The tail command
Used to display the content at the end of the specified file. When no file is specified, it is processed as input information. Review log files frequently.
Common parameters:
-f Loop read (often used to view increasing log files) -n< number of lines > shows number of lines (from back to front)
(1) Loop read gradually increasing file contents
Ping 127.0.0.1 > ping.log &
Running in the background: You can use jobs-l to view it, or you can use fg to move it to the foreground.
tail -f ping.log
(Check the log)
14. Touch command
The Linux touch command is used to modify the time properties of a file or directory, including access time and change time. If the file doesn’t exist, the system creates a new one.
Ls -l can display the time record of the file.
grammar
Touch [- delivered acfm per input horsepower] [-d < date/time >] [-r < > reference file or directory] t < date/time > [-] [-- help] [-- version] [...] file or directory
A to change the read time record of the file. M change the time record of the modified file. C If the destination file does not exist, a new file will not be created. This has the same effect as –no-create. F is not used and is reserved for compatibility with other UNIX systems. R uses the reference file to record the time, which is the same as –file. D Set the time and date, which can be used in a variety of formats. T sets the time record of the file in the same format as the DATE instruction. — No-create does not create new files. -help lists the format of the instructions. -version lists version information.
The instance
Use the command “touch” to change the time property of the file” testfile” to the current system time. Enter the following command:
$touch testfile # Modify the time attribute of the file
First, use the ls command to view the properties of the testfile, as shown below:
$ls-l testfile # 16:09-rw-r --r-- 1 HDD HDD 55 2011-08-22 16:09 testfile # 16:09-l testfile # 16:09-l testfile
Execute the command “touch” to modify the file properties, and look at the file’s time properties again, as shown below:
-rw-r--r-- 1 HDD HDD 55 2011-08-22 - $ls-l testfile - $ls-l testfile - $ls-l testfile - $ls-l testfile - $ls-l testfile - $ls-l testfile - $ls-l testfile - $ls-l testfile - $ls-l testfile - $ls-l testfile - $rw-r--r-- 1 HDD HDD 55 2011-08-22 19:53 testfile
When using the “touch” directive, a new blank file is created if the specified file does not exist. For example, in the current directory, use this directive to create a blank file” file” and type:
$touch file # Creates a new blank file named "file"
15. Vim command
Vim is a text editor developed from vi. Code completion, compilation and error jump and other convenient programming functions are particularly rich, widely used in programmers.
Open the file and jump to line 10: Vim +10 filename.txt. Open the file and jump to the first matching line: Vim +/search-term filename.txt. Open the file in read-only mode: vim-r /etc/passwd.
Basically, vi/vim can be divided into three modes, which are Command mode, Insert mode and Last line mode.
Briefly, we can think of these three patterns as the ICONS below:
** The whereis command can only be used to search for program names, and only binaries (parameter -b), man specification files (parameter -m), and source code files (parameter -s). If the parameter is omitted, all information is returned. Whereis and locate are both efficient searches based on a database built into the system, while find traversal a hard drive to find files.
Common parameters:
-b locate the executable file. -M location help file. -s locate source code files. -u Search the default path for files other than executables, source files, and help files.
Example:
(1) Find the relevant files of locate program
whereis locate
(2) Find the source file located
whereis -s locate
(3) Find the help file of LCOATE
whereis -m locate
17. Which command
To search for a file in Linux that you don’t know where it is, you can use the following commands:
Which looks at the location of the executable. Whereis views the location of the file. LOCATE coordinates with the database to view file locations. Find actually searches the hard disk to find the name of the file.
Which searches for the location of a system command on the specified PATH and returns the first search result. Using the which command, you can see if a system command exists, and at which location the command was executed.
Common parameters:
-n Specifies the filename length, which must be greater than or equal to the longest filename in all files.
Example: (1) Check whether ls command exists and which one to execute
which ls
(2) Which
which which
3) Check the CD
Which CD (shows does not exist because CD is a built-in command and which lookup shows a command in PATH)
To view the current PATH configuration:
echo $PATH
Or use env to view all environment variables and their corresponding values
7. Document editing commands
1. The grep command
Powerful text search command, grep(Global Regular Expression Print) Global Regular Expression search.
The way grep works is that it searches for string templates in one or more files. If the template includes Spaces, it must be referenced, and all strings after the template are treated as filenames. The results of the search are sent to standard output without affecting the contents of the original file.
Command format:
grep [option] pattern file|dir
Common parameters:
-- A -- n --after --context --before --context --before -- C --count --count the number of columns that match the style -- I ignore case -- l List only file names whose file contents match the specified style -f reads keywords from the file -n shows the number of lines in the file where the matching content resides -r recursively look up folders
The regular expression for grep:
^ # Anchor line starts with: '^grep' matches all lines starting with grep. $# anchors the end of a line such as: 'grep$' matches all lines ending in grep. . # matches a non-newline character such as 'gr.p' matches gr followed by an arbitrary character, followed by p. * # matches zero or more previous characters such as '*grep' matches all lines followed by one or more Spaces followed by grep. .* # is used together to represent any character. [] # matches a specified range of characters, such as '[Gg]rep' matches Grep and Grep. [^] # matches A character that is not in the specified range, such as '[^ a-fh-z]rep' matches the beginning of A letter that does not contain a-r and t-z, followed by the line of rep. \ [.. \) # marks matching characters, such as '\(love\)', where love is marked as 1. \< # anchors the beginning of a word, such as :'\<grep' matches lines that contain words beginning with grep. \> # anchors the end of a word, such as 'grep\>' to match lines containing words ending in grep. X \{m\} # Repeat the character x m times, such as: '0\{5\}' matches a line containing 5 O's. X \{m,\} # Repeat the character x at least m times, such as: 'o\{5,\}' matches lines with at least 5 o's. X \{m,n\} # Repeat the character x at least m times and no more than n times, such as: 'o\{5,10\}' matches 5--10 lines of o. \w # matches literal and numeric characters, that is, [a-za-z0-9], such as: 'G\w*p' matches G followed by zero or more literal or numeric characters, followed by p. \W #\ W is an inverted form that matches one or more non-word characters, such as the dot period, etc. \b # Word lockers, such as '\bgrep\b' only match grep.
Example:
(1) Find the specified process
ps -ef | grep svn
(2) Find the number of processes specified
ps -ef | grep svn -c
(3) Read the keywords from the file
cat test1.txt | grep -f key.log
(4) Recursively search for rows beginning with grep from the folder, and list only files
grep -lR '^grep' /tmp
(5) Find the non-X switch line content
grep '^[^x]' test.txt
(6) Display the content line containing the Ed or at character
grep -E 'ed|at' test.txt
2. Wc command
WC (Word Count) function to count the number of bytes, words, lines in the specified file, and output the statistical results
Command format:
wc [option] file..
Command parameters:
-C counts bytes -L counts lines -M counts characters -W counts words, where a word is defined as a whitespace, space hop, or newline character delimited string
Example: (1) find the number of lines, words, bytes, file name
wc text.txt
Results:
7 8 70 test.txt
(2) Count the number of lines of the output result
cat test.txt | wc -l
Disk management commands
** CD (changeDirectory) ** CD (changeDirectory)
CD [directory name]
Note: Switch current directory to dirName.
Example: (1) Enter the desired directory
cd /
(2) Enter the directory “HOME”
cd ~
(3) Enter the previous working path
cd -
(4) Use the parameters of the last command as the CD parameter.
cd ! $
2. The df command
Displays disk space usage. If no file name is specified, the available space for all currently mounted file systems will be displayed. By default, disk space is shown in units of 1KB, unless the environment variable POSIXLY\_CORRECT is specified, which is shown in units of 512 bytes:
-A list of all file systems -H displays information in easy to read form -I displays inode information -K block is 1024 bytes -L shows only local disks -T lists file system types
Example: (1) Displays disk usage
df -l
(2) List all file systems and their types in a readable manner
df -haT
3. The du command
The du command also looks at the space used, but unlike the df command, the Linux du command looks at the space used by files and directory disks:
Command format:
Du [option] [file]
Common parameters:
-A shows all file sizes in the directory -K shows file sizes in KB -M shows file sizes in MB -G shows file sizes in GB -H shows file sizes in readable form -S shows total only -C or -- Total In addition to showing the sizes of individual directories or files, It also shows the sum of all directories or files
Example: (1) To display the size of folders and subfolders in a readable manner
du -h scf/
(2) Display all file sizes in the folder in a readable way
du -ah scf/
(3) Display the size of each file or directory to take up disk space, but also the sum of their statistics
du -hc test/ scf/
(4) Output the space used by each subdirectory under the current directory
du -hc --max-depth=1 scf/
4. The ls command
Is the abbreviation of list, through ls command can not only view the files contained in the Linux folder, but also can view the file permissions (including directory, folder, file permissions) to view directory information and so on.
Common parameter collocation:
Ls -a lists all files in the directory, including. Start with the hidden file ls -A listed apart. And.. Sort by file modification time. Sort by file size. Sort by file size. Sort by file size. Display by readable size
Example: (1) Sort in reverse chronological order in an easy-to-read manner and display file details
ls -lhrt
(2) Displays file details in reverse order of size
ls -lrS
(3) list the contents of all the current directory beginning with “t” directory details
ls -l t*
(4) list the absolute path of files (not including hidden files)
ls | sed "s:^:`pwd`/:"
(5) List the absolute path of files (including hidden files)
find $pwd -maxdepth 1 | xargs ls -ld
5. The mkdir command
The mkdir command is used to create a folder.
-m: Set access permissions to the newly created directory, or chmod; -p: Can be a path name. At this time, if some directories in the path do not exist, with this option, the system will automatically establish those directories are not yet, that is, can be established at a time more than one directory.
(1) Create a folder named t in the current working directory
mkdir t
Create directory “test/t1/t” in TMP; if it does not exist, create directory “test/t1/t”;
mkdir -p /tmp/test/t1/t
6. The PWD command
The PWD command is used to view the path to the current working directory.
(1) View the current path
pwd
(2) View the actual path of the soft link
pwd -P
** Deletes one or more subdirectory entries from a directory. Deleting a directory must also have write permission to its parent directory. Note: You cannot delete a non-empty directory
(1) If the parent subdirectory is deleted so that it is also empty, delete it as well:
rmdir -p parent/child/child11
Nine, network communication command
1. The ifconfig command
Ifconfig is used to view and configure the network interface of a Linux system. View all network interfaces and their status: ifconfig-a. Start or stop an interface with the up and down commands: ifconfig eth0 up and ifconfig eth0 down.
2. The iptables command
Iptables, is a command-line tool for configuring Linux kernel firewalls. The function is very powerful, for our development, the main master how to open the port. Such as:
Iptables -i input-s 192.168.1.101-p TCP –dport 80-j REJECT packets from 192.168.1.101
Open port 80, because this is the port that the Web uses externally
iptables -A INPUT -p tcp --dport 80 -j ACCEP
Also, be sure to use the iptables save command to save. Otherwise, the configured rules will be lost after the server is restarted.
3. The netstat command
The Linux netstat command is used to display network status.
Use the netstat directive to give you access to the entire Linux network.
grammar
Netstat [-accefghilmnnoprstuvvwx][-a < network type >][-- IP]
-a or -all displays all sockets in the connection. -A< network type > or — < network type > lists the relevant addresses in the wires of that network type. -c or — continuous lists the network state continuously. -c or — cache displays cache information for the router configuration. -e or -extend displays other information about the network. -f or -fib shows fib. -g or — groups displays the membership list of multiple broadcast feature groups. -h or -help online help. -i or — interfaces display the network interface information form. -l or — listening displays the Socket of the server under monitoring. -m or — masquerade displays a disguised network connection. -n or -numeric uses IP addresses directly, not through the domain name server. -n or — netlink or — symbolic displays the symbolic connection name of a network hardware peripheral. -o or — timers displays the timer. -p or — programs display the program ID and program name of the Socket being used. -r or — route displays Routing Table. -s or — statistice displays statistics of network working information. -t or -tcp shows the connection status of the TCP transport protocol. -u or -udp displays the connection status of the UDP transport protocol. -v or -verbose shows the execution of the instruction. -v or -version displays version information. -w or — raw shows the connection status of the RAW transport protocol. -x or — UNIX This parameter has the same effect as specifying the “-a UNIX” parameter. — IP or — inet This parameter has the same effect as specifying the “-a inet” parameter.
The instance
How do I check which ports are open?
[root@centos6 ~ 13:20 #55]# netstat -lnp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program Name TCP 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1035/ SSHD TCP 0 0: ::22 ::* LISTEN 1035/ SSHD UDP 0 0 0 0.0.0.0:68 0.0.0.0:* 931/dhclient Active Unix DomainSockets (Only Servers) Proto RefCNT Flags Type State I-Node PID/Program name Path unix 2 [ ACC ] STREAM LISTENING 6825 1/init @/com/ubuntu/upstart unix 2 [ ACC ] STREAM LISTENING 8429 1003/dbus-daemon /var/run/dbus/system_bus_socket
How to check the network connection status?
[root@centos6 ~ 13:22 #58]# netstat -an Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State TCP 0 0 0.0.0.0:22 0.0.0.0:* LISTEN TCP 0 0 192.168.147.130:22 192.168.147.131:23893 Established TCP 0 0: ::22 :::* Listen UDP 0 0 0.0.0.0:68 0.0.0.0:*
How to count the current process connections in the system?
Type the command netstat – an | grep ESTABLISHED | wc -l. The output is 177. There are 177 connections.
Use the netstat command with other commands to count all ESTABLISHED state links to port 80 by source IP.
Strictly speaking, this topic tests the use of AWK.
First of all, using netstat – an | grep ESTABLISHED command. The results are as follows:
TCP 0 0 120.27.146.122:80 113.65.18.33:62721 TCP 0 0 120.27.146.122:80 27.43.83.115:47148 ESTABLISHED TCP 0 0 120.27.146.122:58838 106.39.162.96:443 ESTABLISHED TCP 0 0 120.27.146.122:52304 203.208.40.121:443 ESTABLISHED TCP 0 0 120.27.146.122:33194 203.208.40.122:443 ESTABLISHED TCP 0 0 120.27.146.122:53758 101.37.183.144:443 ESTABLISHED TCP 0 0 ESTABLISHED 23.105.193.30 120.27.146.122:27017:50556
4. The ping command
The Linux ping command is used to detect the host.
The ping command uses the ICMP transport protocol to send a message requesting a response. If there is no problem with the remote host’s network function, the message is returned and the host is told that it is functioning normally.
Specifies the number of times a packet is received
ping -c 2 www.baidu.com
5. Telnet command
The Linux Telnet command is used for remote login.
Execute the Telnet instruction to start the terminal operation, and log in the remote host.
grammar
8 acdeffklrx Telnet [-] [- b < > host alias] [-e < out > characters] [- k < domain name >] [-l < user name >] [-n > < log file] [-s < service type >] [-x < > certification form] [host name or IP address < > communication port]
-8 allows the use of 8-bit data, including input and output. -A attempts to automatically log into the remote system. -b< host alias > uses the alias to specify the remote host name. -c does not read.telnetrc files in user-specific directories. -D Start debug mode. -e< disengage character > sets disengage character. -e Filters out stray characters. -f This parameter has the same effect as specifying the “-f” parameter. -f When authenticating with Kerberos V5, add this parameter to upload authentication data from the local host to the remote host. -k< domain name > When using Kerberos authentication, add this parameter to make the remote host use the specified domain name instead of the domain name of the host. -k does not automatically log in to the remote host. -l< user name > Specifies the user name to log into the remote host. -l allows 8-bit data to be output. -n< record file > specifies file record related information. -r uses a user interface similar to the rlogin directive. -s < service type > Set IP TOS information required for Telnet connection. -x assumes the host has support for data encryption, and uses it. -x < Authentication form > closes the specified authentication form.
Instance logs in to the remote host
IP 192.168.0.5 Telnet 192.168.0.5
**, system management command **
1. The date command
Displays or sets the date and time of the system.
Command parameters:
-d< string > Displays the date and time to which the string refers. Strings must be preceded by double quotation marks. -s< string > to set date and time according to string. Strings must be preceded by double quotation marks. -u shows GMT. %H hours (00-23) %I hours (00-12) %M minutes (represented by 00-59) %s total number of seconds. Starting time is 1970-01-01 00:00:00 UTC. An abbreviation for %S seconds (in local usage) %a week. %A full name of the week. %d date (represented by 01-31). %D Date (including year, month and day). %m months (in terms of 01-12). %y year (in terms of 00-99). %Y year (represented in four digits).
Example: (1) Display the next day
Date +%Y%m%d --date="+1 day
(2) Use of -D parameter
Date -d "nov 22" date -d "nov 22" date -d "next Monday" date -d "next Monday" date -d "next week" date -d "nov 22" date -d "next week" date -d "next Monday" date -d "next week" date -d "next week" date -d "next week" date -d "next week" date -d "next week" date -d "next week" date -d "next week +%Y%m% D Date -d tomorrow +%Y%m% D Date -d last day +%Y%m% D Date -d tomorrow +%Y%m% D Date -d last day +%Y%m% D Date -d tomorrow +%Y%m% D Date -d last day +%Y%m% D Date -d tomorrow +%Y%m% D Date -d last day Date -d yesterday +%Y%m%d date -d last-month +%Y%m date -d next-month +%Y%m
2. The free command
Displays system memory usage, including physical memory, interactive area memory (swap), and kernel buffer memory.
Command parameters:
-b shows memory usage in bytes -k shows memory usage in kilobytes -m shows memory usage in megabytes -g shows memory usage in gigabytes -s< interval seconds > continues to show memory -t shows total memory usage
Example: (1) Display memory usage
free
free -k
free -m
(2) Display memory usage information in the form of sum
free -t
(3) Periodically query memory usage
free -s 10
3. Kill command
Sends the specified signal to the corresponding process. No type specified will send SIGTERM (15) to terminate the specified process. If the program cannot be terminated, use the “-kill” parameter, which sends a signal of SIGKILL(9), will force the end of the process, use the ps command or the jobs command to see the process number. The root user will affect the user’s process, and the non-root user can only affect his or her own process.
Common parameters:
-l signal, if no signal number parameter is used, the "-l" parameter will list all signal names -a, when processing the current process, does not limit the relationship between command name and process number -p specifies kill command only prints the process number of the associated process, and does not send any signal -s specifies send signal -u specifies the user
(1) Use ps to find the process pro1, then use kill to kill
kill -9 $(ps -ef | grep pro1)
4. The ps command
Ps (process status), which is used to view the status of the current running process, once view, if you need dynamic continuous results use top
Processes on Linux have five states: 1. Running (running or waiting in a run queue) 2. Interrupt (in hibernation, blocked, waiting for a condition to form or to receive a signal) Uninterruptible (does not wake up and cannot run after receiving a signal, and the process must wait until an interrupt occurs) Dead (the process is terminated, but the process descriptor exists until the parent process calls wait4() and releases it). Stop (the process stops running after receiving SIGSTOP, SIGSTP, SIGTIN, SIGTOU signals)
The PS tool identifies the five status codes of the process:
D non-interruptible uninterruptible sleep (usually IO) R running runnable (on the run queue) S interrupt sleeping T stop traced the or stopped Z zombie a Defunct (" zombie ") in the process
Command parameters:
-A shows all processes A shows all processes -A shows all processes on the same terminal C shows the real name of the process E shows the environment variable F shows the relationship between processes R shows the current terminal running processes -AUX shows all processes containing other uses
Example: (1) Display all current process environment variables and inter-process relationships
ps -ef
(2) Display all current processes
ps -A
(3) Combined with grep to find a process
ps -aux | grep apache
(4) Find out the PID number associated with cron and syslog
ps aux | grep '(cron|syslog)'
5. The RPM command
The Linux RPM command is used to manage the suite.
RPM (RedHat Package Manager) was originally used by the Red Hat Linux distribution to manage Linux packages. It was popular because it was GPL-compliant and powerful and convenient. Increasingly, it was adopted by other distributions. The emergence of RPM suite management makes Linux easy to install, upgrade, and indirectly improve the applicability of Linux.
# to check the system comes with the JDK RPM - qa | grep JDK system at # delete JDK RPM -e -- nodeps view the JDK display RPM data # JDK installation - the ivh JDK 7 u80 - Linux - x64. RPM
6. The top command
Displays information about the process currently running on the system, including process ID, memory usage, CPU usage, etc
Common parameters:
-c display full process command -s secret mode -p < process number > specifies process display -n < number of times > loop display number
Example:
Top-14:06:23 up 70 days, 16:44, 2 users, load average: 1.25, 1.32, 1.35 206 total, 1 running, 205 sleeping, 0 stopped, 0 zombie Cpu(s): Sy us 5.9%, 3.4%, 0.0% ni, 90.4% id, wa, 0.0%, 0.0% hi 0.2% si, 0.0% st Mem: 32949016k total, 14411180k used, 18537836k free, 169884k buffers Swap: 32764556k total, 0k used, 32764556k free, 3612636k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 28894 root 22 0 1501m 405m 10m S 52.2 1.3 2534:16 java
The first five lines are the overall statistics area of the current system condition.
The first line, the task queue information, and the execution result of the uptime command, the specific parameter description is as follows:
14:06:23 — Current system time
Up 70 days, 16:44 — The system has been running for 70 days, 16 hours and 44 minutes (during which time the system has not been rebooted).
2 users – There are currently 2 users logged into the system
LOAD average: 1.15, 1.42, 1.44 — The last three numbers after LOAD average are 1 minute, 5 minute, and 15 minute respectively.
The Load Average data is the number of active processes checked every 5 seconds and calculated by a specific algorithm. If you divide this number by the number of logical CPUs, anything above 5 indicates that the system is overloaded.
In the second line, Tasks – Tasks (processes) are described as follows:
There are 206 processes in the system, including 1 running process, 205 sleeping process, 0 stoped process, 0 zombie process.
The third line, CPU state information, the specific attributes are described as follows:
5.9%us - Percentage of CPU consumed by user space. 3.4% SY -- Percentage of kernel space used by CPU. 0.0% ni -- Percentage of CPU used by processes that have changed priority 90.4% id -- Percentage of idle CPU 0.0% wa -- IO Wait -- Percentage of CPU used by Hardware IRQ 0.2%si -- Percentage of CPU consumed by Software Interrupts
Note: The CPU usage ratio here is different from the Windows concept, so you need to understand the Linux system user space and kernel space knowledge!
The fourth line, memory state, details as follows:
32949016K total -- Total physical memory (32GB) 14411180K used -- Total memory in use (14GB) 18537836K free -- Total free memory (18GB) 169884K buffers -- The amount of memory cached (169 m)
In line 5, swap swaps partition information. The specific information is as follows:
0k used -- total amount of swap used (0k) 32764556k free -- total amount of free swap (32GB) 3612636k cached -- total amount of cached swap (3.6GB)
Line six, blank line.
The seventh line follows: the status monitoring of each process (task). The item column information is described as follows:
PID -- process id USER -- process owner PR -- process priority NI -- nice value Negative values denote high priority, and positive values denote low priority VIRT - the total amount of virtual memory used by the process, in kilobytes. VIRT=SWAP+RES RES - The amount of physical memory used by the process that has not been swapped out, in kilobytes. RES=CODE+DATA SHR -- Shared memory size, in KB S -- process state. D= Uninterruptible Sleep R= Run S= Sleep T= Track/Stop Z= Zombot Process %CPU - Percentage of CPU TIME used since last update % Mem - Percentage of physical memory used by the process Time + - Total CPU TIME used by the process, Unit 1/100 second COMMAND - process name (COMMAND name/COMMAND line)
Top interactive command
H display top interactive command help information c togdle display command name and full command line m sort by memory usage P sort by CPU percentage size T sort by time/accumulated time W write current Settings to ~/.toprc file o or o change the order of display items
7. Yum command
Yum (Yellow Dog Updater, Modified) is a Shell front-end package manager in Fedora and RedHat as well as SUSE.
Based on the RPM package management, it can automatically download and install the RPM package from the specified server, automatically handle the dependency relationship, and install all the dependent software packages at one time, without tedious download and install again.
YUM provides commands to find, install, and delete a particular package, a group of packages, or even all packages, and the commands are concise and easy to remember.
1. Make a list of all updatable software. Yum install
The instance installs PAM – DEVEL
[root@www ~]# yum install pam-devel
Back up the compression command
1. Bzip2 command
Create a compressed *.bz2 file: bzip2 test.txt. Unzip *.bz2 file: bzip2-d test.txt.bz2.
2. The gzip command
Create a compressed *.gz file: gzip test.txt. Unzip the *. Gz file: gzip-d test.txt.gz. Show the compression ratio: gzip -l *.gz.
3. The tar command
Used to compress and extract files. Tar itself does not have the compression function, only has the packaging function, the compression and decompression is done by calling other functions.
Understand two concepts: packaging and compression. Packaging means turning a bunch of files or directories into a single file; Compression is a large file through some compression algorithms into a small file
Common parameters:
-C creates new compressed files -F specifies compressed files -R adds files to already compressed packages -U adds modified and existing files to compressed packages -X extracts files from compressed packages -T shows the contents of compressed files -Z supports gzip compression -J supports bzip2 compression -Z Support COMPRESS file - V display operation process
About gzip and bzip2 compression:
Gzip instance: compressed gzip fileName. Tar. Gz and. TGZ extract: gunzip fileName. Gz or gzip - d fileName. Gz corresponds to: Tar ZCVF filename.tar.gz tar ZXVF filename.tar.gz bz2: bzip2-z filename.tar.bz2 Tar JCVF filename.tar.gz tar JXVF filename.tar.bz2 tar JXVF filename.tar.bz2
Example: (1) package all the files into tar
Tar-cvf log.tar 1.log,2.log or tar-cvf log.*
(2) Pack all files and directories under /etc to the specified directory, and use GZ compression
tar -zcvf /tmp/etc.tar.gz /etc
(3) View the contents of the newly packaged file (must add Z, because it is compressed using gzip)
tar -ztvf /tmp/etc.tar.gz
/etc, but not /home/dmtsaI
tar --exclude /home/dmtsai -zcvf myfile.tar.gz /home/* /etc
4. Unzip command
· Unzip *.zip file: Unzip test.zip. · View the contents of the *.zip file: unzip-l jasper.zip.
Author: eet –
Link: ttps://www.eet-china.com/mp/a34260.html
Source: eet-china.com
supplement
How to learn Java, share two universal learning databases:
1. Books:
codeGoogler/ProgramBooks
2. Video Tutorials:
SpringBoot, Spring, MyBatis, Redis, RabbitMQ, SpringCloud, High Concurrency (continuous update)
Brush 200 questions to the top of the headlines, I float!