0%

Linux常用命令总结

系统

查看系统版本:

1
cat /proc/version

实例结果:

1
Linux version 4.4.0-112-generic (buildd@lgw01-amd64-010) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.5) ) #135-Ubuntu SMP Fri Jan 19 11:48:36 UTC 2018

CPU

查看CPU信息:

1
cat /proc/cpuinfo

示例结果:

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
processor       : 0
vendor_id : GenuineIntel
cpu family : 6
model : 63
model name : Intel(R) Xeon(R) CPU E5-2673 v3 @ 2.40GHz
stepping : 2
microcode : 0x3a
cpu MHz : 1200.000
cache size : 30720 KB
physical id : 0
siblings : 24
core id : 0
cpu cores : 12
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 15
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm epb invpcid_single kaiser tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm xsaveopt cqm_llc cqm_occup_llc dtherm ida arat pln pts
bugs :
bogomips : 4800.24
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 : 63
model name : Intel(R) Xeon(R) CPU E5-2673 v3 @ 2.40GHz
stepping : 2
microcode : 0x3a
cpu MHz : 1207.687
cache size : 30720 KB
physical id : 0
siblings : 24
core id : 1
cpu cores : 12
apicid : 2
initial apicid : 2
fpu : yes
fpu_exception : yes
cpuid level : 15
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm epb invpcid_single kaiser tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm xsaveopt cqm_llc cqm_occup_llc dtherm ida arat pln pts
bugs :
bogomips : 4800.24
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:

内存

查看内存及用量(M为单位):

1
free -m

示例结果:

1
2
3
              total        used        free      shared  buff/cache   available
Mem: 128806 7115 115910 77 5780 120877
Swap: 0 0 0

查看内存及用量(G为单位):

1
free -g

示例结果:

1
2
3
              total        used        free      shared  buff/cache   available
Mem: 125 6 113 0 5 118
Swap: 0 0 0

硬盘用量

查看各分区使用情况:

1
df -h

示例结果:

1
2
3
4
5
6
Filesystem      Size  Used Avail Use% Mounted on
udev 63G 0 63G 0% /dev
tmpfs 13G 66M 13G 1% /run
/dev/sda1 224G 101G 113G 48% /
tmpfs 63G 352K 63G 1% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock

查看当前目录文件及文件夹大小:

1
du -sh *

示例结果:

1
2
3
4
5
6.9G    anaconda3
213M cuda_samples
7.9M Desktop
8.0K Documents
7.1G Downloads

GPU

查看 GPU 使用情况:

1
nvidia-smi

示例结果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Sun Mar 11 15:34:14 2018       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 384.111 Driver Version: 384.111 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 1080 Off | 00000000:02:00.0 On | N/A |
| 0% 36C P8 15W / 320W | 224MiB / 8105MiB | 0% Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 1322 G /usr/lib/xorg/Xorg 178MiB |
| 0 1880 G compiz 43MiB |
+-----------------------------------------------------------------------------+

进程

查看所有进程:

1
ps -ef

示例结果:

1
2
3
4
5
6
UID        PID  PPID  C STIME TTY          TIME CMD
root 1 0 0 Feb09 ? 00:00:15 /sbin/init splash
root 2 0 0 Feb09 ? 00:00:00 [kthreadd]
root 3 2 0 Feb09 ? 00:00:05 [ksoftirqd/0]
root 5 2 0 Feb09 ? 00:00:00 [kworker/0:0H]
root 6 2 0 Feb09 ? 00:00:01 [kworker/u96:0]

筛选进程:

1
ps -ef | grep python

示例结果:

1
2
chen      6466 44495  0 Mar09 ?        00:01:56 /usr/bin/python2 -m ipykernel_launcher -f /run/user/1000/jupyter/kernel-218926a1-f3b9-4410-bffb-1de1341732be.json
chen 11630 44495 0 Mar09 ? 00:00:13 /home/chen/anaconda3/bin/python -m ipykernel_launcher -f /run/user/1000/jupyter/kernel-c2942b7d-d73c-420a-b6be-78f0169e68c9.json

根据名称强制杀死进程:

1
ps -ef | grep python | cut -c 9-15 | xargs kill -9

用户

添加用户:

1
sudo adduser username

添加用户并设置目录:

1
sudo adduser username --home /home/username

将用户设置超级用户组(如添加到 sudo 用户组):

1
sudo usermod -aG sudo username

查看所有用户组:

1
groups

查看某个用户组下所有用户:

1
2
sudo apt-get install members
members sudo