Fork me on GitHub

Ubuntu系统常用命令汇总

目录

  • 背景
  • 第一部分 系统信息
  • 第二部分 资源信息
  • 第三部分 磁盘信息
  • 第四部分 网络信息
  • 第五部分 进程信息
  • 第六部分 用户信息
  • 参考文献及资料

背景

本篇博客主要汇总查询Ubuntu系统的信息的相关命令及展示案例。会持续更新。

第一部分 系统信息

1.1 查看:CPU信息

1
2
root@deeplearning:/# cat /proc/version
Linux version 4.13.0-37-generic (buildd@lcy01-amd64-012) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.9)) #42~16.04.1-Ubuntu SMP Wed Mar 7 16:03:28 UTC 2018

1.2 查看:内核、操作系统、CPU信息

1
2
root@deeplearning:/# uname -a
Linux deeplearning 4.13.0-37-generic #42~16.04.1-Ubuntu SMP Wed Mar 7 16:03:28 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

1.3 查看:操作系统版本信息

1
2
3
4
5
6
root@deeplearning:/# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.4 LTS
Release: 16.04
Codename: xenial

1.4 查看:计算机名

1
2
root@vultr:~# hostname
vultr.guest

第二部分 资源信息

2.1 查看:存储分区的使用信息

1
2
3
4
5
6
7
8
9
root@vultr:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 469M 0 469M 0% /dev
tmpfs 99M 11M 89M 11% /run
/dev/vda1 25G 12G 12G 49% /
tmpfs 495M 0 495M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 495M 0 495M 0% /sys/fs/cgroup
tmpfs 99M 0 99M 0% /run/user/0

2.2 查看:系统运行时间、用户数量

1
2
root@vultr:~# uptime
23:04:54 up 10 days, 17:21, 1 user, load average: 0.21, 0.06, 0.02

第三部分 磁盘信息

3.1 查看:所有分区信息

1
2
3
4
5
6
7
8
9
10
root@vultr:~# fdisk -l
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xcb855d49

Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 52428257 52426210 25G 83 Linux

第四部分 网络信息

4.1 查看:网络接口信息

1
2
3
4
5
6
7
8
9
10
root@vultr:~# ifconfig
#(略)
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 198660 bytes 27478459 (27.4 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 198660 bytes 27478459 (27.4 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

4.2 查看:防火墙信息

1
2
3
4
root@vultr:~# iptables -L
Chain DOCKER-USER (1 references)
target prot opt source destination
RETURN all -- anywhere anywhere

4.3 查看:路由表

1
2
3
4
5
root@vultr:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
#(略)
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0

4.4 查看:监听端口、已经建立的连接

1
2
3
4
root@vultr:~# netstat -lntp
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 749/sshd
1
2
3
4
root@vultr:~# netstat -antp
Active Internet connections (servers and established)
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 749/sshd

4.5 查看:网络统计信息

1
2
3
4
5
6
root@vultr:~# netstat -s
Ip:
Forwarding: 1
5729182 total packets received
9 with invalid addresses
#略信息

第五部分 进程信息

5.1 查看:所有进程信息

1
2
3
root@vultr:~# ps -ef 
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Mar25 ? 00:00:44 /sbin/init

5.2 查看:实时显示进程状态

1
2
3
4
5
6
7
8
9
10
root@vultr:~# top
top - 23:24:19 up 10 days, 17:41, 1 user, load average: 0.02, 0.02, 0.00
Tasks: 87 total, 1 running, 86 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.7 us, 0.3 sy, 0.0 ni, 99.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 1012392 total, 74384 free, 270236 used, 667772 buff/cache
KiB Swap: 0 total, 0 free, 0 used. 556896 avail Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
25691 root 20 0 554760 13348 3448 S 0.3 1.3 35:21.42 docker-containe
#(略信息)

第六部分 用户信息

6.1 查看:活动用户

1
2
3
4
root@vultr:~# w
23:25:22 up 10 days, 17:42, 1 user, load average: 0.33, 0.08, 0.02
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 140.31.74.0 22:59 2.00s 0.06s 0.00s w

6.2 查看:用户登录日志信息

1
2
3
4
5
root@vultr:~# last
root pts/0 113.41.56.0 Wed Apr 4 22:59 still logged in
root pts/0 113.41.56.0 Wed Apr 4 08:37 - 13:38 (05:00)

wtmp begins Sun Apr 1 19:59:32 2018

参考文献及资料

1、The 50 Most Useful Linux Commands To Run in the Terminal,链接:https://www.ubuntupit.com/best-linux-commands-to-run-in-the-terminal/

本文标题:Ubuntu系统常用命令汇总

文章作者:rong xiang

发布时间:2018年03月14日 - 19:03

最后更新:2022年10月25日 - 23:10

原始链接:https://zjrongxiang.github.io/posts/c886b2e4/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

0%