Basic introduction to Linux common command shell

2.1 Powerful and easy to use Shell
******************************************** **************************************************** ************
Generally speaking, computer hardware is composed of arithmetic unit, controller, memory, input/output device, etc. The thing that works together is the system kernel. The kernel of the Linux system is responsible for completing management tasks such as allocation and scheduling of hardware resources. It can be seen that the system kernel is too important for the normal operation of the computer, so it is generally not recommended to edit the parameters in the kernel directly, but to allow users to manage the computer through programs or services developed based on the system call interface to Meet the needs of daily work

Shell is one such command-line tool. Shell (also known as terminal or shell) acts as a translator between people and the kernel (hardware). The user "tells" the terminal some commands, and it will call the corresponding program service to complete certain tasks. The default terminal used by many mainstream Linux systems, including Red Hat, is the Bash (Bourne-Again SHell) interpreter. The mainstream Linux system chooses the Bash interpreter as the command line terminal mainly has the following four advantages:
➢ Use the up and down arrow keys to call up the Linux commands that have been executed in the past;
➢ Only enter the first few digits of a command or parameter and use the Tab key to complete it;
➢ Has a powerful batch script;
➢ Has a practical environment variable function.
**************************************************** **************************************************** ******

 

2.2 Execute the view help command
************************************************ **************************************************** ************

Command name [Command parameters] [Command object]
Long format and short format of command parameters
Long format man --help
Short format man -h

Common keys and uses in the man command
Spacebar to turn down a page
PaGe down Turn down a page
PaGe up Turn up a page
home Go directly to the first page
end Go directly to the last page
/ Search for a keyword from top to bottom, such as "/ linux"
? Search for a certain keyword from bottom to top, such as "?linux"
n Locate the next searched keyword
N Locate the previous searched keyword
q Exit the help file
********* **************************************************** ************************************************

 

2.3 Common system work commands
************************************************ **************************************************** **********
1. The echo command is used to input a string or variable extracted value in the terminal, the format is "echo [string | $variable]"

2. The date command is used to display and set the time or date of the system. You only need to enter the parameters starting with "+" in the date command, and the system time or date can be output according to the specified format.
➢ Parameters and functions of the date command
Parameter function
%t Tab [tab]
%H hour (00~23)
%I hour (00~12)
%M minute (00~59)
%S second (00~59)
%j day of the year
[root@linuxprobe ~]# date "+%Y-%m-%d %H:%M:%S"
Y year m month d day
3. The reboot command is used to restart the system

4. The poweroff command is used to shut down the system

5. The wget command is used to download network files in the terminal, the format is: wget [parameters] Download address
➢ Parameters and functions of the wget command
-b background download mode
-P download to the specified directory
-t maximum number of attempts
-c breakpoint continue Pass
-p to download all resources on the page, including pictures, videos, etc.
-r to download recursively


6. The ps command is used to view the process status in the system, the format is: ps [parameters]
➢ Parameters and functions of the ps command (ps -aux)
-a Display all processes (including processes of other users)
-u User and other details Information
-x Displays processes without a controlling terminal
In Linux systems, there are 5 common process states, namely running, interrupted, uninterruptible, dead and stopped
➢ R (running): The process is running or waiting in the run queue.
➢ S (interrupt): The process is dormant. When a certain condition is formed or when a signal is received, it will leave this state.
➢ D (Uninterruptible): The process does not respond to system asynchronous signals, and it cannot be removed even with the kill command. break.
➢ Z (Zombie): The process has terminated, but the process descriptor still exists, until the parent process calls the wait4() system function and releases the process
➢ T (Stop): The process stops running after receiving the stop signal

7. The top command is used to dynamically monitor information such as process activity and system load. Format: top
➢ Line 1: system time, running time, number of login terminals, and system load
(the three values ​​are 1 minute, 5 minutes, 15 Average value within minutes, lower value means lower load).
➢ Line 2: The total number of processes, the number of running processes, the number of sleeping processes, the number of stopped processes, and the number of dead processes.
➢ Line 3: The percentage of resources occupied by users, the percentage of resources occupied by the system kernel, the percentage of process resources whose priorities have been changed, the percentage of idle resources, etc.
➢ Line 4: total physical memory, memory usage, free memory, and memory used as kernel cache.
➢ Line 5: total virtual memory, virtual memory usage, virtual memory free, and preloaded memory.
Note: The data in line 3 are all CPU data and displayed in percentage format, for example, 97.1id means 97.1% of CPU resources are idle

8. The pidof command is used to query the PID value of a specified service process. The format is: pidof [Parameter] [Service Name]
The process number value (PID) of each process is unique, so PID can be used to distinguish different ones. Process, for example: pidof sshd 2156

9. The kill command is used to terminate a service process with a specified PID, the format is: kill [parameter] [process PID], for example: kill 2156

