Linux工具-sar
参考文献
sar
sar是System Activity Reporter(系统活动情况报告)的缩写.sar工具将对系统当前的状态进行取样,然后通过计算数据和比例来表达系统的当前运行状态.它的特点是可以连续对系统取样,获得大量的取样数据;取样数据和分析的结果都可以存入文件,所需的负载很小
安装
1sudo apt install sysstat
语法格式
1sar -[ options ] time_interval number_of_tines_to_display
查看CPU信息
1234567891011# 输出CPU信息间隔2秒 一共输出5次# sar -u 2 5Linux 5.4.0-150-generic (yw-PowerEdge-R740) 2024年09月06日 _x86_64_ (40 CPU)13时20分04秒 CPU %user %nice %system %iowait %steal %idle13时20分06秒 all 1.13 0.00 0.14 1. ...
Linux工具-strace
参考文献
5 simple ways to troubleshoot using Strace
strace
strace命令用于跟踪系统调用和信号。主要用于诊断,调试程序,使用该命令能够打印出进程执行的系统调用信息。
示例
找出应用程序启动时读取的配置文件
12345strace mysql 2>&1 |grep my.cnfstat("/etc/my.cnf", 0x7ffc3bd0d7e0) = -1 ENOENT (No such file or directory)stat("/etc/mysql/my.cnf", {st_mode=S_IFREG|0644, st_size=869, ...}) = 0openat(AT_FDCWD, "/etc/mysql/my.cnf", O_RDONLY|O_CLOEXEC) = 3stat("/home/xx/.my.cnf", 0x7ffc3bd0d7e0) = -1 ENOENT (No such f ...
Linux工具-fuser
参考文献
fuser
123456789101112131415161718192021222324252627# fuser -hUsage: fuser [-fIMuvw] [-a|-s] [-4|-6] [-c|-m|-n SPACE] [-k [-i] [-SIGNAL]] NAME... fuser -l fuser -VShow which processes use the named files, sockets, or filesystems. -a,--all display unused files too -i,--interactive ask before killing (ignored without -k) -I,--inode use always inodes to compare files -k,--kill kill processes accessing the named file -l,--list ...
Linux工具-nc
参考文献
nc
12345678910111213141516171819202122232425262728293031323334353637383940414243# nc -hOpenBSD netcat (Debian patchlevel 1.187-1ubuntu0.1)usage: nc [-46CDdFhklNnrStUuvZz] [-I length] [-i interval] [-M ttl] [-m minttl] [-O length] [-P proxy_username] [-p source_port] [-q seconds] [-s source] [-T keyword] [-V rtable] [-W recvlimit] [-w timeout] [-X proxy_protocol] [-x proxy_address[:port]] [destination] [port] Command Summary: -4 Use IPv4 -6 Use IPv6 -b Allow broadcast -C Sen ...
Linux工具-lsof
参考文献
https://wangchujiang.com/linux-command/c/lsof.html
lsof
lsof命令 用于查看你进程打开的文件,打开文件的进程,进程打开的端口(TCP、UDP).找回/恢复删除的文件.是十分方便的系统监视工具,因为lsof命令需要访问核心内存和各种文件,所以需要root用户执行.
在Linux环境下,任何事物都以文件的形式存在,通过文件不仅仅可以访问常规数据,还可以访问网络连接和硬件.所以如传输控制协议 (TCP) 和用户数据报协议 (UDP) 套接字等,系统在后台都为该应用程序分配了一个文件描述符,无论这个文件的本质如何,该文件描述符为应用程序与基础操作系统之间的交互提供了通用接口.因为应用程序打开文件的描述符列表提供了大量关于这个应用程序本身的信息,因此通过sof工具能够查看这个列表对系统监测以及排错将是很有帮助的.
基础用法
12345678910111213141516171819202122232425262728293031323334353637lsof [选项]lsof 4.89 latest revision: ...
Linux工具-netstat
参考文献
netstat
12345678910111213[root@linux ~]# netstat -[rn] <==与路由有关的参数 [root@linux ~]# netstat -[antulpc] <==与网络接口有关的参数 参数: 与路由(route) 有关的参数说明: -r : 列出路由表(route table),功能如同 route 这个指令;-n : 不使用主机名称与服务名称,使用 IP 与 port number ,如同 route -n 与网络接口有关的参数: -a : 列出所有的联机状态,包括 tcp/udp/unix socket 等; -t : 仅列出 TCP 封包的联机;-u : 仅列出 UDP 封包的联机;-l : 仅列出有在 Listen(监听) 的服务之网络状态; -p : 列出 PID 与 Program 的檔名;-c : 可以设定几秒钟后自动更新一次,例如 -c 5 每五秒更新一次网络状态的显示;
-i展示网络接口信息
1234567891011121314151617181920212223 ...
Linux工具-watch
参考文献
Linux watch命令教程:如何实时监控命令输出(附实例详解和注意事项)
watch
watch 是一个非常实用的命令,它可以帮助用户定时执行一个程序或命令,并将结果输出到终端。这个命令通常用于周期性地监视某个命令的输出结果,例如监控系统资源的使用情况、查看目录内容的变化等。通过使用 watch,你可以实时地了解到命令输出的动态变化
基本语法
1watch [option] 命令
常用选项或参数说明
选项
描述
-d
高亮显示变化的部分
-n
设置刷新间隔,以秒为单位
-t
不显示标题栏,包含时间和刷新间隔
--help
显式帮助信息
-v
显示版本信息
示例
基础使用
12# 每隔2秒刷新一次datewatch -n 2 date
监控某个服务的状态
1watch -n 5 systemctl status nginx
Linux工具-pv
参考文献
pv
Linux pv命令教程:掌握数据流可视化(附实例详解和注意事项)
PV
pv(Pipe Viewer)是一个终端应用程序,能够以可视化的方式展示管道中的数据传输过程。它可以显示进度条、数据传输速率、已传输的数据量和剩余时间估计等信息。这对于调试和监视长时间运行的数据传输任务特别有帮助。pv能够插入到管道命令序列中,无需对其他命令做任何改变。
基本语法
1pv [option] [file]
常用选项或参数说明
选项
描述
-a, --average-rate
显示数据传输平均速率计数器
-b, --bytes
显示已传输的字节数
-c, --cursor
使用光标定位转义序列
-e, --eta
显示预计到达时间 (完成)
-l, --line-mode
计数行而不是字节
-n, --numeric
输出百分比
-p, --progress
显示进度条
-r, --rate
显示数据传输速率计数器
-s
设置预期的数据总量
-t, --timer
显示已用时间
-w
设置进度条的宽度
-h
显示帮助信息 ...
Linux工具-openssl
参考文献
openssl
加密
对称加密-AES
AES是当前针对大量数据加密时最常用的分组加密算法。AES-256表示分组的密钥空间长度为256比特,具体由于分组算法的不同,AES-256还可以细分为很多种。
1234#加密openssl enc -aes-256-cbc -in msg.txt -out enc.txt -pass pass:123456 -iter 100 -pbkdf2#解密openssl enc -d -aes-256-cbc -in enc.txt -out plain.txt -pass pass:123456 -iter 100 -pbkdf2
对称加密-DES
3DES是DES的升级版,DES的加密强度比较弱。
12#加密openssl enc -des3 -in out.txt -out p.txt -pass pass:123456 -iter 100 -pbkdf2
对称加密-blowfish
12#加密openssl enc -blowfish -in out.txt -out p.txt -pass pass:123456 -iter ...
Linux工具-find
参考文献
find
1234567891011121314151617181920212223242526272829303132333435363738394041# find [PATH] [option] [action]参数: 1. 与时间有关的参数: -atime n : n 为数字,意义为在 n 天之前的『一天之内』被 access 过的档案; -ctime n : n 为数字,意义为在 n 天之前的『一天之内』被 change 过状态的档案; -mtime n : n 为数字,意义为在 n 天之前的『一天之内』被 modification 过的档案; -newer file : file 为一个存在的档案,意思是说,只要档案比 file 还要新, 就会被列出来~2. 与使用者或群组名称有关的参数: -uid n : n 为数字,这个数字是使用者的账号 ID,亦即 UID ,这个 UID 是记录在 /etc/passwd 里面与账号名称对应的数字。这方面我们会在第四篇介绍。 -gi ...