0%

linux命令01-查看信息

1. 查看linux系统信息

1.1 查看系统版本

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
#lsb_release -a 
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.6 LTS
Release: 16.04
Codename: xenial

#uname -srm
Linux 4.15.0-1060-gcp x86_64

#cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.6 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.6 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

#cat /proc/version
Linux version 4.15.0-1060-gcp (buildd@lcy01-amd64-028) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12)) #64-Ubuntu SMP Thu Mar 26 03:21:15 UTC 2020

#cat /etc/issue
Ubuntu 16.04.6 LTS \n \l

1.2 查看硬盘内存 CPU

1.2.1 查看硬盘
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# df -h  查看磁盘空间
Filesystem Size Used Avail Use% Mounted on
udev 986M 0 986M 0% /dev
tmpfs 200M 22M 179M 11% /run
/dev/sda1 29G 5.6G 24G 20% /


#fdisk -l 查看Linux中的所有磁盘分区
Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: A03F431A-7AE6-406D-B233-EED234598EEE

Device Start End Sectors Size Type
/dev/sda1 227328 62914526 62687199 29.9G Linux filesystem
/dev/sda14 2048 10239 8192 4M BIOS boot
/dev/sda15 10240 227327 217088 106M EFI System
1.2.1 查看内存
1
2
3
4
# free -h 查看内存
total used free shared buff/cache available
Mem: 1.9G 769M 211M 21M 1.0G 1.0G
Swap: 0B 0B 0B
1.2.2 查看 CPU
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 2

# cat /proc/cpuinfo 查看 CPU 信息
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 63
model name : Intel(R) Xeon(R) CPU @ 2.30GHz
stepping : 0
microcode : 0x1
cpu MHz : 2300.000
cache size : 46080 KB

# cat /proc/cpuinfo| grep "processor"| wc -l 查看 CPU 个数
2

2. 进程端口相关

2.1 查询进程

1
2
3
ps     # displays processes for the current shell.
ps -ef # Display every active process on a Linux system in generic (Unix/Linux) format.
ps -aux # Display all processes in BSD format.

2.2 查询端口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#1. 这类命令一定要用sudo
#2. a: all p: procee, t:tcp, u:udp, l:正在监听的 , n: 禁止域名解析, 只显示数字ip
sudo netstat -anp | grep 80
sudo netstat -tunlp | grep 80


# 知道进程名字反查端口
ps -ef | grep processName #得到processID
netstat -anp | grep processID #p能显示出进程名和进程id, 过滤得到端口

# 知道端口反查进程名字
sudo lsof -i :80

# 一个命令搞定
sudo netstat -anp | grep processID
sudo netstat -anp | grep processName

3. 参考教程

可以加首页作者微信,咨询相关问题!