目录
一、文件类
①:设置vim查看文件编码格式
# 查看文件编码
file --mime-encoding filename
# 设置vim打开编码选择
echo 'set encoding=utf-8 fileencodings=ucs-bom,utf-8,cp936' >> /etc/vimrc
②:文件乱码
# 查看乱码文件编码格式
set fileencoding
# 进入乱码文件输入
set fileencoding = utf-8
③:后台运行py文件
# linux后台运行py文件 一般用于服务启动之类的需要长期监测的脚本
nohup python xxxxx.py -u nohup.out &
④:查找文件
# whereis,find,which
# whereis只能用于查找二进制文件、源代码文件和man手册页。
# find 可以指定目前下或根目录查找
# which 查找在系统变量中的命令位置
(base) [root@finance01 usr]# find -name python
./bin/python
./share/gcc-4.8.2/python
./include/boost/parameter/aux_/python
./include/boost/mpi/python
./include/boost/python
./local/jmeter/jmeter/lib/jython-standalone-2.7.1/com/ziclix/python
./local/jmeter/jmeter/lib/jython-standalone-2.7.1/org/python
(base) [root@finance01 usr]# whereis python
python: /usr/bin/python2.7 /usr/bin/python /usr/bin/python2.7-config /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /root/anaconda3/bin/python /root/anaconda3/bin/python3.8 /root/anaconda3/bin/python3.8-config /usr/share/man/man1/python.1.gz
(base) [root@finance01 usr]# which python
/root/anaconda3/bin/python
二、端口服务类
①:查看进程
# 查看特定进程更改关键字(Python)
ps -ef | grep python
②、查看网络服务(端口服务)
# 查看端口服务及tcp/pid等信息
netstat -nltp
③、杀掉进程
# 通常配合 netstat -nltp 使用
# 指定名字
kill - 9 $(pidof google-chrome)
④、查看linux资源占用情况
# 查看linux资源使用使用情况
top
# 输出如下: (这里可以看到cpu的使用率,可以定位因超高cpu使用率导致程序无响应问题)
top - 11:48:49 up 67 days, 18:14, 2 users, load average: 0.05, 0.04, 0.07
Tasks: 691 total, 1 running, 690 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.3 us, 0.0 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 13162375+total, 30176480 free, 54814288 used, 46632984 buff/cache
KiB Swap: 4194300 total, 3508208 free, 686092 used. 76014976 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
16452 mysql 20 0 13.856g 8.205g 8580 S 14.6 6.5 18849:26 mysqld
3851 root 20 0 50.795g 0.017t 2864 S 1.0 14.2 1903:48 java
1961 root 20 0 2929344 44620 9076 S 0.7 0.0 451:07.88 docker-containe
2010 root 20 0 1001336 263344 1308 S 0.7 0.2 43:19.63 redis-server
13920 root 20 0 35.411g 1.400g 14856 S 0.7 1.1 863:14.99 java
27714 root 20 0 148916 2732 1460 R 0.7 0.0 0:00.05 top
28581 root 20 0 45.287g 3.514g 15396 S 0.7 2.8 524:07.69 java
1582 root 20 0 3570552 54976 15652 S 0.3 0.0 213:47.16 dockerd
15438 root 20 0 30.154g 1.650g 14240 S 0.3 1.3 284:43.05 java
1 root 20 0 54432 7624 2520 S 0.0 0.0 8:25.35 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.02 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:01.33 ksoftirqd/0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
8 root rt 0 0 0 0 S 0.0 0.0 0:01.61 migration/0
9 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
三、权限类
①:查看文件权限
r 对应权限数字为 4,w对应权限数字为 2,x 对应权限数字为 1
# ll 查看当前目录下所有文件及文件夹信息
(base) [root@finance01 usr]# ll
总用量 2218496
dr-xr-xr-x. 2 mongodb mongodb 20480 10月 11 12:43 bin
drwxr-xr-x. 2 root root 10 8月 12 2015 etc
drwxr-xr-x. 2 root root 10 8月 12 2015 games
drwxr-xr-x. 48 root root 8192 5月 20 12:57 include
dr-xr-xr-x. 28 mongodb mongodb 4096 10月 11 12:43 lib
dr-xr-xr-x. 45 mongodb mongodb 36864 10月 11 12:43 lib64
drwxr-xr-x. 19 root root 4096 10月 11 12:43 libexec
drwxr-xr-x. 23 root root 4096 10月 28 14:04 local
drwxr-xr-x. 3 root root 63 4月 2 2021 redis
dr-xr-xr-x. 2 mongodb mongodb 12288 8月 1 10:45 sbin
drwxr-xr-x. 97 root root 4096 10月 11 12:43 share
drwxr-xr-x. 4 root root 44 3月 9 2021 src
lrwxrwxrwx. 1 root root 10 3月 9 2021 tmp -> ../var/tmp
文件调用权限分为三级 : 文件所有者(Owner)、用户组(Group)、其它用户(Other Users)。
dr-xr-xr-x
d : 文件夹的标志
r-x : 5 对应文件所有者
r-x :5 用户组
r-x : 5 其它用户
②:修改文件权限
创建一个a.txt文件,查看权限,再赋新的权限对比。
# chmod 用于赋予文件权限
(base) [root@finance01 usr]# touch a.txt
(base) [root@finance01 usr]# ll
总用量 2218496
-rw-r--r-- 1 root root 0 11月 3 17:31 a.txt
dr-xr-xr-x. 2 mongodb mongodb 20480 10月 11 12:43 bin
drwxr-xr-x. 2 root root 10 8月 12 2015 etc
drwxr-xr-x. 2 root root 10 8月 12 2015 games
drwxr-xr-x. 48 root root 8192 5月 20 12:57 include
dr-xr-xr-x. 28 mongodb mongodb 4096 10月 11 12:43 lib
dr-xr-xr-x. 45 mongodb mongodb 36864 10月 11 12:43 lib64
drwxr-xr-x. 19 root root 4096 10月 11 12:43 libexec
drwxr-xr-x. 23 root root 4096 10月 28 14:04 local
drwxr-xr-x. 3 root root 63 4月 2 2021 redis
dr-xr-xr-x. 2 mongodb mongodb 12288 8月 1 10:45 sbin
drwxr-xr-x. 97 root root 4096 10月 11 12:43 share
drwxr-xr-x. 4 root root 44 3月 9 2021 src
lrwxrwxrwx. 1 root root 10 3月 9 2021 tmp -> ../var/tmp
(base) [root@finance01 usr]# chmod 777 a.txt
(base) [root@finance01 usr]# ll
总用量 2218496
-rwxrwxrwx 1 root root 0 11月 3 17:31 a.txt
dr-xr-xr-x. 2 mongodb mongodb 20480 10月 11 12:43 bin
drwxr-xr-x. 2 root root 10 8月 12 2015 etc
drwxr-xr-x. 2 root root 10 8月 12 2015 games
drwxr-xr-x. 48 root root 8192 5月 20 12:57 include
dr-xr-xr-x. 28 mongodb mongodb 4096 10月 11 12:43 lib
dr-xr-xr-x. 45 mongodb mongodb 36864 10月 11 12:43 lib64
drwxr-xr-x. 19 root root 4096 10月 11 12:43 libexec
drwxr-xr-x. 23 root root 4096 10月 28 14:04 local
drwxr-xr-x. 3 root root 63 4月 2 2021 redis
dr-xr-xr-x. 2 mongodb mongodb 12288 8月 1 10:45 sbin
drwxr-xr-x. 97 root root 4096 10月 11 12:43 share
drwxr-xr-x. 4 root root 44 3月 9 2021 src
lrwxrwxrwx. 1 root root 10 3月 9 2021 tmp -> ../var/tmp
四、查看服务器硬件情况
①:cpu情况
# cpu情况查看
lscpu
# 输出如下: (可以看到cpu的核数、型号、及每个核的最大线程数等情况)
(base) [root@finance01 ~]# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 64
On-line CPU(s) list: 0-63
Thread(s) per core: 2
Core(s) per socket: 16
座: 2
NUMA 节点: 2
厂商 ID: GenuineIntel
CPU 系列: 6
型号: 79
型号名称: Intel(R) Xeon(R) CPU E5-2683 v4 @ 2.10GHz
步进: 1
CPU MHz: 1199.953
BogoMIPS: 4200.07
虚拟化: VT-x
L1d 缓存: 32K
L1i 缓存: 32K
L2 缓存: 256K
L3 缓存: 40960K
NUMA 节点0 CPU: 0-15,32-47
NUMA 节点1 CPU: 16-31,48-63
②:linux分区情况查看
df -h
# 输出如下: (不加-h默认输出的容量单位为byte)
(base) [root@finance01 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 63G 0 63G 0% /dev
tmpfs 63G 0 63G 0% /dev/shm
tmpfs 63G 74M 63G 1% /run
tmpfs 63G 0 63G 0% /sys/fs/cgroup
/dev/mapper/centos-root 11T 2.5T 8.6T 23% /
/dev/sda2 497M 107M 391M 22% /boot
tmpfs 13G 0 13G 0% /run/user/0
③:linux内存情况
# 内存情况查看
free -h
# 输出 (不加-h也是以单位为字节来输出的)
(base) [root@finance01 ~]# free -h
total used free shared buff/cache available
Mem: 125G 52G 28G 73M 44G 72G
Swap: 4.0G 670M 3.3G