Linux常用命令_时刻更新
前言
Github:https://github.com/HealerJean
1、帮助指令
1.1、–-help
:显示shell内部的命令帮助信息
--help
命令用于显示shell内部的帮助信息。help命令只能显示shell内部的命令帮助信息。而对于外部命令的帮助信息只能使用man或者info命令查看。
grep --help
root@healerjean:~# grep --help
Usage: grep [OPTION]... PATTERN [FILE]...
Search for PATTERN in each FILE or standard input.
PATTERN is, by default, a basic regular expression (BRE).
Example: grep -i 'hello world' menu.h main.c
Regexp selection and interpretation:
-E, --extended-regexp PATTERN is an extended regular expression (ERE)
-F, --fixed-strings PATTERN is a set of newline-separated strings
-G, --basic-regexp PATTERN is a basic regular expression (BRE)
-P, --perl-regexp PATTERN is a Perl regular expression
-e, --regexp=PATTERN use PATTERN for matching
-f, --file=FILE obtain PATTERN from FILE
-i, --ignore-case ignore case distinctions
-w, --word-regexp force PATTERN to match only whole words
-x, --line-regexp force PATTERN to match only whole lines
-z, --null-data a data line ends in 0 byte, not newline
Miscellaneous:
-s, --no-messages suppress error messages
-v, --invert-match select non-matching lines
-V, --version display version information and exit
--help display this help text and exit
Output control:
-m, --max-count=NUM stop after NUM matches
-b, --byte-offset print the byte offset with output lines
-n, --line-number print line number with output lines
--line-buffered flush output on every line
-H, --with-filename print the file name for each match
-h, --no-filename suppress the file name prefix on output
--label=LABEL use LABEL as the standard input file name prefix
-o, --only-matching show only the part of a line matching PATTERN
-q, --quiet, --silent suppress all normal output
--binary-files=TYPE assume that binary files are TYPE;
TYPE is 'binary', 'text', or 'without-match'
-a, --text equivalent to --binary-files=text
-I equivalent to --binary-files=without-match
-d, --directories=ACTION how to handle directories;
ACTION is 'read', 'recurse', or 'skip'
-D, --devices=ACTION how to handle devices, FIFOs and sockets;
ACTION is 'read' or 'skip'
-r, --recursive like --directories=recurse
-R, --dereference-recursive likewise, but follow all symlinks
--include=FILE_PATTERN search only files that match FILE_PATTERN
--exclude=FILE_PATTERN skip files and directories matching FILE_PATTERN
--exclude-from=FILE skip files matching any file pattern from FILE
--exclude-dir=PATTERN directories that match PATTERN will be skipped.
-L, --files-without-match print only names of FILEs containing no match
-l, --files-with-matches print only names of FILEs containing matches
-c, --count print only a count of matching lines per FILE
-T, --initial-tab make tabs line up (if needed)
-Z, --null print 0 byte after FILE name
Context control:
-B, --before-context=NUM print NUM lines of leading context
-A, --after-context=NUM print NUM lines of trailing context
-C, --context=NUM print NUM lines of output context
-NUM same as --context=NUM
--color[=WHEN],
--colour[=WHEN] use markers to highlight the matching strings;
WHEN is 'always', 'never', or 'auto'
-U, --binary do not strip CR characters at EOL (MSDOS/Windows)
-u, --unix-byte-offsets report offsets as if CRs were not there
(MSDOS/Windows)
'egrep' means 'grep -E'. 'fgrep' means 'grep -F'.
Direct invocation as either 'egrep' or 'fgrep' is deprecated.
When FILE is -, read standard input. With no FILE, read . if a command-line
-r is given, - otherwise. If fewer than two FILEs are given, assume -h.
Exit status is 0 if any line is selected, 1 otherwise;
if any error occurs and -q is not given, the exit status is 2.
Report bugs to: bug-grep@gnu.org
GNU grep home page: <http://www.gnu.org/software/grep/>
General help using GNU software: <http://www.gnu.org/gethelp/>
root@healerjean:~#
1.2、man
:查看命令帮助(手册页丰富)
man
命令,manual的简写,查看Linux中的指令帮助、配置文件帮助和编程帮助等信息。man是在程序安装的时候安装的帮助文档可以在系统的目录下找到,如果软件有配套的页面,就可以使用man来查找。如果删除了某个手册页文件时man就无法显示了。man命令显示的帮助信息要更加丰富,它比命令的help选项多了命令的用法示例、命令的描述等内容
man grep
1.2.1、浏览技巧
1.2.1.1、滚动一行:Enter键
1.2.1.2、翻一页:空格键
1.2.1.3、查询某个内容: 例如: /a ,查询a这个单词的位置
1.2.1.4、退出 :q
GREP(1) General Commands Manual GREP(1)
NAME
grep, egrep, fgrep, rgrep - print lines matching a pattern
SYNOPSIS
grep [OPTIONS] PATTERN [FILE...]
grep [OPTIONS] [-e PATTERN]... [-f FILE]... [FILE...]
DESCRIPTION
grep searches the named input FILEs for lines containing a match to the given PATTERN. If no files are specified, or if the file “-” is given, grep searches standard input. By
default, grep prints the matching lines.
In addition, the variant programs egrep, fgrep and rgrep are the same as grep -E, grep -F, and grep -r, respectively. These variants are deprecated, but are provided for backward
compatibility.
OPTIONS
Generic Program Information
--help Output a usage message and exit.
-V, --version
Output the version number of grep and exit.
Matcher Selection
-E, --extended-regexp
Interpret PATTERN as an extended regular expression (ERE, see below).
-F, --fixed-strings
Interpret PATTERN as a list of fixed strings (instead of regular expressions), separated by newlines, any of which is to be matched.
-G, --basic-regexp
Interpret PATTERN as a basic regular expression (BRE, see below). This is the default.
-P, --perl-regexp
Interpret the pattern as a Perl-compatible regular expression (PCRE). This is highly experimental and grep -P may warn of unimplemented features.
Matching Control
-e PATTERN, --regexp=PATTERN
Use PATTERN as the pattern. If this option is used multiple times or is combined with the -f (--file) option, search for all patterns given. This option can be used to
protect a pattern beginning with “-”.
-f FILE, --file=FILE
Obtain patterns from FILE, one per line. If this option is used multiple times or is combined with the -e (--regexp) option, search for all patterns given. The empty file
contains zero patterns, and therefore matches nothing.
-i, --ignore-case
Ignore case distinctions in both the PATTERN and the input files.
-v, --invert-match
Invert the sense of matching, to select non-matching lines.
-w, --word-regexp
Select only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or preceded by a
non-word constituent character. Similarly, it must be either at the end of the line or followed by a non-word constituent character. Word-constituent characters are
letters, digits, and the underscore.
-x, --line-regexp
Select only those matches that exactly match the whole line. For a regular expression pattern, this is like parenthesizing the pattern and then surrounding it with ^ and
$.
-y Obsolete synonym for -i.
General Output Control
-c, --count
Suppress normal output; instead print a count of matching lines for each input file. With the -v, --invert-match option (see below), count non-matching lines.
--color[=WHEN], --colour[=WHEN]
Surround the matched (non-empty) strings, matching lines, context lines, file names, line numbers, byte offsets, and separators (for fields and groups of context lines)
with escape sequences to display them in color on the terminal. The colors are defined by the environment variable GREP_COLORS. The deprecated environment variable
GREP_COLOR is still supported, but its setting does not have priority. WHEN is never, always, or auto.
-L, --files-without-match
Suppress normal output; instead print the name of each input file from which no output would normally have been printed. The scanning will stop on the first match.
-l, --files-with-matches
Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match.
-m NUM, --max-count=NUM
Stop reading a file after NUM matching lines. If the input is standard input from a regular file, and NUM matching lines are output, grep ensures that the standard input
is positioned to just after the last matching line before exiting, regardless of the presence of trailing context lines. This enables a calling process to resume a search.
When grep stops after NUM matching lines, it outputs any trailing context lines. When the -c or --count option is also used, grep does not output a count greater than NUM.
When the -v or --invert-match option is also used, grep stops after outputting NUM non-matching lines.
-o, --only-matching
Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line.
-q, --quiet, --silent
Quiet; do not write anything to standard output. Exit immediately with zero status if any match is found, even if an error was detected. Also see the -s or --no-messages
option.
-s, --no-messages
Suppress error messages about nonexistent or unreadable files.
Output Line Prefix Control
-b, --byte-offset
Print the 0-based byte offset within the input file before each line of output. If -o (--only-matching) is specified, print the offset of the matching part itself.
-H, --with-filename
Print the file name for each match. This is the default when there is more than one file to search.
-h, --no-filename
Suppress the prefixing of file names on output. This is the default when there is only one file (or only standard input) to search.
--label=LABEL
Display input actually coming from standard input as input coming from file LABEL. This is especially useful when implementing tools like zgrep, e.g., gzip -cd foo.gz |
grep --label=foo -H something. See also the -H option.
-n, --line-number
Prefix each line of output with the 1-based line number within its input file.
-T, --initial-tab
Make sure that the first character of actual line content lies on a tab stop, so that the alignment of tabs looks normal. This is useful with options that prefix their
output to the actual content: -H,-n, and -b. In order to improve the probability that lines from a single file will all start at the same column, this also causes the line
number and byte offset (if present) to be printed in a minimum size field width.
-u, --unix-byte-offsets
Report Unix-style byte offsets. This switch causes grep to report byte offsets as if the file were a Unix-style text file, i.e., with CR characters stripped off. This
will produce results identical to running grep on a Unix machine. This option has no effect unless -b option is also used; it has no effect on platforms other than MS-DOS
and MS-Windows.
-Z, --null
Output a zero byte (the ASCII NUL character) instead of the character that normally follows a file name. For example, grep -lZ outputs a zero byte after each file name
instead of the usual newline. This option makes the output unambiguous, even in the presence of file names containing unusual characters like newlines. This option can be
used with commands like find -print0, perl -0, sort -z, and xargs -0 to process arbitrary file names, even those that contain newline characters.
Context Line Control
-A NUM, --after-context=NUM
Print NUM lines of trailing context after matching lines. Places a line containing a group separator (--) between contiguous groups of matches. With the -o or
--only-matching option, this has no effect and a warning is given.
-B NUM, --before-context=NUM
Print NUM lines of leading context before matching lines. Places a line containing a group separator (--) between contiguous groups of matches. With the -o or
--only-matching option, this has no effect and a warning is given.
-C NUM, -NUM, --context=NUM
Print NUM lines of output context. Places a line containing a group separator (--) between contiguous groups of matches. With the -o or --only-matching option, this has
no effect and a warning is given.
File and Directory Selection
-a, --text
Process a binary file as if it were text; this is equivalent to the --binary-files=text option.
--binary-files=TYPE
If the first few bytes of a file indicate that the file contains binary data, assume that the file is of type TYPE. By default, TYPE is binary, and grep normally outputs
either a one-line message saying that a binary file matches, or no message if there is no match. If TYPE is without-match, grep assumes that a binary file does not match;
this is equivalent to the -I option. If TYPE is text, grep processes a binary file as if it were text; this is equivalent to the -a option. When processing binary data,
grep may treat non-text bytes as line terminators; for example, the pattern '.' (period) might not match a null byte, as the null byte might be treated as a line
terminator. Warning: grep --binary-files=text might output binary garbage, which can have nasty side effects if the output is a terminal and if the terminal driver
interprets some of it as commands.
-D ACTION, --devices=ACTION
If an input file is a device, FIFO or socket, use ACTION to process it. By default, ACTION is read, which means that devices are read just as if they were ordinary files.
If ACTION is skip, devices are silently skipped.
-d ACTION, --directories=ACTION
If an input file is a directory, use ACTION to process it. By default, ACTION is read, i.e., read directories just as if they were ordinary files. If ACTION is skip,
silently skip directories. If ACTION is recurse, read all files under each directory, recursively, following symbolic links only if they are on the command line. This is
equivalent to the -r option.
--exclude=GLOB
Skip files whose base name matches GLOB (using wildcard matching). A file-name glob can use *, ?, and [...] as wildcards, and \ to quote a wildcard or backslash character
literally.
--exclude-from=FILE
1.3、info:比man
指令的更详细内容
info
指令是man
更详细内容。但man 使用起来要方便的多。一个man 只有一页,通常man中若包含的信息概要在info中也有时,会有提示:“请参考info页更详细内容”
2、passwd
:用于修改密码
用于修改密码,先输入旧密码,再输入新密码
3、who
:查看当前用户登录到系统的用户信息
查看当前用户登录到系统的用户信息
root@healerjean:~# who
root pts/0 2020-01-15 12:26 (106.37.187.184)
3、uname
:显示当前正在使用的Linux的系统信息
显示当前正在使用的Linux的系统信息
命令 | 说明 |
---|---|
uname -a |
all:显示全部的信息 |
uname -s |
sysname : 显示操作系统名称(Linux) |
uname -n |
nodename:显示在网络上的主机名(healerjean) |
uname -r |
release:操作系统的发行编号(4.4.0-117-generic) |
uname -m |
machine:显示电脑类型(x86_64) |
3.1、uname -a
:显示全部的信息
root@healerjean:~# uname -a
Linux healerjean 4.4.0-117-generic #141-Ubuntu SMP Tue Mar 13 11:58:07 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
3.2、其他命令
root@healerjean:~# uname -s
Linux
root@healerjean:~# uname -n
healerjean
root@healerjean:~# uname -r
4.4.0-117-generic
root@healerjean:~# uname -m
x86_64
root@healerjean:~#
4、date
:显示或设置系统时间
显示或设置系统时间
root@healerjean:~# date
Wed Jan 15 14:04:18 CST 2020
5、cal
:输出日历信息
输出日历信息
root@healerjean:~# cal
January 2020
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 .15. 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
月份 | 英文 |
---|---|
一月 | january |
二月 | february |
三月 | march |
四月 | april |
五月 | may |
六月 | june |
七月 | july |
八月 | august |
九月 | september |
十月 | october |
十一月 | november |
十二月 | december |
5、su:切换登陆用户
切换用户使用的系统,需要知道用户名和密码。
返回使用命令:exit
6、netstat
:查看端口状态
利用
netstat
指令可让你得知整个Linux系统的网络情况。
命令 | 说明 |
---|---|
netstat -a |
列出所有连接 |
netstat -t |
列出 TCP 协议的连接: |
netstat -u |
列出 UDP 协议的连接 |
netstat -n |
禁止用反向域名解析,加快查询速度,具体看下面 |
netstat -l |
只列出监听中的连接 |
netstat -p |
获取进程名、进程号以及用户 ID |
6.1、使用说明
6.1.1、Status
Status | 说明 |
---|---|
LISTEN | 侦听来自远方的TCP端口的连接请求 |
SYN-SENT | 在发送连接请求后等待匹配的连接请求(如果有大量这样的状态包,检查是否中招了) |
SYN-RECEIVED | 在收到和发送一个连接请求后等待对方对连接请求的确认(如有大量此状态,估计被flood攻击了) |
ESTABLISHED | 代表一个打开的连接 |
FIN-WAIT-1 | 等待远程TCP连接中断请求,或先前的连接中断请求的确认 |
FIN-WAIT-2 | 从远程TCP等待连接中断请求 |
CLOSE-WAIT | 等待从本地用户发来的连接中断请求 |
CLOSING | 等待远程TCP对连接中断的确认 |
LAST-ACK | 等待原来的发向远程TCP的连接中断请求的确认(不是什么好东西,此项出现,检查是否被攻击) |
TIME-WAIT | 等待足够的时间以确保远程TCP接收到连接中断请求的确认 |
CLOSED | 没有任何连接状态 |
6.2.2、常用组合命令
6.2.2.1、只查询tcp
协议、并显示进程号,禁止域名反向解析,显示状态为LISTEN的端口
netstat -ntpl | grep 8080
6.2.2.2、查询tcp
和udp
协议,并显示进程号,禁用域名反向解析
netstat -anput | grep 8888
6.1、netstat -a
:列出所有连接
列出所有连接
netstat -a
root@healerjean:~# netstat -a
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:ssh *:* LISTEN
tcp 0 0 *:https *:* LISTEN
tcp 0 0 *:7777 *:* LISTEN
tcp 0 0 localhost:9000 *:* LISTEN
tcp 0 0 *:6666 *:* LISTEN
tcp 0 0 localhost:6379 *:* LISTEN
tcp 0 0 *:9999 *:* LISTEN
tcp 0 0 *:http *:* LISTEN
tcp 0 0 *:tproxy *:* LISTEN
tcp 0 0 *:8082 *:* LISTEN
tcp 0 0 healerjean:45088 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45080 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45102 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45016 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:42858 100.100.30.25:http ESTABLISHED
tcp 0 0 healerjean:44990 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45074 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45066 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45032 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45082 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45056 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45036 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45062 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:44998 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45026 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:44996 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45046 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45084 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45052 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45000 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45068 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45072 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45044 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45086 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45028 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45020 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45034 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45064 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45030 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45008 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45076 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45058 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45098 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45024 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45022 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45014 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:44994 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45096 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45012 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45054 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45078 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45004 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45070 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45100 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:ssh 106.37.187.184:4775 ESTABLISHED
tcp 0 0 healerjean:45090 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:44992 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45048 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45094 100.100.100.200:http TIME_WAIT
tcp 0 8400 healerjean:ssh 106.37.187.184:18710 ESTABLISHED
tcp 0 0 healerjean:45006 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45002 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45018 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45050 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:45042 100.100.100.200:http TIME_WAIT
tcp6 0 0 [::]:mysql [::]:* LISTEN
udp 0 0 *:bootpc *:*
udp 0 0 healerjean:ntp *:*
udp 0 0 localhost:ntp *:*
udp 0 0 *:ntp *:*
udp6 0 0 [::]:ntp [::]:*
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ] DGRAM 2328429 /run/user/0/systemd/notify
unix 2 [ ACC ] STREAM LISTENING 2328430 /run/user/0/systemd/private
unix 2 [ ACC ] SEQPACKET LISTENING 9292 /run/udev/control
unix 2 [ ACC ] STREAM LISTENING 11260 /var/run/dbus/system_bus_socket
unix 2 [ ACC ] STREAM LISTENING 10224 /run/uuidd/request
unix 3 [ ] DGRAM 9051 /run/systemd/notify
unix 2 [ ACC ] STREAM LISTENING 685879 /run/systemd/private
unix 2 [ ACC ] STREAM LISTENING 9289 /run/systemd/fsck.progress
unix 2 [ ] DGRAM 9290 /run/systemd/journal/syslog
unix 10 [ ] DGRAM 9291 /run/systemd/journal/dev-log
unix 2 [ ACC ] STREAM LISTENING 9297 /run/systemd/journal/stdout
unix 6 [ ] DGRAM 9298 /run/systemd/journal/socket
unix 2 [ ACC ] STREAM LISTENING 230958689 /var/run/mysqld/mysqld.sock
unix 2 [ ACC ] STREAM LISTENING 400046466 /usr/local/aegis/Aegis-<Guid(5A2C30A2-A87D-490A-9281-6765EDAD7CBA)>
unix 2 [ ACC ] STREAM LISTENING 400046465 /tmp/Aegis-<Guid(5A2C30A2-A87D-490A-9281-6765EDAD7CBA)>
unix 2 [ ] DGRAM 2330332
unix 3 [ ] STREAM CONNECTED 735406
unix 3 [ ] STREAM CONNECTED 2330326
unix 3 [ ] STREAM CONNECTED 3046640
unix 3 [ ] STREAM CONNECTED 2328411 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 538788633
unix 3 [ ] STREAM CONNECTED 735407 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 3046639
unix 3 [ ] STREAM CONNECTED 11837
unix 3 [ ] STREAM CONNECTED 12567 /run/systemd/journal/stdout
unix 2 [ ] DGRAM 410089914
unix 2 [ ] DGRAM 2328419
unix 2 [ ] DGRAM 735409
unix 3 [ ] STREAM CONNECTED 11838 /var/run/dbus/system_bus_socket
unix 2 [ ] STREAM CONNECTED 537159779
unix 3 [ ] STREAM CONNECTED 11364
unix 3 [ ] DGRAM 735419
unix 3 [ ] STREAM CONNECTED 11363
unix 2 [ ] DGRAM 11360
unix 3 [ ] DGRAM 735420
unix 3 [ ] STREAM CONNECTED 538788636
unix 3 [ ] STREAM CONNECTED 749487
unix 3 [ ] STREAM CONNECTED 538788634
unix 3 [ ] STREAM CONNECTED 749488 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 12622 /run/systemd/journal/stdout
unix 2 [ ] DGRAM 539128832
unix 3 [ ] STREAM CONNECTED 12566
unix 3 [ ] STREAM CONNECTED 11421
unix 3 [ ] STREAM CONNECTED 12701
unix 3 [ ] STREAM CONNECTED 11523
unix 3 [ ] STREAM CONNECTED 12702 /var/run/dbus/system_bus_socket
unix 2 [ ] DGRAM 534823795
unix 2 [ ] DGRAM 11431
unix 3 [ ] STREAM CONNECTED 559897 /run/systemd/journal/stdout
unix 2 [ ] DGRAM 9316
unix 3 [ ] STREAM CONNECTED 11326 /run/systemd/journal/stdout
unix 2 [ ] STREAM CONNECTED 538789484
unix 3 [ ] STREAM CONNECTED 560057 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 559038
unix 3 [ ] STREAM CONNECTED 560056
unix 3 [ ] STREAM CONNECTED 12648 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 685878
unix 2 [ ] DGRAM 538974267
unix 3 [ ] STREAM CONNECTED 538788635
unix 2 [ ] STREAM CONNECTED 537177061
unix 3 [ ] STREAM CONNECTED 11324
unix 2 [ ] DGRAM 2866759
unix 3 [ ] STREAM CONNECTED 686129 /var/run/dbus/system_bus_socket
unix 2 [ ] DGRAM 750451
unix 3 [ ] STREAM CONNECTED 2865786
unix 3 [ ] STREAM CONNECTED 400046463
unix 3 [ ] STREAM CONNECTED 400046464
unix 2 [ ] DGRAM 11976
unix 3 [ ] STREAM CONNECTED 2866737 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 752695
unix 3 [ ] STREAM CONNECTED 400046461
unix 3 [ ] STREAM CONNECTED 752698 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 400046462
6.2、netstat -t
:列出 TCP 协议的连接
列出 TCP 协议的连接
6.2.1、netstat -t
netstat -t
root@healerjean:~# netstat -t
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 healerjean:49414 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49504 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49458 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:42858 100.100.30.25:http ESTABLISHED
tcp 0 0 healerjean:49478 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49468 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49500 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:6666 li2091-37.members:51004 TIME_WAIT
tcp 0 0 healerjean:49430 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49428 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49442 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49518 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49490 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49470 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49426 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49436 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49476 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49510 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49508 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49516 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49494 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49484 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49498 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49460 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49448 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49416 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49464 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49486 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49488 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49452 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49462 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49446 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49512 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49420 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:ssh 106.37.187.184:4775 ESTABLISHED
tcp 0 0 healerjean:49438 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49466 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49502 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49474 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49444 100.100.100.200:http TIME_WAIT
tcp 0 2352 healerjean:ssh 106.37.187.184:18710 ESTABLISHED
tcp 0 0 healerjean:49432 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49456 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49454 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49492 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49506 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49520 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49514 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49440 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49434 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49472 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49424 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49422 100.100.100.200:http TIME_WAIT
6.2.2、netstat -at
netstat -at
root@healerjean:~# netstat -at
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:ssh *:* LISTEN
tcp 0 0 *:https *:* LISTEN
tcp 0 0 *:7777 *:* LISTEN
tcp 0 0 localhost:9000 *:* LISTEN
tcp 0 0 *:6666 *:* LISTEN
tcp 0 0 localhost:6379 *:* LISTEN
tcp 0 0 *:9999 *:* LISTEN
tcp 0 0 *:http *:* LISTEN
tcp 0 0 *:tproxy *:* LISTEN
tcp 0 0 *:8082 *:* LISTEN
tcp 0 0 healerjean:47344 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47326 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47382 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47414 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47440 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47416 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:42858 100.100.30.25:http ESTABLISHED
tcp 0 0 healerjean:47404 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47370 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47332 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47448 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47444 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47428 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47368 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47386 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47418 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47430 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47400 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47336 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47422 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47384 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47446 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47396 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47374 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47432 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47408 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47390 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47398 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47352 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47372 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47338 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47420 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47438 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47442 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47358 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47388 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47378 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47364 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47348 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47410 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47366 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47450 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47452 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47454 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47406 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47362 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47376 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47394 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47412 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47354 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47350 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47356 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:ssh 106.37.187.184:4775 ESTABLISHED
tcp 0 0 healerjean:47380 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47426 100.100.100.200:http TIME_WAIT
tcp 0 7824 healerjean:ssh 106.37.187.184:18710 ESTABLISHED
tcp 0 0 healerjean:47402 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47334 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47330 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47346 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47436 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49250 100.100.27.15:3128 ESTABLISHED
tcp 0 0 healerjean:47340 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:47342 100.100.100.200:http TIME_WAIT
tcp6 0 0 [::]:mysql [::]:* LISTEN
root@healerjean:~#
6.3、netstat -u
:列出 UDP 协议的连接
6.3.1、netstat -u
netstat -au
root@healerjean:~# netstat -u
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
6.3.2、netstat -au
netstat -au
root@healerjean:~# netstat -au
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
udp 0 0 *:bootpc *:*
udp 0 0 healerjean:ntp *:*
udp 0 0 localhost:ntp *:*
udp 0 0 *:ntp *:*
udp6 0 0 [::]:ntp [::]:*
root@healerjean:~#
6.4、netstat -n
禁用反向域名解析,加快查询速度
默认情况下
netstat
会通过反向域名解析技术查找每个 IP 地址对应的主机名。这会降低查找速度。如果你觉得 IP 地址已经足够,而没有必要知道主机名,就使用 -n 选项禁用域名解析功能。这样禁用反向域名解析,加快查询速度
6.4.1、netstat -n
netstat -n
root@healerjean:~# netstat -n
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 172.17.39.235:49748 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49804 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49794 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49722 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49726 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49716 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49788 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49802 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49750 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49714 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49774 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49738 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49820 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49740 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49790 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:42858 100.100.30.25:80 ESTABLISHED
tcp 0 0 172.17.39.235:49818 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49696 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49700 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49796 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49768 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49732 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49808 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49780 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49760 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49742 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49728 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49754 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49702 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49800 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49746 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49730 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49806 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49708 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49786 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49792 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49718 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49724 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49704 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49782 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49762 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49758 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49710 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49776 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49744 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49798 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49736 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:22 106.37.187.184:4775 ESTABLISHED
tcp 0 0 172.17.39.235:49770 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49812 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49822 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49778 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49810 100.100.100.200:80 TIME_WAIT
tcp 0 5376 172.17.39.235:22 106.37.187.184:18710 ESTABLISHED
tcp 0 0 172.17.39.235:49734 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49772 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49706 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49712 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49764 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49766 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49698 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49814 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49756 100.100.100.200:80 TIME_WAIT
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ] DGRAM 2328429 /run/user/0/systemd/notify
unix 3 [ ] DGRAM 9051 /run/systemd/notify
unix 2 [ ] DGRAM 9290 /run/systemd/journal/syslog
unix 10 [ ] DGRAM 9291 /run/systemd/journal/dev-log
unix 6 [ ] DGRAM 9298 /run/systemd/journal/socket
unix 2 [ ] DGRAM 2330332
unix 3 [ ] STREAM CONNECTED 735406
unix 3 [ ] STREAM CONNECTED 2330326
unix 3 [ ] STREAM CONNECTED 3046640
unix 3 [ ] STREAM CONNECTED 2328411 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 538788633
unix 3 [ ] STREAM CONNECTED 735407 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 3046639
unix 3 [ ] STREAM CONNECTED 11837
unix 3 [ ] STREAM CONNECTED 12567 /run/systemd/journal/stdout
unix 2 [ ] DGRAM 410089914
unix 2 [ ] DGRAM 2328419
unix 2 [ ] DGRAM 735409
unix 3 [ ] STREAM CONNECTED 11838 /var/run/dbus/system_bus_socket
unix 2 [ ] STREAM CONNECTED 537159779
unix 3 [ ] STREAM CONNECTED 11364
unix 3 [ ] DGRAM 735419
unix 3 [ ] STREAM CONNECTED 11363
unix 2 [ ] DGRAM 11360
unix 3 [ ] DGRAM 735420
unix 3 [ ] STREAM CONNECTED 538788636
unix 3 [ ] STREAM CONNECTED 749487
unix 3 [ ] STREAM CONNECTED 538788634
unix 3 [ ] STREAM CONNECTED 749488 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 12622 /run/systemd/journal/stdout
unix 2 [ ] DGRAM 539128832
unix 3 [ ] STREAM CONNECTED 12566
unix 3 [ ] STREAM CONNECTED 11421
unix 3 [ ] STREAM CONNECTED 12701
unix 3 [ ] STREAM CONNECTED 11523
unix 3 [ ] STREAM CONNECTED 12702 /var/run/dbus/system_bus_socket
unix 2 [ ] DGRAM 534823795
unix 2 [ ] DGRAM 11431
unix 3 [ ] STREAM CONNECTED 559897 /run/systemd/journal/stdout
unix 2 [ ] DGRAM 9316
unix 3 [ ] STREAM CONNECTED 11326 /run/systemd/journal/stdout
unix 2 [ ] STREAM CONNECTED 538789484
unix 3 [ ] STREAM CONNECTED 560057 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 559038
unix 3 [ ] STREAM CONNECTED 560056
unix 3 [ ] STREAM CONNECTED 12648 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 685878
unix 2 [ ] DGRAM 538974267
unix 3 [ ] STREAM CONNECTED 538788635
unix 2 [ ] STREAM CONNECTED 537177061
unix 3 [ ] STREAM CONNECTED 11324
unix 2 [ ] DGRAM 2866759
unix 3 [ ] STREAM CONNECTED 686129 /var/run/dbus/system_bus_socket
unix 2 [ ] DGRAM 750451
unix 3 [ ] STREAM CONNECTED 2865786
unix 3 [ ] STREAM CONNECTED 400046463
unix 3 [ ] STREAM CONNECTED 400046464
unix 2 [ ] DGRAM 11976
unix 3 [ ] STREAM CONNECTED 2866737 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 752695
unix 3 [ ] STREAM CONNECTED 400046461
unix 3 [ ] STREAM CONNECTED 752698 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 400046462
root@healerjean:~#
6.4.2、netstat -atn
netstat -atn
root@healerjean:~# netstat -atn
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 0.0.0.0:443 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:7777 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:6666 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:9999 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:8081 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:8082 0.0.0.0:* LISTEN
tcp 0 0 172.17.39.235:47784 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47800 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47768 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47786 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47758 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47816 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:42858 100.100.30.25:80 ESTABLISHED
tcp 0 0 172.17.39.235:47848 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47752 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47834 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47840 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47738 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47820 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47802 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47790 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47764 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47814 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47774 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47828 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47748 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47772 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47838 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47798 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47792 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47760 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47734 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47824 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47812 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47766 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47732 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47794 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47756 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47846 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47830 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47826 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47782 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47770 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47746 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47796 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:49626 100.100.27.15:3128 ESTABLISHED
tcp 0 0 172.17.39.235:47844 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47780 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47730 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:22 106.37.187.184:4775 ESTABLISHED
tcp 0 0 172.17.39.235:47818 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47842 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47778 100.100.100.200:80 TIME_WAIT
tcp 0 8032 172.17.39.235:22 106.37.187.184:18710 ESTABLISHED
tcp 0 0 172.17.39.235:47804 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47822 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:80 86.107.226.174:38561 TIME_WAIT
tcp 0 0 172.17.39.235:47836 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47740 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47750 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47742 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47736 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47754 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47762 100.100.100.200:80 TIME_WAIT
tcp 0 0 172.17.39.235:47788 100.100.100.200:80 TIME_WAIT
tcp6 0 0 :::3306 :::* LISTEN
root@healerjean:~#
6.5、netstat -l
:只列出监听中的连接
任何网络服务的后台进程都会打开一个端口,用于监听接入的请求。这些正在监听的套接字也和连接的套接字一样,也能被
netstat
列出来。使用 -l 选项列出正在监听的套接字。
6.5.1、netstat -l
netstat -l
root@healerjean:~# netstat -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:ssh *:* LISTEN
tcp 0 0 *:https *:* LISTEN
tcp 0 0 *:7777 *:* LISTEN
tcp 0 0 localhost:9000 *:* LISTEN
tcp 0 0 *:6666 *:* LISTEN
tcp 0 0 localhost:6379 *:* LISTEN
tcp 0 0 *:9999 *:* LISTEN
tcp 0 0 *:http *:* LISTEN
tcp 0 0 *:tproxy *:* LISTEN
tcp 0 0 *:8082 *:* LISTEN
tcp6 0 0 [::]:mysql [::]:* LISTEN
udp 0 0 *:bootpc *:*
udp 0 0 healerjean:ntp *:*
udp 0 0 localhost:ntp *:*
udp 0 0 *:ntp *:*
udp6 0 0 [::]:ntp [::]:*
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 2328430 /run/user/0/systemd/private
unix 2 [ ACC ] SEQPACKET LISTENING 9292 /run/udev/control
unix 2 [ ACC ] STREAM LISTENING 11260 /var/run/dbus/system_bus_socket
unix 2 [ ACC ] STREAM LISTENING 10224 /run/uuidd/request
unix 2 [ ACC ] STREAM LISTENING 685879 /run/systemd/private
unix 2 [ ACC ] STREAM LISTENING 9289 /run/systemd/fsck.progress
unix 2 [ ACC ] STREAM LISTENING 9297 /run/systemd/journal/stdout
unix 2 [ ACC ] STREAM LISTENING 230958689 /var/run/mysqld/mysqld.sock
unix 2 [ ACC ] STREAM LISTENING 400046466 /usr/local/aegis/Aegis-<Guid(5A2C30A2-A87D-490A-9281-6765EDAD7CBA)>
unix 2 [ ACC ] STREAM LISTENING 400046465 /tmp/Aegis-<Guid(5A2C30A2-A87D-490A-9281-6765EDAD7CBA)>
6.5.2、netstat -al
: 这里的结果就有点不科学了,所以使用-l就不要用-a命令了吧
root@healerjean:~# netstat -al
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:ssh *:* LISTEN
tcp 0 0 *:https *:* LISTEN
tcp 0 0 *:7777 *:* LISTEN
tcp 0 0 localhost:9000 *:* LISTEN
tcp 0 0 *:6666 *:* LISTEN
tcp 0 0 localhost:6379 *:* LISTEN
tcp 0 0 *:9999 *:* LISTEN
tcp 0 0 *:http *:* LISTEN
tcp 0 0 *:tproxy *:* LISTEN
tcp 0 0 *:8082 *:* LISTEN
tcp 0 0 healerjean:50050 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49956 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50012 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50060 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49970 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50014 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50072 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49958 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50022 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50048 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49972 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50054 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:42858 100.100.30.25:http ESTABLISHED
tcp 0 0 healerjean:49994 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50002 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50026 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50018 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49990 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50068 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50062 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50064 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50078 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49964 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50016 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49986 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:51836 100.100.27.15:3128 ESTABLISHED
tcp 0 0 healerjean:49988 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49968 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49952 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50044 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50066 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50004 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50010 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50024 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50076 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50038 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49996 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50056 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49962 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50058 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50000 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49998 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49980 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50040 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49960 100.100.100.200:http TIME_WAIT
tcp 0 0 localhost:9999 localhost:48164 TIME_WAIT
tcp 0 0 healerjean:50032 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50036 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49978 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:ssh 106.37.187.184:4775 ESTABLISHED
tcp 0 0 healerjean:50028 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50070 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49984 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50046 100.100.100.200:http TIME_WAIT
tcp 0 6784 healerjean:ssh 106.37.187.184:18710 ESTABLISHED
tcp 0 0 healerjean:50006 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49954 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50080 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50052 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49976 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49966 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:50030 100.100.100.200:http TIME_WAIT
tcp 0 0 healerjean:49992 100.100.100.200:http TIME_WAIT
tcp6 0 0 [::]:mysql [::]:* LISTEN
udp 0 0 *:bootpc *:*
udp 0 0 healerjean:ntp *:*
udp 0 0 localhost:ntp *:*
udp 0 0 *:ntp *:*
udp6 0 0 [::]:ntp [::]:*
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ] DGRAM 2328429 /run/user/0/systemd/notify
unix 2 [ ACC ] STREAM LISTENING 2328430 /run/user/0/systemd/private
unix 2 [ ACC ] SEQPACKET LISTENING 9292 /run/udev/control
unix 2 [ ACC ] STREAM LISTENING 11260 /var/run/dbus/system_bus_socket
unix 2 [ ACC ] STREAM LISTENING 10224 /run/uuidd/request
unix 3 [ ] DGRAM 9051 /run/systemd/notify
unix 2 [ ACC ] STREAM LISTENING 685879 /run/systemd/private
unix 2 [ ACC ] STREAM LISTENING 9289 /run/systemd/fsck.progress
unix 2 [ ] DGRAM 9290 /run/systemd/journal/syslog
unix 10 [ ] DGRAM 9291 /run/systemd/journal/dev-log
unix 2 [ ACC ] STREAM LISTENING 9297 /run/systemd/journal/stdout
unix 6 [ ] DGRAM 9298 /run/systemd/journal/socket
unix 2 [ ACC ] STREAM LISTENING 230958689 /var/run/mysqld/mysqld.sock
unix 2 [ ACC ] STREAM LISTENING 400046466 /usr/local/aegis/Aegis-<Guid(5A2C30A2-A87D-490A-9281-6765EDAD7CBA)>
unix 2 [ ACC ] STREAM LISTENING 400046465 /tmp/Aegis-<Guid(5A2C30A2-A87D-490A-9281-6765EDAD7CBA)>
unix 2 [ ] DGRAM 2330332
unix 3 [ ] STREAM CONNECTED 735406
unix 3 [ ] STREAM CONNECTED 2330326
unix 3 [ ] STREAM CONNECTED 3046640
unix 3 [ ] STREAM CONNECTED 2328411 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 538788633
unix 3 [ ] STREAM CONNECTED 735407 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 3046639
unix 3 [ ] STREAM CONNECTED 11837
unix 3 [ ] STREAM CONNECTED 12567 /run/systemd/journal/stdout
unix 2 [ ] DGRAM 410089914
unix 2 [ ] DGRAM 2328419
unix 2 [ ] DGRAM 735409
unix 3 [ ] STREAM CONNECTED 11838 /var/run/dbus/system_bus_socket
unix 2 [ ] STREAM CONNECTED 537159779
unix 3 [ ] STREAM CONNECTED 11364
unix 3 [ ] DGRAM 735419
unix 3 [ ] STREAM CONNECTED 11363
unix 2 [ ] DGRAM 11360
unix 3 [ ] DGRAM 735420
unix 3 [ ] STREAM CONNECTED 538788636
unix 3 [ ] STREAM CONNECTED 749487
unix 3 [ ] STREAM CONNECTED 538788634
unix 3 [ ] STREAM CONNECTED 749488 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 12622 /run/systemd/journal/stdout
unix 2 [ ] DGRAM 539128832
unix 3 [ ] STREAM CONNECTED 12566
unix 3 [ ] STREAM CONNECTED 11421
unix 3 [ ] STREAM CONNECTED 12701
unix 3 [ ] STREAM CONNECTED 11523
unix 3 [ ] STREAM CONNECTED 12702 /var/run/dbus/system_bus_socket
unix 2 [ ] DGRAM 534823795
unix 2 [ ] DGRAM 11431
unix 3 [ ] STREAM CONNECTED 559897 /run/systemd/journal/stdout
unix 2 [ ] DGRAM 9316
unix 3 [ ] STREAM CONNECTED 11326 /run/systemd/journal/stdout
unix 2 [ ] STREAM CONNECTED 538789484
unix 3 [ ] STREAM CONNECTED 560057 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 559038
unix 3 [ ] STREAM CONNECTED 560056
unix 3 [ ] STREAM CONNECTED 12648 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 685878
unix 2 [ ] DGRAM 538974267
unix 3 [ ] STREAM CONNECTED 538788635
unix 2 [ ] STREAM CONNECTED 537177061
unix 3 [ ] STREAM CONNECTED 11324
unix 2 [ ] DGRAM 2866759
unix 3 [ ] STREAM CONNECTED 686129 /var/run/dbus/system_bus_socket
unix 2 [ ] DGRAM 750451
unix 3 [ ] STREAM CONNECTED 2865786
unix 3 [ ] STREAM CONNECTED 400046463
unix 3 [ ] STREAM CONNECTED 400046464
unix 2 [ ] DGRAM 11976
unix 3 [ ] STREAM CONNECTED 2866737 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 752695
unix 3 [ ] STREAM CONNECTED 400046461
unix 3 [ ] STREAM CONNECTED 752698 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 400046462
root@healerjean:~#
6.5.3、netstat -tnl
netstat -tnl
root@healerjean:~# netstat -tnl
Active Internet connections (only servers)
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 0.0.0.0:443 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:7777 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:6666 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:9999 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:8081 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:8082 0.0.0.0:* LISTEN
tcp6 0 0 :::3306 :::* LISTEN
6.6、netstat -p
:获取进程名、进程号以及用户 ID
6.6.1、netstat -p
:获取进程名、进程号以及用户 ID
netstat -p
root@healerjean:~# netstat -p
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 healerjean:52226 100.100.27.15:3128 ESTABLISHED 31604/CmsGoAgent-Wo
tcp 0 0 healerjean:50366 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50284 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50312 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50406 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50372 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50294 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:7777 scan-145.security:45342 TIME_WAIT -
tcp 0 0 healerjean:50364 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50382 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50282 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50350 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:42858 100.100.30.25:http ESTABLISHED 12165/AliYunDun
tcp 0 0 healerjean:50362 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50308 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50386 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50346 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50388 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50314 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50360 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50408 100.100.100.200:http ESTABLISHED 595/aliyun-service
tcp 0 0 healerjean:50392 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50324 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50338 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50358 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50302 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50320 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50292 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50380 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50342 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50310 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50304 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50356 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50394 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50384 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50396 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50340 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50398 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50280 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50290 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50300 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50318 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50370 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50378 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50402 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50376 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50390 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50316 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50322 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50286 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50344 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50404 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50296 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50352 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50306 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50288 100.100.100.200:http TIME_WAIT -
tcp 0 2048 healerjean:ssh 106.37.187.184:18710 ESTABLISHED 29062/2
tcp 0 0 healerjean:50348 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50374 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50354 100.100.100.200:http TIME_WAIT -
tcp 0 0 healerjean:50334 100.100.100.200:http TIME_WAIT -
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags Type State I-Node PID/Program name Path
unix 2 [ ] DGRAM 2328429 30717/systemd /run/user/0/systemd/notify
unix 3 [ ] DGRAM 9051 1/systemd /run/systemd/notify
unix 2 [ ] DGRAM 9290 1/systemd /run/systemd/journal/syslog
unix 9 [ ] DGRAM 9291 1/systemd /run/systemd/journal/dev-log
unix 6 [ ] DGRAM 9298 1/systemd /run/systemd/journal/socket
unix 2 [ ] DGRAM 2330332 30718/(sd-pam)
unix 3 [ ] STREAM CONNECTED 735406 26511/systemd-udevd
unix 3 [ ] STREAM CONNECTED 2330326 30717/systemd
unix 3 [ ] STREAM CONNECTED 3046640 28619/php-fpm.conf)
unix 3 [ ] STREAM CONNECTED 2328411 1/systemd /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 538788633 28170/nginx.conf
unix 3 [ ] STREAM CONNECTED 735407 1/systemd /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 3046639 28619/php-fpm.conf)
unix 3 [ ] STREAM CONNECTED 11837 492/accounts-daemon
unix 3 [ ] STREAM CONNECTED 12567 1/systemd /run/systemd/journal/stdout
unix 2 [ ] DGRAM 410089914 29170/mysqld
unix 2 [ ] DGRAM 2328419 30717/systemd
unix 2 [ ] DGRAM 735409 26511/systemd-udevd
unix 3 [ ] STREAM CONNECTED 11838 469/dbus-daemon /var/run/dbus/system_bus_socket
unix 2 [ ] STREAM CONNECTED 537159779 25044/java
unix 3 [ ] STREAM CONNECTED 11364 469/dbus-daemon
unix 3 [ ] DGRAM 735419 26511/systemd-udevd
unix 3 [ ] STREAM CONNECTED 11363 469/dbus-daemon
unix 2 [ ] DGRAM 11360 469/dbus-daemon
unix 3 [ ] DGRAM 735420 26511/systemd-udevd
unix 3 [ ] STREAM CONNECTED 538788636 28170/nginx.conf
unix 3 [ ] STREAM CONNECTED 749487 28341/uuidd
unix 3 [ ] STREAM CONNECTED 538788634 28170/nginx.conf
unix 3 [ ] STREAM CONNECTED 749488 1/systemd /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 12622 1/systemd /run/systemd/journal/stdout
unix 2 [ ] DGRAM 539128832 29062/2
unix 3 [ ] STREAM CONNECTED 12566 490/systemd-logind
unix 3 [ ] STREAM CONNECTED 11421 492/accounts-daemon
unix 3 [ ] STREAM CONNECTED 12701 490/systemd-logind
unix 3 [ ] STREAM CONNECTED 11523 510/cron
unix 3 [ ] STREAM CONNECTED 12702 469/dbus-daemon /var/run/dbus/system_bus_socket
unix 2 [ ] DGRAM 534823795 1/systemd
unix 2 [ ] DGRAM 11431 490/systemd-logind
unix 3 [ ] STREAM CONNECTED 559897 1/systemd /run/systemd/journal/stdout
unix 2 [ ] DGRAM 9316 190/systemd-journal
unix 3 [ ] STREAM CONNECTED 11326 1/systemd /run/systemd/journal/stdout
unix 2 [ ] STREAM CONNECTED 538789484 28178/java
unix 3 [ ] STREAM CONNECTED 560057 469/dbus-daemon /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 559038 21061/python3
unix 3 [ ] STREAM CONNECTED 560056 21061/python3
unix 3 [ ] STREAM CONNECTED 12648 1/systemd /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 685878 1/systemd
unix 3 [ ] STREAM CONNECTED 538788635 28170/nginx.conf
unix 2 [ ] STREAM CONNECTED 539222767 28178/java
unix 2 [ ] STREAM CONNECTED 537177061 25044/java
unix 3 [ ] STREAM CONNECTED 11324 469/dbus-daemon
unix 2 [ ] DGRAM 2866759 31595/CmsGoAgent.li
unix 3 [ ] STREAM CONNECTED 686129 469/dbus-daemon /var/run/dbus/system_bus_socket
unix 2 [ ] DGRAM 750451 28432/ntpd
unix 3 [ ] STREAM CONNECTED 2865786 31595/CmsGoAgent.li
unix 3 [ ] STREAM CONNECTED 400046463 12165/AliYunDun
unix 3 [ ] STREAM CONNECTED 400046464 12165/AliYunDun
unix 2 [ ] DGRAM 11976 641/dhclient
unix 3 [ ] STREAM CONNECTED 2866737 1/systemd /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 752695 28575/sshd
unix 3 [ ] STREAM CONNECTED 400046461 12165/AliYunDun
unix 3 [ ] STREAM CONNECTED 752698 1/systemd /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 400046462 12165/AliYunDun
root@healerjean:~#
6.6.2、netstat -tnpl
netstat -tnpl
root@healerjean:~# netstat -tnpl
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 28575/sshd
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 28170/nginx.conf
tcp 0 0 0.0.0.0:7777 0.0.0.0:* LISTEN 28178/java
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 28619/php-fpm.conf)
tcp 0 0 0.0.0.0:6666 0.0.0.0:* LISTEN 28170/nginx.conf
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 21426/redis-server
tcp 0 0 0.0.0.0:9999 0.0.0.0:* LISTEN 25044/java
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 28170/nginx.conf
tcp 0 0 0.0.0.0:8081 0.0.0.0:* LISTEN 28170/nginx.conf
tcp 0 0 0.0.0.0:8082 0.0.0.0:* LISTEN 28170/nginx.conf
tcp6 0 0 :::3306 :::* LISTEN 29170/mysqld
7、ls:显示文件
命令 | 说明 |
---|---|
ls -a |
查询所有文件和文件夹,包括隐藏的文件 |
ls -l |
详细列表,不包含隐藏文件,也可以ls -l缩写为 ll |
ls -al |
全部文件(包括隐藏文件)的详细列表 |
ls -h |
友好的文件展示(大小会显示K),或者ls - lh 、ll -h |
7.1、 ls -a
:查询所有文件和文件夹,包括隐藏的文件
查询所有文件和文件夹,包括隐藏的文件
7.2、 ls -l
:详细列表,不包含隐藏文件,也可以ls -l缩写为 ll
详细列表,不包含隐藏文件,也可以ls -l缩写为 ll
7.3、 ls -al
:全部文件(包括隐藏文件)的详细列表
7.4、 ls -l
:-h 友好显示 或者ls - lh ll -h
7.5、ls -l /etc
:查看其它目录下的详细列表
8、查看文件
8.1、cat
:显示文件命令
8.1.1、cat filename
:显示文件内容
显示文件内容
cat iku-client.stdout.log
root@healerjean:/usr/local/service/logs/iku/iku-client# cat iku-client.stdout.log
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.5.RELEASE)
2020-01-15 10:37:29 INFO -[ ]- Starting IkuClientApplication v1.0.0-SNAPSHOT on healerjean with PID 28178 (/usr/local/service/app/iku/iku-client/iku-client.jar started by root in /usr/local/service/app/iku/iku-client) com.healerjean.proj.IkuClientApplication.logStarting[50]
2020-01-15 10:37:29 INFO -[ ]- The following profiles are active: prod com.healerjean.proj.IkuClientApplication.logStartupProfileInfo[679]
2020-01-15 10:37:30 INFO -[ ]- Multiple Spring Data modules found, entering strict repository configuration mode! org.springframework.data.repository.config.RepositoryConfigurationDelegate.multipleStoresDetected[244]
2020-01-15 10:37:30 INFO -[ ]- Bootstrapping Spring Data repositories in DEFAULT mode. org.springframework.data.repository.config.RepositoryConfigurationDelegate.registerRepositoriesIn[126]
2020-01-15 10:37:31 INFO -[ ]- Finished Spring Data repository scanning in 278ms. Found 10 repository interfaces. org.springframework.data.repository.config.RepositoryConfigurationDelegate.registerRepositoriesIn[182]
2020-01-15 10:37:31 WARN -[ ]- No MyBatis mapper was found in '[com.healerjean.proj]' package. Please check your configuration. org.mybatis.spring.mapper.ClassPathMapperScanner.doScan[166]
2020-01-15 10:37:31 INFO -[ ]- Multiple Spring Data modules found, entering strict repository configuration mode! org.springframework.data.repository.config.RepositoryConfigurationDelegate.multipleStoresDetected[244]
2020-01-15 10:37:31 INFO -[ ]- Bootstrapping Spring Data repositories in DEFAULT mode. org.springframework.data.repository.config.RepositoryConfigurationDelegate.registerRepositoriesIn[126]
2020-01-15 10:37:31 INFO -[ ]- Spring Data Redis - Could not safely identify store assignment for repository candidate "com.healerjean.proj.data.repository.item.ItemAdzoneRefRepository". org.sprin
8.1.2、cat -n filename
:显示文件内容,并加上行号
显示文件内容,并加上行号
root@healerjean:/usr/local/service/logs/iku/iku-client# cat -n iku-client.stdout.log
1
2 . ____ _ __ _ _
3 /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
4 ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
5 \\/ ___)| |_)| | | | | || (_| | ) ) ) )
6 ' |____| .__|_| |_|_| |_\__, | / / / /
7 =========|_|==============|___/=/_/_/_/
8 :: Spring Boot :: (v2.1.5.RELEASE)
9
10 2020-01-15 10:37:29 INFO -[ ]- Starting IkuClientApplication v1.0.0-SNAPSHOT on healerjean with PID 28178 (/usr/local/service/app/iku/iku-client/iku-client.jar started by root in /usr/local/service/app/iku/iku-client) com.healerjean.proj.IkuClientApplication.logStarting[50]
11 2020-01-15 10:37:29 INFO -[ ]- The following profiles are active: prod com.healerjean.proj.IkuClientApplication.logStartupProfileInfo[679]
12 2020-01-15 10:37:30 INFO -[ ]- Multiple Spring Data modules found, entering strict repository configuration mode! org.springframework.data.repository.config.RepositoryConfigurationDelegate.multipleStoresDetected[244]
13 2020-01-15 10:37:30 INFO -[ ]- Bootstrapping Spring Data repositories in DEFAULT mode. org.springframework.data.repository.config.RepositoryConfigurationDelegate.registerRepositoriesIn[126]
14 2020-01-15 10:37:31 INFO -[ ]- Finished Spring Data repository scanning in 278ms. Found 10 repository interfaces. org.springframework.data.repository.config.RepositoryConfigurationDelegate.registerRepositoriesIn[182]
15 2020-01-15 10:37:3
9、cp
:复制命令
不加
-r
或者-R
的时候,只拷贝文件,不拷贝文件夹;加上后则会拷贝文件夹——包括下一级的子文件夹,以及子文件夹中的子文件夹,余此类…
9.1、cp originFileNmae newFileName
:复制文件
cp test.txt cp.txt
root@healerjean:/usr/local/service/logs/iku/iku-client# ll
total 48
drwxrwxrwx 2 root root 4096 Jan 15 15:20 ./
drwxrwxrwx 4 root root 4096 Jan 14 18:45 ../
-rw-r--r-- 1 root root 0 Jan 15 10:37 iku-client.error
-rw-r--r-- 1 root root 35435 Jan 15 14:59 iku-client.stdout.log
-rw-r--r-- 1 root root 6 Jan 15 15:20 test.txt
root@healerjean:/usr/local/service/logs/iku/iku-client# cp test.txt cp.txt
root@healerjean:/usr/local/service/logs/iku/iku-client# ll
total 52
drwxrwxrwx 2 root root 4096 Jan 15 15:20 ./
drwxrwxrwx 4 root root 4096 Jan 14 18:45 ../
-rw-r--r-- 1 root root 6 Jan 15 15:20 cp.txt
-rw-r--r-- 1 root root 0 Jan 15 10:37 iku-client.error
-rw-r--r-- 1 root root 35435 Jan 15 14:59 iku-client.stdout.log
-rw-r--r-- 1 root root 6 Jan 15 15:20 test.txt
root@healerjean:/usr/local/service/logs/iku/iku-client#
9.2、cp conf -r /use/local
:复制目录
10、rm
:删除命令
10.1、rm filename
:删除文件
rm test.txt
root@healerjean:/usr/local/service/logs/iku/iku-client# ll
total 44
drwxrwxrwx 2 root root 4096 Jan 15 15:13 ./
drwxrwxrwx 4 root root 4096 Jan 14 18:45 ../
-rw-r--r-- 1 root root 0 Jan 15 10:37 iku-client.error
-rw-r--r-- 1 root root 35435 Jan 15 14:59 iku-client.stdout.log
-rw-r--r-- 1 root root 0 Jan 15 15:14 test.txt
root@healerjean:/usr/local/service/logs/iku/iku-client# rm test.txt
root@healerjean:/usr/local/service/logs/iku/iku-client# ll
total 44
drwxrwxrwx 2 root root 4096 Jan 15 15:19 ./
drwxrwxrwx 4 root root 4096 Jan 14 18:45 ../
-rw-r--r-- 1 root root 0 Jan 15 10:37 iku-client.error
-rw-r--r-- 1 root root 35435 Jan 15 14:59 iku-client.stdout.log
10.2、rm -rf 目录名字
:删除目录
-r
:就是向下递归,不管有多少级目录,一并删除-f
:就是直接强行删除,不作任何提示的意思
rm -rf conf
root@healerjean:/usr/local/service/logs/iku/iku-client# ll
total 56
drwxrwxrwx 3 root root 4096 Jan 15 15:22 ./
drwxrwxrwx 4 root root 4096 Jan 14 18:45 ../
drwxr-xr-x 2 root root 4096 Jan 15 15:22 conf/
-rw-r--r-- 1 root root 6 Jan 15 15:20 cp.txt
-rw-r--r-- 1 root root 0 Jan 15 10:37 iku-client.error
-rw-r--r-- 1 root root 35435 Jan 15 14:59 iku-client.stdout.log
-rw-r--r-- 1 root root 6 Jan 15 15:20 test.txt
root@healerjean:/usr/local/service/logs/iku/iku-client# rm -rf conf
root@healerjean:/usr/local/service/logs/iku/iku-client# ll
total 52
drwxrwxrwx 2 root root 4096 Jan 15 15:22 ./
drwxrwxrwx 4 root root 4096 Jan 14 18:45 ../
-rw-r--r-- 1 root root 6 Jan 15 15:20 cp.txt
-rw-r--r-- 1 root root 0 Jan 15 10:37 iku-client.error
-rw-r--r-- 1 root root 35435 Jan 15 14:59 iku-client.stdout.log
-rw-r--r-- 1 root root 6 Jan 15 15:20 test.txt
root@healerjean:/usr/local/service/logs/iku/iku-client#
11、解压
11.1、tar、解压tar文件
命令 | 说明 |
---|---|
z | 表示 tar 包是被 gzip 压缩过的,所以解压时需要用 gunzip 解压 |
x | 从 tar 包中把文件提取出来 |
v | 显示详细信息 |
f xxx.tar.gz | 指定被处理的文件是 xxx.tar.gz |
C | 压缩到指定目录 |
11.1.1、当前目录解压
tar -zxvf jdk.tar.gz
11.1.2、解压到指定目录
tar -zxvf jdk.tar.gz -C /usr/local
11.2、unzip、zip:zip文件
11..2.1、unzip filename.zip
解压
unzip filename.zip
11.2.2、zip new.zip filename
:压缩
zip scf-m.zip scf-m
12、chmod
:权限改变
12.1、who:用户、组、其他用户、所有用户,以及文件权限
u 用户,g 组,o 其它,a 所有用户(默认)
12.2、opcode
+增加权限,- 删除权限,= 重新分配权限
12.3、permission
r 读,w 写,x 执行,s设置用户(或组)的ID号t设置粘着位(sticky bit),防止文件或目录被非属主删除
12.4、数字
作为选择,我们多数用三位八进制数字的形式来表示权限
第一位指定属主的权限,第二位指定组权限,第三位指定其他用户的权限,每位通过4(读)、2(写)、1(执行)三种数值的和来确定权限。如6(4+2)代表有读写权,7(4+2+1)有读、写和执行的权限。
还可设置第四位,它位于三位权限序列的前面,第四位数字取值是4,2,1,代表意思如下:
4,执行时设置用户ID,用于授权给基于文件属主的进程,而不是给创建此进程的用户。
2,执行时设置用户组ID,用于授权给基于文件所在组的进程,而不是基于创建此进程的用户。
1,设置粘着位。
12.5、举例
12.5.1、多案例
chmod u+x file 给file的属主增加执行权限
chmod 751 file 给file的属主分配读、写、执行(7)的权限,给file的所在组分配读、执行(5)的权限,给其他用户分配执行(1)的权限
chmod u=rwx,g=rx,o=x file 上例的另一种形式
chmod =r file 为所有用户分配读权限
chmod 444 file 同上
chmod a-wx,a+r file 同上例
chmod -R u+r directory 递归地给directory目录下所有文件和子目录的属主分配读的权限
chmod u+x *.sh 给bin中所有的sh授予执行权限
12.5.2、自己内测
1、新建一个文件txt.txt
2、chmod u=rwx txt.txt
3、这个时候可以看到root用户以及拥有了读写执行的权限,但是其他组、用户只有可读权限,也就是说和healerjean
组是删除不了这个用户的,只能给组赋值才能够删除这个txt.txt文件
4、给组healerjean
授予权限(这里全部赋予最高,就可以了看到txt.txt
的锁消失了)
13、sudo
:让普通用户执行一些或者全部的root命令
13.1、将用户添加到sudo配置文件中
13.1.1、提示下文,原因是用户没有加入到sudo的配置文件里
13.1.2、添加用户进入sudo配置文件
2.1、切换到root用户下
2.2、添加sudo文件的写权限,命令是:
chmod u+w /etc/sudoers
2.3、编辑sudoers文件,找到这行 root ALL=(ALL) ALL,在他下面添加xxx ALL=(ALL) ALL (这里的xxx是你的用户名)
vi /etc/sudoers
解释::这里说下你可以sudoers添加下面四行中任意一条
youuser ALL=(ALL) ALL
%youuser ALL=(ALL) ALL
youuser ALL=(ALL) NOPASSWD: ALL
%youuser ALL=(ALL) NOPASSWD: ALL
第一行:允许用户youuser执行sudo命令(需要输入密码).
第二行:允许用户组youuser里面的用户执行sudo命令(需要输入密码).
第三行:允许用户youuser执行sudo命令,并且在执行的时候不输入密码.
第四行:允许用户组youuser里面的用户执行sudo命令,并且在执行的时候不输入密码.
13.1.3、这样普通用户就可以使用sudo了
14、mv
:移动文件、目录
命令 | 说明 |
---|---|
mv 文件名 文件名 |
将源文件名改为目标文件名 |
mv 文件名 目录名 |
将文件移动到目标目录 |
mv 目录名 目录名 |
目标目录已存在,将源目录 移动到目标目录;目标 目录不存在则改名 |
15、cd
:切换当前工作路径
15.1、命令使用
命令 | 说明 |
---|---|
cd ../ 和cd ., |
上一层目录 |
cd ~ |
当前用户目录 |
cd - |
上一次访问的目录 |
cd / |
跟目录 |
16、mkdir
:创建目录
16.1、级联创建目录
16.1.1、先创建t1,再创建t2
mkdir t1/t2
16.1.2、直接动态创建目录
mkdir -p t1/t2
17、vi/vim:编辑文件
17.1、退出的几种
1、q! 不保存强制退出
2、wq 保存并退出
3、q 不保存,退出
4、w保存,不退出
5、凡是有!都是强制
5.1、wq! 保存强制退出
5.2、w! 强制保存,不退出
5.3、q! 不保存,强制退出
17.2、选中删除,vi是不能用的,vim可以
gg 让光标移到首行,
V 是进入Visual(可视)模式 ,可以移动上下移动位置,选中内容以后就可以其他的操作了
G 光标移到最后一行
d 删除选中内容
18、ps:查看进程
18.1、ps -ef
:查询进程
18.1.1、返回格式说明
格式 | 说明 |
---|---|
UID |
进程是被哪个用户打开的 root用户几乎可以杀死所有的进程 |
PID |
进程Id,linux只有知道这个id才能杀死进程 |
cmd |
表明进程对应的程序,或者程序的位置 |
18.1.2、测试
18.1.2.1、查询某个应用的进程
ps -ef | grep scf-client
[work@vm10-123-3-2 ~]$ ps -ef | grep scf-client
work 12523 1 0 Jan02 ? 00:53:18 /usr/local/service/app/scf/scf-client/jdk1.8.0_202/bin/java -Xmn128M -Xmx512M -Xms256M -XX:MaxPermSize=128M -XX:PermSize=128M -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC -XX:CMSFullGCsBeforeCompaction=50 -XX:+UseCMSCompactAtFullCollection -XX:MaxTenuringThreshold=10 -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -XX:+PrintFlagsFinal -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8383 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Xloggc:/usr/local/service/log/scf/scf-client/gc.log -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=19136 -Dlog4j2.isThreadContextMapInheritable=true -Djava.util.logging.manager=com.caucho.log.LogManagerImpl -Djava.system.class.loader=com.caucho.loader.SystemClassLoader -Djava.endorsed.dirs=/usr/local/service/app/scf/scf-client/jdk1.8.0_202/jre/lib/endorsed:/usr/local/service/app/scf/scf-client/resin-pro-4.0.58/endorsed -Djavax.management.builder.initial=com.caucho.jmx.MBeanServerBuilderImpl -Djava.awt.headless=true -Dresin.home=/usr/local/service/app/s
19、kill:杀死进程
kill -9 pid pid为进程号
20、关机
20.1、reboot
:重启命令
20.2、halt
:直接关机命令
21、Linux软件安装
21.1、yum
:centos安装软件命令
21.1.1、yum list
: 查看远程服务器的可安装软件列表
yum list
文件名(软件包名) 版本 容器的名称
21.1.2、yum search 关键字
: 搜索服务器商所有和关键字相关的软件包
yum search java
21.1.3、yum -y install 包名
:安装软件
安装软件 ,命令-y :自动回答yes
测试:安装一个gcc的c语言的编译器,这里我的不知道为什么早就安装好了
21.1.4、yum -y update 包名
:更新软件
千万记得输入包名,不输入的话,会导致更新所有的东西,这样会导致linux内核改变,造成不必要的损失
21.1.5、yum -y remove 包名
:卸载软件
21.1.6、注意点
yum的更新和卸载一般不要使用。用什么装什么。不要轻易使用
21.2、rpm:centos安装软件命令
命令 | 说明 |
---|---|
rpm–i |
安装模式 |
rpm–q |
查询模式 |
rpm–V |
验证模式 |
rpm–e |
删除模式 |
rpm -U |
升级模式 |
21.2.1、其他组合命令
命令 | 说明 |
---|---|
-a | 查询所有套件。 |
–nodeps | 不验证套件档的相互关联性 |
-i | 查询安装信息 |
-l | 安装的位置 ,查看安装的位置 |
-f | 查看系统文件属于哪个包 |
-h | (hash)显示进度(安装时候使用) |
-v | 显示安装过程的的信息(控制台打印的内容) |
21.2.2、rpm -q
:查询模式
21.2.1.1、rpm -qa
:查看本机是否有java软件
rpm -qa | grep java
[work@vm10-123-3-2 ~]$ rpm -qa | grep java
tzdata-java-2016g-2.el7.noarch
javapackages-tools-3.4.1-11.el7.noarch
nuxwdog-client-java-1.0.3-5.el7.x86_64
python-javapackages-3.4.1-11.el7.noarch
21.2.1.2、rpm -qi
:查看软件的详细信息
rpm -qi gcc
[work@vm10-123-3-2 ~]$ rpm -qi gcc
Name : gcc
Version : 4.8.5
Release : 11.el7
Architecture: x86_64
Install Date: Fri 30 Jun 2017 08:47:54 AM CST
Group : Development/Languages
Size : 39227971
License : GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD
Signature : RSA/SHA256, Mon 21 Nov 2016 01:46:14 AM CST, Key ID 24c6a8a7f4a80eb5
Source RPM : gcc-4.8.5-11.el7.src.rpm
Build Date : Sat 05 Nov 2016 12:01:22 AM CST
Build Host : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://gcc.gnu.org
Summary : Various compilers (C, C++, Objective-C, Java, ...)
Description :
The gcc package contains the GNU Compiler Collection version 4.8.
You'll need this package in order to compile C code.
21.2.1.3、rpm -ql
:查看软件的安装位置
rpm -ql gcc
[work@vm10-123-3-2 ~]$ rpm -ql gcc
/usr/bin/c89
/usr/bin/c99
/usr/bin/cc
/usr/bin/gcc
/usr/bin/gcc-ar
/usr/bin/gcc-nm
/usr/bin/gcc-ranlib
/usr/bin/gcov
/usr/bin/x86_64-redhat-linux-gcc
/usr/lib/gcc
/usr/lib/gcc/x86_64-redhat-linux
/usr/lib/gcc/x86_64-redhat-linux/4.8.2
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/32
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/32/crtbegin.o
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/32/crtbeginS.o
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/32/crtbeginT.o
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/32/crtend.o
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/32/crtendS.o
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/32/crtfastmath.o
21.2.1.4、rpm -qf
:查看软件属于哪个包
[work@vm10-123-3-2 ~]$ rpm -qf /usr/bin/gcc-ranlib
gcc-4.8.5-11.el7.x86_64
21.2.3、rpm -i
:安装模式
缺少依赖就会报错,这样缺少哪个就安装哪个,所以不如yum命令和apt-get命令方便
rpm -ivh http-
21.2.4、rpm -e
:删除模式
rpm -e --nodeps python-javapackages-3.4.1-11.el7.noarch
21.3、yum和rpm命令区别
1、rpm是由红帽公司开发的软件包管理方式,使用rpm我们可以方便的进行软件的安装、查询、卸载、升级等工作。但是rpm软件包之间的依赖性问题往往会很繁琐,尤其是软件由多个rpm包组成时。
2、Yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器。基於RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软体包,无须繁琐地一次次下载、安装
21.4、apt-get
:Ubuntu 安装软件
21.4.1、apt-get update:更新
21.4.2、apt-get install nginx :安装ngingx
21.4.3、apt-get remove openjdk :卸载openjdk
22、wget:下载文件
wget http://sw.bos.baidu.com/sw-search-sp/software/991c736e7065f/BaiduNetdisk_5.6.2.1.exe
23、ping
、nslookup
、telent
23.1、nslookup
和ping
ping出来的是一台服务器的IP,(如果有多台服务器,则随机出现ip而nslookup是查看该域名有哪几台服务器提供服务,很多公司都使用了负载均衡技术,将用户的访问随机定到某一台服务器上,所以你ping的可能有时候不一样,而nslookup则能看到所有提供服务的服务器
23.2、telnet
23.2.1、telnet ip port
查某个端口是否打开
telnet 39.97.176.134 6666
24、用户,组的添加
24.1、groupadd
:添加用户组
groupadd mysql
24.2、useradd
:添加用户到用户组
添加用户mysql(第一个为用户) 到用户组mysql
useradd -g mysql mysql
24.3、chown -R
修改当前目录的拥有者为其他用户
修改当前目录mysql拥有者为mysql用户,mysql组
chown -R mysql:mysql ./
修改目录/usr/weblogic拥有者为weblogic用户,weblogic组 ,后面的路径表示目录(参考MySQL安装)
chown -R weblogic:weblogic /usr/weblogic
修改test.xml的用户为weblogic
chown weblogic test.xml
25、环境变量的配置
25.1、java
export MYSQL_HOME="/usr/local/mysql"
export PATH="$PATH:$MYSQL_HOME/bin"
JAVA_HOME=/usr/local/java1.7.0_80
JRE_HOME=/usr/local/java1.7.0_80/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME PATH
25.2、mysql
#mysql
export MYSQL_HOME="/usr/local/mysql-5.7.21-macos10.13-x86_64"
export PATH="$PATH:$MYSQL_HOME/bin"
#maven java 安装自动已经具备了
export M2_HOME="/Library/apache-maven-3.3.9"
export PATH="$M2_HOME/bin:$PATH"
26、执行 sh文件
26.1、相对路径
26.1.1、直接./加上文件名.sh(hello.sh必须有x权限)
26.1.2、直接sh 加上文件名.sh(hello.sh可以没有x权限)
./hello.sh
sh hello.sh
26.2、绝对路径
./home/test/shell/hello.sh
/home/test/shell/hello.sh
sh /home/test/shell/hello.sh
环境变量可以,直接写hello.sh
27、ssh:连接服务器
记得输入yes,之后会要求输入密码
ssh root@192.168.1.1 -p 27505
ssh -i ~/.ssh/id_rsa_dev_test work@127.0.0.1
ssh 用户名@relay.xiaomi.com
28、sed
:替换字符串
28.1、sed -i
:直接对文本文件进行操作的
sed -i 's/原字符串/新字符串/' /home/1.txt //只替每行的第一个
sed -i 's/原字符串/新字符串/g' /home/1.txt //替换所有的
这两条命令的区别就是,看示例吧
#cat 1.txt
d
ddd
#ff
sed -i 's/d/7523/' /home/1.txt
执行结果
7523
7523dd
#ff
sed -i 's/d/7523/g' /home/1.txt
执行结果
7523
752375237523
#ff
28.2、删除字符串
sed -i '/字符串/d' file
29、上传、下载
29.1、scp
:命令上传、 下载
29.1.1、下载文件
scp username@servername:/path/filename /var/www/local_dir(本地目录)
29.1.2、下载目录
scp -r username@servername:/var/www/remote_dir/(远程目录) /var/www/local_dir(本地目录)
29.1.3、上传文件
scp -r filename username@servername:remote_dir
29.1.3、上传目录
scp -r local_dir username@servername:remote_dir
29.2、sz
、rz
软件和命令上传、下载
远程连接Linux服务器进行操作时总会需要上传、下载文件。要实现这个目的,既可以通过FTP的方式, 也可以在本地终端使用scp命令。
但如果是使用Xshell等工具操作服务器的话,最简单的方法就是其自带支持的
sz
、rz
命令了。
29.2.1、sz
:下载
sz –be filename
-a 以文本方式传输(ascii)。
-b 以二进制方式传输(binary)。
29.2.2、rz
:上传
rz –be
30、软链接、硬链接
30.1、ln -s
软链接(相当于还是原来的文件)
就是一个快捷方式和我们常见的快捷方式一模一样
ln -s 绝对路径 绝对路径/相对路径
30.1.1、软连接是文件的时候
30.1.1.1、删除
1、删除软链接文件,源文件没有任何影响
2、删除源文件,软链接文件不可用(linux 文件查看颜色会从正常的颜色,变成红色),如下
root@healerjean:/usr/local/service/logs# ll
total 20
drwxrwxrwx 4 root root 4096 Jan 15 17:52 ./
drwxrwxrwx 5 root root 4096 Jan 14 18:52 ../
drwxrwxrwx 4 root root 4096 Jan 14 18:45 iku/
drwxrwxrwx 2 root root 4096 Jan 14 19:19 nginx/
lrwxrwxrwx 1 root root 32 Jan 15 17:52 test2.txt -> /usr/local/service/logs/test.txt
-rw-r--r-- 1 root root 103 Jan 15 17:50 test.txt
root@healerjean:/usr/local/service/logs# rm test.txt
root@healerjean:/usr/local/service/logs# ll
total 16
drwxrwxrwx 4 root root 4096 Jan 15 17:52 ./
drwxrwxrwx 5 root root 4096 Jan 14 18:52 ../
drwxrwxrwx 4 root root 4096 Jan 14 18:45 iku/
drwxrwxrwx 2 root root 4096 Jan 14 19:19 nginx/
lrwxrwxrwx 1 root root 32 Jan 15 17:52 test2.txt -> /usr/local/service/logs/test.txt
root@healerjean:/usr/local/service/logs# cat test2.txt
cat: test2.txt: No such file or directory
root@healerjean:/usr/local/service/logs#
30.1.1.2、修改
内容:无论修改哪一个文件内容,两个文件都会跟着变化,因为类似于快捷方式
文件名:修改文件名,两个文件不会变化
30.1.2、目录
30.1.2.1、删除
1、删除软链接目录,源目录没有任何影响
2、删除源目录,软链接目录不可用(linux 文件查看颜色会从正常的颜色,变成红色),如下
30.1.2.2、修改
内容:无论修改哪一个文件内容,两个文件都会跟着变化,因为类似于快捷方式
文件名:修改文件名,两个文件不会变化
30.2、ln
:硬链接 (创建了一个一样的文件,占内存)
相当于是复制一个文件,只能是文件复制,不可以是目录,
作用:修改一个文件内容,另外一个也会变化,但是删除是各自删除该文件是各自删除各自的,的互不干扰
ln 绝对路径/相对路径 绝对路径/相对路径
31、iptables
:防火墙
默认情况下,版本高的不使用这个防火墙,而是使用的
firewalld
,当使用iptables
命令的时候会提示下面的错误
错误:service iptables save 出现”Failed to restart iptables.service: Unit iptables.service failed to load: No such file or directory.”
31.1、命令
31.1.1、停止,并且禁用firewalld
systemctl stop firewalld
systemctl mask firewalld
31.1.2、安装iptables
yum –y install iptables-services
31.1.3、开机启动 iptables
systemctl enable iptables
31.1.4、查看防火墙状态
service iptables status
31.1.5、启动防火墙
service iptables start
31.1.6、关闭防火墙(开机后还会启动)
service iptables stop
31.1.7、禁用防火墙(永久)
chkconfig iptables off
31.1.8、启用防火墙
chkconfig iptables on
31.2、外网访问Linux修改配置
如果使用外面访问
linux
的tomcat
首先需要配置/etc/selinux/config
,找到SELINUX=enforcin
g,将其修改为SELINUX=disabled
31.2.1、检测selinux
状态
/usr/sbin/sestatus -v
31.3、配置防火墙 /etc/sysconfig/iptables
1、我是个二货,我将代码一直放到了commit后面,太二货了,找了好久才发现,
2、而且配置文件中使用的是Firewall,更傻逼,如果这个配置文件错误了,防火墙命令start根本不能用。
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
32、curl
32.1、curl
:单个文件查看
curl http://www.centos.org
32.2、curl -I
:查看请求返回信息,验证是否有权限访问
curl -I https://www.baidu.com/
curl -I http://127.0.0.1:9999
root@healerjean:/usr/local/service/logs# curl -I https://www.baidu.com/
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Connection: keep-alive
Content-Length: 277
Content-Type: text/html
Date: Wed, 15 Jan 2020 11:35:52 GMT
Etag: "575e1f60-115"
Last-Modified: Mon, 13 Jun 2016 02:50:08 GMT
Pragma: no-cache
Server: bfe/1.0.8.18
root@healerjean:/usr/local/service/logs# curl -I http://127.0.0.1:9999
HTTP/1.1 404
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Wed, 15 Jan 2020 11:37:19 GMT
root@healerjean:/usr/local/service/logs# curl -I http://127.0.0.1:6666
HTTP/1.1 403 Forbidden
Server: nginx/1.10.3 (Ubuntu)
Date: Wed, 15 Jan 2020 11:37:31 GMT
Content-Type: text/html
Content-Length: 178
Connection: keep-alive
32.2、curl -o、curl -O
:文件下载
32.2.1、-o
:将文件保存为命令行中指定的文件名的文件中
curl -o down.html http://www.gnu.org/software/gettext/manual/gettext.html
root@healerjean:/usr/local/service/logs# curl -o down.html http://www.gnu.org/software/gettext/manual/gettext.html
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1487k 100 1487k 0 0 433k 0 0:00:03 0:00:03 --:--:-- 433k
root@healerjean:/usr/local/service/logs# ll
total 2992
drwxrwxrwx 4 root root 4096 Jan 15 19:23 ./
drwxrwxrwx 5 root root 4096 Jan 14 18:52 ../
-rw-r--r-- 1 root root 1523198 Jan 15 19:22 down.html
drwxrwxrwx 4 root root 4096 Jan 14 18:45 iku/
drwxrwxrwx 2 root root 4096 Jan 14 19:19 nginx/
32.2.2、-O
:使用URL中默认的文件名保存文件到本地
curl -O http://www.gnu.org/software/gettext/manual/gettext.html
root@healerjean:/usr/local/service/logs# curl -O http://www.gnu.org/software/gettext/manual/gettext.html
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1487k 100 1487k 0 0 677k 0 0:00:02 0:00:02 --:--:-- 677k
root@healerjean:/usr/local/service/logs# ll
total 2992
drwxrwxrwx 4 root root 4096 Jan 15 19:23 ./
drwxrwxrwx 5 root root 4096 Jan 14 18:52 ../
-rw-r--r-- 1 root root 1523198 Jan 15 19:22 down.html
-rw-r--r-- 1 root root 1523198 Jan 15 19:23 gettext.html
drwxrwxrwx 4 root root 4096 Jan 14 18:45 iku/
drwxrwxrwx 2 root root 4096 Jan 14 19:19 nginx/
32.3、-u
:从FTP服务器下载文件
32.3.1、-u -o
:列出目录下的所有文件夹和文件
curl -u ftpuser:ftppass -O ftp://ftp_server/public/
32.3.2、-u -o
:下载文件
curl -u ftpuser:ftppass -O ftp://ftp_server/public_html/file.txt
32.4、 -T
上传文件到FTP服务器
32.4.1、上传文件、多个文件
curl -u ftpuser:ftppass -T myfile.txt ftp://ftp.testserver.com
curl -u ftpuser:ftppass -T "{file1,file2}" ftp://ftp.testserver.com
33、which
:查找命令是否存在,以及命令的存放位置在哪儿
查找命令是否存在,以及命令的存放位置在哪儿
root@healerjean:/usr/local/service/logs# which nginx
/usr/sbin/nginx
34、whereis
: 用于搜索程序名
用于搜索程序名
命令 | 说明 |
---|---|
whereis -b |
搜索二进制文件 |
whereis -m |
man说明文件 |
whereis -s |
源代码文件 |
root@healerjean:/usr/local/service/logs# whereis nginx
nginx: /usr/sbin/nginx /etc/nginx /usr/share/nginx
35、df
:磁盘空间查看
35.1、df -k/-m/-h
:显示磁盘使用量和占用率 ,默认是KB
命令 | 说明 |
---|---|
df -k 、 df |
以KB为单位显示磁盘使用量和占用率,默认是KB |
df -m |
以M为单位显示磁盘使用量和占用率 |
df -h |
友好显示,以人们易读的GB、MB、KB等格式显示 |
35.1.1、显示格式说明
格式 | 说明 |
---|---|
Filesystem |
文件系统 |
1K-blocks |
容量 |
Used |
已用 |
Available |
可用 |
Use% |
已用% |
Mounted on |
挂载点 |
35.1.2、命令运行
35.1.2.1、df
、 df -k
:以KB为单位显示磁盘使用量和占用率,默认是KB
root@healerjean:~# df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 2004712 0 2004712 0% /dev
tmpfs 404632 3088 401544 1% /run
/dev/vda1 41151808 5122896 33915484 14% /
tmpfs 2023156 0 2023156 0% /dev/shm
tmpfs 5120 0 5120 0% /run/lock
tmpfs 2023156 0 2023156 0% /sys/fs/cgroup
tmpfs 404632 0 404632 0% /run/user/0
root@healerjean:/usr# df -k
Filesystem 1K-blocks Used Available Use% Mounted on
udev 2004712 0 2004712 0% /dev
tmpfs 404632 3088 401544 1% /run
/dev/vda1 41151808 5122964 33915416 14% /
tmpfs 2023156 0 2023156 0% /dev/shm
tmpfs 5120 0 5120 0% /run/lock
tmpfs 2023156 0 2023156 0% /sys/fs/cgroup
tmpfs 404632 0 404632 0% /run/user/0
35.1.2.2、df -m
:以M为单位显示磁盘使用量和占用率
root@healerjean:~# df -m
Filesystem 1M-blocks Used Available Use% Mounted on
udev 1958 0 1958 0% /dev
tmpfs 396 4 393 1% /run
/dev/vda1 40188 5003 33121 14% /
tmpfs 1976 0 1976 0% /dev/shm
tmpfs 5 0 5 0% /run/lock
tmpfs 1976 0 1976 0% /sys/fs/cgroup
tmpfs 396 0 396 0% /run/user/0
35.1.2.3、df -h
:友好显示,以人们易读的GB、MB、KB等格式显示
root@healerjean:/usr# df -h
Filesystem Size Used Avail Use% Mounted on
udev 2.0G 0 2.0G 0% /dev
tmpfs 396M 3.1M 393M 1% /run
/dev/vda1 40G 4.9G 33G 14% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
tmpfs 396M 0 396M 0% /run/user/0
35.1.3、结果说明
1、文件系统/dev/vdal
是我们真正的磁盘,也可以看到它挂载点是 根目录/
,其他都是根目录下其他的文件夹,而且其实我们看已用百分比就可以看到,除了它比较大一点点,其他基本上都是0
2、文件系统temfs
:是临时文件系统,可以看到它都是挂在到对应的磁盘目录中的,一般情况下,我们只管/dev/vdal
3、所以可以看到整个磁盘的空间是40G
,已经使用了14%
,4.9G
了 还剩33G
可用
36、du
:目录空间查看
命令 | 说明 |
---|---|
du -k 、du |
当前目录:以KB为单位查看当前目录列表中所有目录、多级目录使用量,默认是KB |
du -m |
当前目录:以M为单位查看当前目录列表中所有目录、多级目录使用量 |
du -h |
当前目录:友好显示当前目录列表中所有目录、多级目录使用量, 以人们易读的GB、MB、KB等格式显示 |
du -a |
当前目录包含所有目录、多级目录、所有文件的使用量 |
du -sh |
查看当前目录的使用量 |
du -sh * |
查看当前目录一级目录的使用量 |
du -sh /usr/ |
查看某个目录的使用量 |
du /usr/ |
查看某目录列表中所有文件、目录使用量 |
36.1、查看目录列表中所有文件、目录的使用量
36.1.1、du/ du -k
:当前目录:以KB为单位查看当前目录列表中所有目录、多级目录使用量,默认是KB
root@healerjean:/usr/local/service# du
63036 ./app/iku/iku-client-webh5
64700 ./app/iku/iku-client
127740 ./app/iku
127744 ./app
2136 ./logs/nginx
324 ./logs/iku/iku-client-webh5
48 ./logs/iku/iku-client
376 ./logs/iku
5492 ./logs
1440 ./image/iku/iku-client-webh5
4 ./image/iku/iku-client
1448 ./image/iku
1452 ./image
root@healerjean:/usr/local/service# du -k
63036 ./app/iku/iku-client-webh5
64700 ./app/iku/iku-client
127740 ./app/iku
127744 ./app
2136 ./logs/nginx
324 ./logs/iku/iku-client-webh5
48 ./logs/iku/iku-client
376 ./logs/iku
5492 ./logs
1440 ./image/iku/iku-client-webh5
4 ./image/iku/iku-client
1448 ./image/iku
1452 ./image
134692 .
36.1.2、du -m
:当前目录:以M为单位查看当前目录列表中所有目录、多级目录使用量
du -m
root@healerjean:/usr/local/service# du -m
62 ./app/iku/iku-client-webh5
64 ./app/iku/iku-client
125 ./app/iku
125 ./app
3 ./logs/nginx
1 ./logs/iku/iku-client-webh5
1 ./logs/iku/iku-client
1 ./logs/iku
6 ./logs
2 ./image/iku/iku-client-webh5
1 ./image/iku/iku-client
2 ./image/iku
2 ./image
132 .
36.1.3、du -h
:当前目录:友好显示当前目录列表中所有目录、多级目录使用量,以人们易读的GB、MB、KB等格式显示
du -h
root@healerjean:/usr/local/service# du -h
62M ./app/iku/iku-client-webh5
64M ./app/iku/iku-client
125M ./app/iku
125M ./app
2.1M ./logs/nginx
324K ./logs/iku/iku-client-webh5
48K ./logs/iku/iku-client
376K ./logs/iku
5.4M ./logs
1.5M ./image/iku/iku-client-webh5
4.0K ./image/iku/iku-client
1.5M ./image/iku
1.5M ./image
132M .
36.1.4、du -h /usr/local/service/
:指定友好显示指定目录列表中所有目录、多级目录使用量,
以人们易读的GB、MB、KB等格式显示
du -k /usr/local/service/
du -m /usr/local/service/
du -h /usr/local/service/
root@healerjean:/usr/local/service# du -k /usr/local/service/
63036 /usr/local/service/app/iku/iku-client-webh5
64700 /usr/local/service/app/iku/iku-client
127740 /usr/local/service/app/iku
127744 /usr/local/service/app
2136 /usr/local/service/logs/nginx
324 /usr/local/service/logs/iku/iku-client-webh5
48 /usr/local/service/logs/iku/iku-client
376 /usr/local/service/logs/iku
5492 /usr/local/service/logs
1440 /usr/local/service/image/iku/iku-client-webh5
4 /usr/local/service/image/iku/iku-client
1448 /usr/local/service/image/iku
1452 /usr/local/service/image
134692 /usr/local/service/
root@healerjean:/usr/local/service# du -m /usr/local/service/
62 /usr/local/service/app/iku/iku-client-webh5
64 /usr/local/service/app/iku/iku-client
125 /usr/local/service/app/iku
125 /usr/local/service/app
3 /usr/local/service/logs/nginx
1 /usr/local/service/logs/iku/iku-client-webh5
1 /usr/local/service/logs/iku/iku-client
1 /usr/local/service/logs/iku
6 /usr/local/service/logs
2 /usr/local/service/image/iku/iku-client-webh5
1 /usr/local/service/image/iku/iku-client
2 /usr/local/service/image/iku
2 /usr/local/service/image
132 /usr/local/service/
root@healerjean:/usr/local/service# du -h /usr/local/service/
62M /usr/local/service/app/iku/iku-client-webh5
64M /usr/local/service/app/iku/iku-client
125M /usr/local/service/app/iku
125M /usr/local/service/app
2.1M /usr/local/service/logs/nginx
324K /usr/local/service/logs/iku/iku-client-webh5
48K /usr/local/service/logs/iku/iku-client
376K /usr/local/service/logs/iku
5.4M /usr/local/service/logs
1.5M /usr/local/service/image/iku/iku-client-webh5
4.0K /usr/local/service/image/iku/iku-client
1.5M /usr/local/service/image/iku
1.5M /usr/local/service/image
132M /usr/local/service/
36.1.5、du -a
:当前目录包含所有目录、多级目录、所有文件的使用量
du -ah
root@healerjean:/usr/local/service# du -ah
62M ./app/iku/iku-client-webh5/iku-client-webh5.jar
4.0K ./app/iku/iku-client-webh5/stop.sh
4.0K ./app/iku/iku-client-webh5/restart.sh
4.0K ./app/iku/iku-client-webh5/start.sh
62M ./app/iku/iku-client-webh5
4.0K ./app/iku/iku-client/stop.sh
4.0K ./app/iku/iku-client/restart.sh
4.0K ./app/iku/iku-client/start.sh
64M ./app/iku/iku-client/iku-client.jar
64M ./app/iku/iku-client
125M ./app/iku
125M ./app
2.1M ./logs/nginx/access.log
16K ./logs/nginx/error.log
2.1M ./logs/nginx
1.5M ./logs/down.html
160K ./logs/iku/iku-client-webh5/iku-client-webh5.stdout.log
0 ./logs/iku/iku-client-webh5/iku-client-webh5.stdout.error
160K ./logs/iku/iku-client-webh5/iku-client-webh5.log
324K ./logs/iku/iku-client-webh5
4.0K ./logs/iku/iku-client/cp.txt
0 ./logs/iku/iku-client/iku-client.error
36K ./logs/iku/iku-client/iku-client.stdout.log
4.0K ./logs/iku/iku-client/test.txt
48K ./logs/iku/iku-client
376K ./logs/iku
1.5M ./logs/gettext.html
5.4M ./logs
96K ./image/iku/iku-client-webh5/ikuisme.jpg
1.4M ./image/iku/iku-client-webh5/ikuhelpcenter.jpg
1.5M ./image/iku/iku-client-webh5
4.0K ./image/iku/iku-client
1.5M ./image/iku
1.5M ./image
132M .
36.2、du -sh
:查看某个目录的使用量
du -sh 当前目录
du -sh /usr/ 指定目录:usr目录
root@healerjean:/usr/local/service# du -sh
132M
root@healerjean:/usr# du -sh /usr/
2.8G /usr/
37、top
:cpu使用量
top - 21:09:44 up 219 days, 7:37, 2 users, load average: 0.04, 0.03, 0.00
Tasks: 118 total, 1 running, 117 sleeping, 0 stopped, 0 zombie
%Cpu(s): 1.0 us, 0.7 sy, 0.0 ni, 98.0 id, 0.3 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 4046316 total, 430480 free, 1464136 used, 2151700 buff/cache
KiB Swap: 0 total, 0 free, 0 used. 2258136 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
12165 root 10 -10 136508 17196 14520 S 2.0 0.4 1810:00 AliYunDun
25044 root 20 0 3532516 620744 17324 S 0.7 15.3 10:18.50 java
28178 root 20 0 3516784 588380 17000 S 0.7 14.5 4:15.60 java
7 root 20 0 0 0 0 S 0.3 0.0 92:27.21 rcu_sched
1 root 20 0 37772 5652 3844 S 0.0 0.1 11:05.70 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.55 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 3:40.50 ksoftirqd/0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
9 root rt 0 0 0 0 S 0.0 0.0 0:01.91 migration/0
10 root rt 0 0 0 0 S 0.0 0.0 1:12.97 watchdog/0
11 root rt 0 0 0 0 S 0.0 0.0 1:03.37 watchdog/1
12 root rt 0 0 0 0 S 0.0 0.0 0:01.92 migration/1
13 root 20 0 0 0 0 S 0.0 0.0 4:44.08 ksoftirqd/1
15 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/1:0H
16 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kdevtmpfs
17 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 netns
18 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 perf
19 root 20 0 0 0 0 S 0.0 0.0 0:08.80 khungtaskd
20 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 writeback
21 root 25 5 0 0 0 S 0.0 0.0 0:00.00 ksmd
22 root 39 19 0 0 0 S 0.0 0.0 1:24.81 khugepaged
23 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 crypto
24 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kintegrityd
25 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 bioset
26 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kblockd
27 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 ata_sff
28 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 md
29 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 devfreq_wq
34 root 20 0 0 0 0 S 0.0 0.0 0:00.62 kswapd0
35 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 vmstat
37.1、输出日志分析
第一行、任务队列信息
top - 21:09:35 up 219 days, 7:37, 2 users, load average: 0.04, 0.03, 0.00
格式 | 说明 |
---|---|
21:10:23 | 系统当前时间 |
up 219 days | 主机已运行时间 ,219天了 |
2 users | 用户连接数(不是用户数,who命令) |
load average: 0.07, 0.03, 0.00 | 系统平均负载,统计最近1,5,15分钟的系统平均负载 |
@:1、load average:系统平均负载
top命令中load average显示的是最近1分钟、5分钟和15分钟的系统平均负载。系统平均负载表示
系统平均负载被定义为在特定时间间隔内运行队列中(在CPU上运行或者等待运行多少进程)的平均进程数。如果一个进程满足以下条件则其就会位于运行队列中:
1、它没有在等待I/O操作的结果
2、 它没有主动进入等待状态(也就是没有调用’wait’)
3、 没有被停止(例如:等待终止)
第二行:进程信息 :进程数相关
Tasks: 215 total, 2 running, 213 sleeping, 0 stopped, 0 zombie
格式 | 说明 |
---|---|
Tasks: 215 total | 进程总数 |
2 running | 正在运行的进程数 |
213 sleeping | 睡眠的进程数,正在睡眠的进程,正在等待事件完成,但可被唤醒 |
0 stopped | 停止的进程数 |
0 zombie | 僵尸进程数,进程已经终止但却无法被删除至内存外 |
@:1、僵尸进程数 (遇到再说吧,现在简单看一下概念)
当一个进程死亡并退出,但是父进程并没有获取到他的返回代码,这个进程就会变成僵尸进程,僵尸进程会一直以终止状态保持在进程表里并会一直等待父进程获取其退出状态。所以只要子进程退出,父进程还在运行,但父进程没有读取子进程的进程状态,子进程进入Z状态。那么如果父进程退出了呢?它就会变成孤儿进程,被init进程回收
第三行:CPU信息:显示占用百分比
一般情况下我们关注 `us`、`sy`、`id`就可以
%Cpu(s): 6.4 us, 0.1 sy, 0.0 ni, 93.5 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
格式 | 说明 |
---|---|
6.4 us |
运行(未调整优先级的) 用户进程的CPU时间 |
0.1 sy |
内核空间占用CPU百分比 |
0.0 ni |
运行已调整优先级的用户进程的CPU时间 |
93.5 id |
空闲CPU百分比 |
0.0 wa |
等待输入输出的CPU时间百分比 |
0.0 hi |
硬件CPU中断占用百分比 |
0.0 si |
软中断占用百分比 |
0.0 st |
虚拟机占用百分比 |
@:1、%cpu
表示什么
这里显示的所有的cpu加起来的使用率,说明你的CPU是多核,你运行top后按大键盘1看看,可以显示每个cpu的使用率,top里显示的是把所有使用率加起来
@:2、用户空间与内核空间
用户空间应用程序往往需要调用硬件(QQ调用相机拍照)或者运行与系统核心相关的内容(360清理进程),免不了与内核打交道,他们之间调用关系又是怎样呢?
交流关系以open()
文件打开函数为例
上层应用在用户空间执行到
open()
函数时,会触发系统软中断,系统调用 系统调用函数sys_open()
,在内核空间执行open代码,这样用户空间的open函数内部代码就取得了在内核空间运行的权限,可以做一些比较牛比较核心的事情。
@:3、关注点
关于CPU还有重要要说明 ,看大部队
第四行:运行内存信息(单位KB)
纳入内核管理的内存不见得都在使用中,还包括过去使用过的现在可以被重复利用的内存,内核并不把这些可被重新使用的内存交还到free中去,因此在`linux`上free内存会越来越少,但不用为此担心。
4046316 total, 430480 free, 1464136 used, 2151700 buff/cache
格式 | 说明 |
---|---|
32780396 total | 物理内存总量 |
430480 free | 总量空闲的内存总量(free+used=total) |
1464136 used | 已使用的内存 |
2151700 buff/cache | 用作内核缓存的内存量 |
第五行:swap信息 虚拟内存使用(交换空间)
对于内存监控,在top里我们要时刻监控第五行swap交换分区的used,如果这个数值在不断的变化,说明内核在不断进行内存和swap的数据交换,这是真正的内存不够用了。
KiB Swap: 0 total, 0 free, 0 used. 2258136 avail Mem
格式 | 说明 |
---|---|
0 total | 交换区总量 |
0 free | 空闲交换区总量 |
0 used | 已使用的交换分区总量 |
16426028 avail Mem | 可用交换取总量, |
第六行:大部队 (关于下面的内存,我要重点看了,这玩意到底是个啥)
格式 | 说明 |
---|---|
PID |
进程id |
USER |
进程所有者的用户名 |
PR |
优先级,动态优先级priority |
NI |
静态优先级、nice值 |
VIRT |
进程使用的虚拟内存总量,单位kb 。 |
RES |
进程使用的物理内存的大小 |
SHR |
进程使用的共享内内存 |
S |
进程状态(D=不可中断的睡眠状态,R=运行,S=睡眠,T=跟踪/停止,Z=僵尸进程) |
%CPU |
上次更新到现在的CPU时间占用百分比 |
%MEM |
进程使用的物理内存和总内存的百分比 |
TIME |
进程所使用的CPU时间总计,单位1/100秒 |
COMMAND |
启动进程的命令的名称和参数 |
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
30030 work 20 0 10.338g 1.034g 5180 S 100.0 3.3 33568:33 java 16587 work 20 0 10.335g 1.248g 23332 S 6.7 4.0 120:49.18 java 423411 root 20 0 43472 2596 1252 S 0.0 0.0 6:43.18 systemd 412342 root 20 0 0 0 0 S 0.0 0.0 0:00.08 kthreadd
@:1、参数解释 :
1.1、PR:优先级 (动态优先级priority)、
我们也统一将“优先级”这个词的概念规定为表示priority值的意思。 Linux实际上实现了140个优先级范围,取值范围是从0-139,这个值越小,优先级越高。
nice值的-20到19,映射到它实际的优先级范围是100-139。
使用说明:
1、Java
程序默认执行优先级为20,nice为0
1.2、NI
:静态优先级、nice值
负值表示高优先级,正值表示低优先级-20至19,一共40个
1、这个值越小,表示进程”优先级”越高,而值越大“优先级”越低。越nice的人抢占资源的能力就越差,而越不nice的人抢占能力就越强。这就是nice值大小的含义
2、用
nice
和renice
命令来调整的优先级;
使用说明:
1、Java
程序默认执行优先级为20,nice为0
1.3、VIRT
:进程使用的虚拟内存总量,单位kb
。
1、进程“需要的”虚拟内存大小,包括进程使用的库、代码、数据,以及
malloc
、new分配的堆空间和分配的栈空间等;2、假如进程新申请
10MB
的内存,但实际只使用了1MB
,那么它会增长10MB
,而不是实际的1MB
使用量3、
VIRT
=SWAP
+RES
使用说明:
1、目前看来没什么重要的
1.4、RES
: 进程使用的物理内存的大小(重要)
1、进程当前使用的内存大小,包括使用中的
malloc
、new分配的堆空间和分配的栈空间,但不包括swap out量;2、包含其他进程的共享;
3、如果申请
10MB
的内存,实际使用1MB
,它只增长1MB
,与VIRT
相反;4、
RES
=CODE
+DATA
DATA
1、数据占用的内存。如果top没有显示,按f键可以显示出来。2、真正的该程序要求的数据空间,是真正在运行中要使用的,个人理解:代码执行需要的。
使用说明:
1.5、SHR
: 进程使用的共享内内存
1、除了自身进程的共享内存,也包括其他进程的共享内存;
2、虽然进程只使用了几个共享库的函数,但它包含了整个共享库的大小
3、计算某个进程所占的物理内存大小公式:
RES
–SHR
;4、swap out后,它将会降下来
1.6、S
:进程状态
D=不可中断的睡眠状态
R=运行
S=睡眠
T=跟踪/停止
Z=僵尸进程
1.7、%CPU
: 上次更新到现在的CPU时间占用百分比
在系统负荷方面,多核CPU与多CPU效果类似,所以考虑系统负荷的时候,必须考虑这台电脑有几个CPU、每个CPU有几个核心,只要保证平均每个核心的负荷不超过1.0,就表明电脑正常运行,如果确实是系统压力吃紧,这种情况是正常的。系统平均负载算出来的逻辑和这里的说的是一回事 。显示的是进程占用一个核的百分比,而不是整个CPU的百分比,有时候如果大于100了,那是因为该进程用了多线程占用了多个核心 ,多核cpu时代,有时候如果系统比较大,也是很正常的 。
抬头中的默认是总CPU, 按1命令之后,如果有
多核心cpu
,会显示所有逻辑CPU
占用情况(逻辑CPU见内容42)。 top命令之后按1就可以看到其他的CPU情况了,而下面表格中的%cpu
1.8、%MEM
:进程使用的物理内存和总内存的百分比
该项目实际占用的物理空间内存百分比
@:2、命令解释
@@: 2.1、1
显示多个cpu执行情况
top后直接显示的`cpu`默认显示的`总cpu`,什么意思呢?
就是说如果有多核心cpu
,会显示所有逻辑CPU
占用情况(逻辑CPU见内容42)。 top命令之后按1就可以看到其他的CPU情况了,而下面表格中的%cpu
显示的是进程占用一个核的百分比,而不是整个CPU的百分比,有时候如果大于100了,那是因为该进程用了多线程占用了CPU,多个核心
Tasks: 222 total, 2 running, 220 sleeping, 0 stopped, 0 zombie
%Cpu0 : 0.0 us, 1.0 sy, 0.0 ni, 99.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
%Cpu1 : 1.0 us, 0.0 sy, 0.0 ni, 99.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
%Cpu2 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
%Cpu3 :100.0 us, 0.0 sy, 0.0 ni, 0.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
%Cpu4 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
%Cpu5 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
%Cpu6 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
%Cpu7 : 0.0 us, 1.0 sy, 0.0 ni, 99.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
%Cpu8 : 1.0 us, 0.0 sy, 0.0 ni, 99.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
%Cpu9 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
%Cpu10 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
%Cpu11 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
%Cpu12 : 0.0 us, 1.0 sy, 0.0 ni, 99.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
%Cpu13 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
%Cpu14 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
%Cpu15 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 32780396 total, 3229812 free, 14268924 used, 15281660 buff/cache
KiB Swap: 0 total, 0 free, 0 used. 16398644 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 30030 work 20 0 10.338g 1.034g 5180 S 100.0 3.3 33573:45 java 3166 work 20 0 10.120g 805828 4456 S 1.0 2.5 612:42.83 java 12523 work 20 0 10.307g 1.015g 7364 S 1.0 3.2 57:11.89 java 27862 work 20 0 162056 2412 1588 S 1.0 0.0 0:02.02 top 28921 work 20 0 162056 2396 1568 R 1.0 0.0 0:00.44 top
@@:2.2、P:根据CPU使用百分比大小进行排序
top - 19:57:34 up 209 days, 23:28, 7 users, load average: 1.00, 1.02, 1.05
Tasks: 220 total, 1 running, 219 sleeping, 0 stopped, 0 zombie
%Cpu(s): 6.4 us, 0.1 sy, 0.0 ni, 93.5 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 32780396 total, 3191436 free, 14263632 used, 15325328 buff/cache
KiB Swap: 0 total, 0 free, 0 used. 16403992 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
30030 work 20 0 10.338g 1.034g 5180 S 100.3 3.3 33715:06 java 8744 work 20 0 10.265g 0.984g 5448 S 0.7 3.1 223:51.40 java 12523 work 20 0 10.307g 1.015g 7364 S 0.7 3.2 57:35.84 java 12566 work 20 0 11.015g 1.441g 7812 S 0.7 4.6 100:58.45 java 3166 work 20 0 10.120g 805828 4456 S 0.3 2.5 613:03.48 java 4989 work 20 0 10.180g 919996 6252 S 0.3 2.8 133:03.37 java
@@:2.3、M:根据驻留内存大小进行排序
38、xargs
38.1、文本内容相关
healerjean$ cat -n text.txt
1 a b c d e f g
2 h i j k l m n
3 o p q
4 r s t
38.1.1、| xargs
:单行输出文本所有内容
healerjean$ cat text.txt | xargs
a b c d e f g h i j k l m n o p q r s t
38.1.2、| xargs -n4
:选择每行打印多少个(按照空格和换行来进行分组)
-n多行输出:后面直接加数字
healerjean$ cat text.txt | xargs -n4
a b c d
e f g h
i j k l
m n o p
q r s t
38.1.3、 | xargs -dX
:按照字符X
,分隔一串字符串
-d 选项可以自定义一个定界符:
healerjean$ echo "nameXnameXnameXname" | xargs -dX
name name name name
38.1.4、 -d -n 联合使用
echo "nameXnameXnameXname" | xargs -dX -n2
name name
name name
38.2、组合多个命令
38.2.1、(查询->删除)
删除vedio开头的键
keys vedio* | xargs redis-cli del
查询文件名为.svn的,然后删除
find . -name ".svn"| xargs rm -Rf
删除镜像
docker images | grep registry.cn-qingdao.aliyuncs.com/duodianyouhui/dev-server | xargs docker rmi
42、Linux查看物理CPU个数、核数、逻辑CPU个数
物理cpu
数:主板上实际插入的
cpu数量 (
physical id`)
cpu核数
:单块CPU上面能处理数据的芯片组的数量,如双核、四核等 (cpu cores
)
逻辑cpu
数:一般情况下,逻辑cpu
=物理CPU
个数×每颗核数,如果不相等的话,则表示服务器的CPU支持超线程技术(HT:简单来说,它可使处理器中的1 颗内核如2 颗内核那样在操作系统中发挥作用。这样一来,操作系统可使用的执行资源扩大了一倍,大幅提高了系统的整体性能,此时逻辑cpu
=物理CPU个数×每颗核数x2) 这个就是我们top命令系统平均负载的参考值
42.1、cat /proc/cpuinfo
,查看cpu
中信息
变量 | 说明 |
---|---|
processor | 逻辑处理器的id。 |
physical id | 物理处理器的id |
core id | 每个核心的id。 |
cpu cores | 一个物理CPU有几个核 |
siblings | 一个物理CPU有几个逻辑CPU |
是否为超线程?
如果siblings
和cpu cores
一致,则说明不支持超线程,或者超线程未打开。
如果siblings
是cpu cores
的两倍, 有两个逻辑CPU具有相同的core id
,那么支持并且,超线程是打开的。
物理CPU个数:cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l
查看CPU是几核的:cat /proc/cpuinfo | grep "cores" | uniq
逻辑CPU个数 :cat /proc/cpuinfo | grep "processor" | wc -l
42.1.1、我米测试服务器
物理CPU数 :16
[work@vm10-123-3-2 ~]$ cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l
16
单个CPU的逻辑核心数量 :1 (如果物理CPU的逻辑核心数量不同,则会显示多行)
[work@vm10-123-3-2 ~]$ cat /proc/cpuinfo | fgrep "cores" | uniq
cpu cores : 1
逻辑CPU数量:16
[work@vm10-123-3-2 ~]$ cat /proc/cpuinfo | grep "processor" | wc -l
16
**总结:这台机器拥有16和物理CPU,每个CPU有1个逻辑核心,系统一共拥有16个逻辑CPU数量。显然没有开启多线程,而且观察siblings
不是cpu cores
的两倍,理由成立 **
[work@vm10-123-3-2 ~]$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 94
model name : Intel Core Processor (Skylake)
stepping : 3
microcode : 0x1
cpu MHz : 2599.998
cache size : 19712 KB
physical id : 0
siblings : 1
core id : 0
cpu cores : 1
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1
bogomips : 5199.99
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 94
model name : Intel Core Processor (Skylake)
stepping : 3
microcode : 0x1
cpu MHz : 2599.998
cache size : 19712 KB
physical id : 1
siblings : 1
core id : 0
cpu cores : 1
apicid : 1
initial apicid : 1
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1
bogomips : 5199.99
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
processor : 2
vendor_id : GenuineIntel
cpu family : 6
model : 94
model name : Intel Core Processor (Skylake)
stepping : 3
microcode : 0x1
cpu MHz : 2599.998
cache size : 19712 KB
physical id : 2
siblings : 1
core id : 0
cpu cores : 1
apicid : 2
initial apicid : 2
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1
bogomips : 5199.99
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
processor : 3
vendor_id : GenuineIntel
cpu family : 6
model : 94
model name : Intel Core Processor (Skylake)
stepping : 3
microcode : 0x1
cpu MHz : 2599.998
cache size : 19712 KB
physical id : 3
siblings : 1
core id : 0
cpu cores : 1
apicid : 3
initial apicid : 3
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1
bogomips : 5199.99
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
processor : 4
vendor_id : GenuineIntel
cpu family : 6
model : 94
model name : Intel Core Processor (Skylake)
stepping : 3
microcode : 0x1
cpu MHz : 2599.998
cache size : 19712 KB
physical id : 4
siblings : 1
core id : 0
cpu cores : 1
apicid : 4
initial apicid : 4
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1
bogomips : 5199.99
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
processor : 5
vendor_id : GenuineIntel
cpu family : 6
model : 94
model name : Intel Core Processor (Skylake)
stepping : 3
microcode : 0x1
cpu MHz : 2599.998
cache size : 19712 KB
physical id : 5
siblings : 1
core id : 0
cpu cores : 1
apicid : 5
initial apicid : 5
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1
bogomips : 5199.99
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
processor : 6
vendor_id : GenuineIntel
cpu family : 6
model : 94
model name : Intel Core Processor (Skylake)
stepping : 3
microcode : 0x1
cpu MHz : 2599.998
cache size : 19712 KB
physical id : 6
siblings : 1
core id : 0
cpu cores : 1
apicid : 6
initial apicid : 6
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1
bogomips : 5199.99
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
processor : 7
vendor_id : GenuineIntel
cpu family : 6
model : 94
model name : Intel Core Processor (Skylake)
stepping : 3
microcode : 0x1
cpu MHz : 2599.998
cache size : 19712 KB
physical id : 7
siblings : 1
core id : 0
cpu cores : 1
apicid : 7
initial apicid : 7
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1
bogomips : 5199.99
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
processor : 8
vendor_id : GenuineIntel
cpu family : 6
model : 94
model name : Intel Core Processor (Skylake)
stepping : 3
microcode : 0x1
cpu MHz : 2599.998
cache size : 19712 KB
physical id : 8
siblings : 1
core id : 0
cpu cores : 1
apicid : 8
initial apicid : 8
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1
bogomips : 5199.99
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
processor : 9
vendor_id : GenuineIntel
cpu family : 6
model : 94
model name : Intel Core Processor (Skylake)
stepping : 3
microcode : 0x1
cpu MHz : 2599.998
cache size : 19712 KB
physical id : 9
siblings : 1
core id : 0
cpu cores : 1
apicid : 9
initial apicid : 9
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1
bogomips : 5199.99
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
processor : 10
vendor_id : GenuineIntel
cpu family : 6
model : 94
model name : Intel Core Processor (Skylake)
stepping : 3
microcode : 0x1
cpu MHz : 2599.998
cache size : 19712 KB
physical id : 10
siblings : 1
core id : 0
cpu cores : 1
apicid : 10
initial apicid : 10
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1
bogomips : 5199.99
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
processor : 11
vendor_id : GenuineIntel
cpu family : 6
model : 94
model name : Intel Core Processor (Skylake)
stepping : 3
microcode : 0x1
cpu MHz : 2599.998
cache size : 19712 KB
physical id : 11
siblings : 1
core id : 0
cpu cores : 1
apicid : 11
initial apicid : 11
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1
bogomips : 5199.99
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
processor : 12
vendor_id : GenuineIntel
cpu family : 6
model : 94
model name : Intel Core Processor (Skylake)
stepping : 3
microcode : 0x1
cpu MHz : 2599.998
cache size : 19712 KB
physical id : 12
siblings : 1
core id : 0
cpu cores : 1
apicid : 12
initial apicid : 12
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1
bogomips : 5199.99
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
processor : 13
vendor_id : GenuineIntel
cpu family : 6
model : 94
model name : Intel Core Processor (Skylake)
stepping : 3
microcode : 0x1
cpu MHz : 2599.998
cache size : 19712 KB
physical id : 13
siblings : 1
core id : 0
cpu cores : 1
apicid : 13
initial apicid : 13
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1
bogomips : 5199.99
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
processor : 14
vendor_id : GenuineIntel
cpu family : 6
model : 94
model name : Intel Core Processor (Skylake)
stepping : 3
microcode : 0x1
cpu MHz : 2599.998
cache size : 19712 KB
physical id : 14
siblings : 1
core id : 0
cpu cores : 1
apicid : 14
initial apicid : 14
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1
bogomips : 5199.99
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
processor : 15
vendor_id : GenuineIntel
cpu family : 6
model : 94
model name : Intel Core Processor (Skylake)
stepping : 3
microcode : 0x1
cpu MHz : 2599.998
cache size : 19712 KB
physical id : 15
siblings : 1
core id : 0
cpu cores : 1
apicid : 15
initial apicid : 15
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1
bogomips : 5199.99
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
42.1.2、其他案例测试
processor | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
physical id | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 |
core id | 0 | 2 | 1 | 3 | 0 | 2 | 1 | 3 |
siblings | 4 | 4 | 4 | 4 | 4 | 4 | 4 | 4 |
cpu cores | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 |
1、逻辑处理器 0 和 4 驻留在物理封装 0 的内核 0 上,siblings
是cpu cores
逻辑处理室是核心数的两倍, ,这就表示逻辑处理器 0 和 4 支持超线程(HT)技术 ,同样 逻辑处理器1和5、2和6、3和7同样如此。 该配置为配置为支持超线程技术的2个2核和CPU
这就表示支持超线程技术,因为两个逻辑处理器共享一个内核。 而上面的服务器
43、远程连接Linux
43.1、直接连接
ssh root@127.0.0.1
43.2、秘钥连接
ssh -i ~/.ssh/id_rsa root@127.0.0.1
44、文件文本查看命令
命令 | 说明 |
---|---|
tail -n 100 /data/webapps/appenv | grep 's' --color |
查看某个字符串所在行的内容 |
cat *filename | head -n 3000 | tail -n +1000 |
显示1000行到3000行 |
44.1、head
:从头开始查看
命令 | 说明 |
---|---|
head -n 2 file1 |
查看一个文件的前两行 |
44.2、tail
:从末尾接着看
shell
中经常用,用来显示屏幕中的进度,一般用来实时浏览日志
命令 | 说明 |
---|---|
tail -f filename |
输出最后10行内容,同时监视文件的改变,只要文件有一变化就显示出来。 |
tail -500f filename |
输出文件最后n行的内容,同时 监视文件的改变,只要文件有一变化就同步刷新并显示出来 |
tail -n 5 filename |
输出文件最后5行的内容 |
tail -n +1000 file1 |
从1000行开始显示,显示1000行以后的 |
44.3、find
44.3.1、-name
:通过名字查询,-iname
不区分大小写
find . -name '*.txt' |grep test
healerjean$ find . -name '*.txt' |grep test
./study/cant-breathe/13、redis/7/1、spring redis/spring-redis-test.txt
./study/HealerJean.github.io/_posts/DDKJ/3、AngularJS_Vue/Vue/模板/element-starter/node_modules/hoek/test/modules/ignore.txt
44.3.2、-type
: 根据文件类型查找(f文件,d目录,l软链接文件
find . -type f -name "text.txt"
healerjean$ find . -type f -name "text.txt"
./text.txt
./workspace/duodianyouhui/youhui-admin/node_modules/vue-resource/test/data/text.txt
40.3.3 -print -print0
-
print0
则不会直接连起来变成一行。
root@AaronWong shell_test]# find /ABC/ -type l -print
/home/AaronWong/ABC/libcvaux.so
/home/AaronWong/ABC/libgomp.so.1
/home/AaronWong/ABC/libcvaux.so.4
[root@AaronWong shell_test]# find /ABC/ -type l -print0
/home/AaronWong/ABC/libcvaux.so/home/AaronWong/ABC/libgomp.so.1/home/AaronWong/ABC/libcvaux.so.4/hom
44.4、grep
命令 | 说明 |
---|---|
grep a text.txt |
查看某个字符串所在行的内容 |
grep -n keyword filename |
查看某个字符串所在行的内容,并显示行号 |
grep -i keyword filename |
列出所搜索内容的匹配行,搜索过程中不区分大小写 |
grep -A 5 keyword filename |
显示匹配到的后5行 |
grep -B 5 keywordf filename |
显示匹配到的前5行 |
grep -C 5 keyword filename |
显示匹配到的前后5行,同下 |
grep -E "word1|word2|word3" file.txt |
满足任意条件(word1、word2和word3之一)将匹配。 |
grep word1 file.txt |grep word2 |grep word3 |
必须同时满足三个条件(word1、word2和word3)才匹配。 |
grep -5 *keyword filename |
显示匹配到的前后5行,模糊匹配 |
grep -c keyword filename |
返回一个文件中某个字符串的个数 |
grep -c keyword 文件名1 文件名2 |
返回多个文件中, 某个字符串各自的个数 |
grep --color keyword filename |
表示搜索出的内容进行高亮显示(带颜色) |
44.3.1、普通查询
grep -ni -5 abc scf-client.stdout.log 显示行号,部分大小写,查询包含abc的前后5行
44.3.2、关联结果查询
healerjean$ find . -name '*.txt' |grep test
./study/cant-breathe/13、redis/7/1、spring redis/spring-redis-test.txt
./study/HealerJean.github.io/_posts/DDKJ/3、AngularJS_Vue/Vue/模板/element-starter/node_modules/hoek/test/modules/ignore.txt
41、wc
: 统计文件中的-c字节数、-w字数、-l行数
cat text.txt
a b c d e f g
h i j k l m n
o p q
r s t
41.1、wc -l
统计行数
healerjean$ wc -l text.txt
4 text.txt
healerjean$ cat text.txt| wc -l
4
41.2、wc -w
:统计单词数量(不包含空格和换行等)
healerjean$ wc -w text.txt
20 text.txt
41.3、wc -c
:统计字符数(只显示Bytes数;)
healerjean$ wc -c text.txt
40 text.txt
41.3、wc
直接打印,分别打印行数,单词书,字符数
$ wc testfile # testfile文件的统计信息
3 92 598 testfile # testfile文件的行数为3、单词数92、字节数598
$ wc testfile testfile_1 testfile_2 #统计三个文件的信息
3 92 598 testfile #第一个文件行数为3、单词数92、字节数598
9 18 78 testfile_1 #第二个文件的行数为9、单词数18、字节数78
3 6 32 testfile_2 #第三个文件的行数为3、单词数6、字节数32
15 116 708 总用量 #三个文件总共的行数为15、单词数116、字节数708