10. The killall command is used to terminate all processes corresponding to a service with a specified name. The format is: killall [parameter] [service name/process name]
Generally speaking, the service program of complex software will have multiple processes cooperating for the user Provide service, such as
[root@linuxprobe ~]# pidof httpd
13581 13580 13579 13578 13577 13576
[root@linuxprobe ~]# killall httpd
[root@linuxprobe ~]# pidof httpd
[root@linuxprobe ~]#
****** **************************************************** ****************************************************

 

2.4 System Status Detection Command
********************************************* **************************************************** **********
As a qualified operation and maintenance personnel, if you want to understand the Linux server faster and better, you must have the ability to quickly view the running status of the Linux system, so I will explain and explain one by one. Network card network, system kernel, system load, memory usage, the number of currently enabled terminals, historical login records, command execution records, and how to use related commands such as rescue diagnosis. These commands are super practical, please study and master them carefully.

1. The ifconfig command is used to obtain information such as network card configuration and network status, format: ifconfig [network device] [parameter]

2. The uname command is used to view information such as the system kernel and system version. Format: uname[-a]
When using the uname command, the -a parameter is usually fixed to view the kernel name, host name, and kernel of the current system. Information such as release version, node name, system time, hardware name, hardware platform, processor type, and operating system name.
[root@linuxprobe ~]# uname -a
Linux linuxprobe.com 3.10.0-123.el7.x86_64 #1 SMP Mon May 5 11:16:57 EDT 2017
x86_64 x86_64 x86_64 GNU/Linux
If you want to view the details of the current system version information, you need to check the redhat-release file
[root@linuxprobe ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.0 (Maipo)

3. The uptime command is used to view the load information of the system. The format:
the average load value of uptime refers to the pressure of the system in the last 1 minute, 5 minutes and 15 minutes (the information part in bold below); the lower the load value, the more Well, try not to exceed 1 for a long time, and not to exceed 5 in a production environment.
[root@linuxprobe ~]# uptime
22:49:55 up 10 min, 2 users, load average: 0.01, 0.19, 0.18

4. The free command is used to display the memory usage information in the current system. The format is: free [-h]
[root@server70 ~]# free -h
total amount of memory used and available amount of memory shared by the process
total used free shared buff /cache available
Mem: 992M 98M 771M 6.6M 121M 748M
Swap: 923M 0B 923M

5. The who command is used to view the information of the user terminal currently logged in to the host, in the format: who
[root@server70 ~]# Who
logs in the user name The terminal device logs in to the system
root pts/0 2018-04-29 14:01 ( 192.168.100.1)

6. The last command is used to view the login records of all systems, format: last [parameter]

7. The history command is used to display the executed commands. The format is: history [-c]. The default command is 1000 lines. If 1000 is not enough, you can also modify the value of the HISTSIZE variable in the /etc/profile file. History commands will be saved to the .bash_history file in the user's home directory. history -c clears the history of linux commands executed by the current user on this machine;

8. The sosreport command is used to collect system configuration and architecture information and output diagnostic documents;
******************************** **************************************************** ************************

 

2.5 Working directory switching command
******************************************** **************************************************** **********
1. The pwd command is used to display the current working directory of the user, the format is: pwd

2. The cd command is used to switch the working path, the format is: cd

3. The ls command is used to display the file information in the directory, the format is: ls [Options] [Files]
Common options: -A Show hidden files
-d Display directory attributes (used together with -l)
-l Display file/directory details
-h display easy-to-read units (use with -l)
-R recursively display
********************************* **************************************************** *********************

 


2.6 Text file editing commands
************************************************ **************************************************** **********
1. The cat command is used to view plain text files (less content), the format is: cat [options] [files], -n displays the line number

2. The more command is used to view plain text files (with more content), the format is: more [options] [files]

3. The head command is used to view the first N lines of a plain text document. The format is: head [options] [files], for example: head -n 20 /etc/passwd, if no lines are added, 10 lines are displayed by default

4. The tr command is used to replace the characters in the text file, the format is: tr [original character] [target character]

5. The wc command is used to count the number of lines, words and bytes of the specified text, the format is: wc [parameter] text,
common options: -l count the number of lines
-w only display the number of words
-c only display the number of bytes
* **************************************************** **************************************************** *****

 

2.7 File Directory Management Command
******************************************** **************************************************** **********
1. The touch command is used to create a blank file or set the time of the file, the format is: touch【Option】【File】
Modify time option: -a only modify the read time
-m only Modification time
-d at the same time -a, -m modification

2. The mkdir command is used to create a blank directory, the format is: mkdir [option] directory, common options: -p recursively create -m to create a directory while setting the permissions of the directory;

3. The cp command is used to copy files or directories, the format is: cp [options] source file target file,
common options: -p retain the attributes of the original file (in cp, the attribution will change, -p will retain the original
-d If the object is a "linked file", keep the attributes of the "linked file" -r
recursive continuous replication (for directories)
-a is equivalent to -pdr (p, d, r are the above parameters)

4. The mv command is used to cut files or re-command files, the format is: mv [options] source file [target directory/target file name]

5. The rm command is used to delete a file or directory, the format is: rm [option] file,
common options: -r delete directory
-f force delete without asking

**********************************************************************************************************

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325234364&siteId=291194637