部分程序&命令记录
find
找到家目录中的不包含隐藏空文件夹的空文件夹删除
find /root/ -type d -empty | grep -v '/root/\.'| xargs rm -r {} \;
sed 分组后向引用保留指定分组内的内容
[root@centos8 ~]# echo xyz123abc | sed -r 's/(xyz)(123)(abc)/\3/'
abc
[root@centos8 ~]# echo xyz123abc | sed -E 's/(xyz)(123)(abc)/\3/'
abc
[root@centos8 ~]# echo xyz123abc | sed -r 's/(xyz)(123)(abc)/\1\3/'
xyzabc
sed后向引用取出IP地址
ifconfig ens33 | sed -rn '2s/.*inet ([0-9.]+) netmask.*/\1/p'
ifconfig ens33 | sed -rn '2s/.*inet ([0-9.]+) .*/\1/p'
Ubuntu设置默认编辑器
echo "export EDITOR=vim" >> .profile
#生效
. .profile
yum查看pachage的依赖关系
yum deplist package_name
find查找a或者b
[root@localhost ca]# find / -name *.pem -o -name *.crt
kmod
kmod-25-17.el8.x86_64
The kmod package provides various programs needed for automatic
: loading and unloading of modules under 2.6, 3.x, and later kernels, as well
: as other module management programs. Device drivers and filesystems are two
: examples of loaded and unloaded modules.
kmod包提供了自动化所需的各种程序: 2.6下模块的加载和卸载,3.X,以及以后的内核
:与其他模块管理程序相同。设备驱动程序和文件系统是两个
:加载模块和卸载模块的例子。
- modinfo
DESCRIPTION
modinfo extracts information from the Linux Kernel modules given on the command line. If the module name is not a filename, then the
/lib/modules/version directory is searched, as is also done by modprobe(8) when loading kernel modules.
modinfo by default lists each attribute of the module in form fieldname : value, for easy reading. The filename is listed the same way
(although it's not really an attribute).
This version of modinfo can understand modules of any Linux Kernel architecture.
modinfo从命令行给出的Linux内核模块中提取信息。如果模块名不是文件名,则
/lib/modules/version目录会被搜索,modprobe(8)在加载内核模块时也会这样做。
Modinfo默认情况下以表单fieldname: value列出模块的每个属性,以便阅读。文件名以同样的方式列出
(尽管它实际上不是一个属性)。
这个版本的modinfo可以理解任何Linux内核架构的模块。
bash-completion
最小化安装的centos没有安装自动补全命令这个包。
[root@web1 ~]#yum install -y bash-completion
journalctl
查看日志
journalctl -xefu kubelet
参数
-f, --follow
Show only the most recent journal entries, and continuously print new entries as they are appended to the journal.
-e, --pager-end
Immediately jump to the end of the journal inside the implied pager tool. This implies -n1000 to guarantee that the pager will not buffer logs of unbounded size. This may be
overridden with an explicit -n with some other numeric value, while -nall will disable this cap. Note that this option is only supported for the less(1) pager.
-x, --catalog
Augment log lines with explanation texts from the message catalog. This will add explanatory help texts to log messages in the output where this is available. These short help texts
will explain the context of an error or log event, possible solutions, as well as pointers to support forums, developer documentation, and any other relevant manuals. Note that help
texts are not available for all messages, but only for selected ones. For more information on the message catalog, please refer to the Message Catalog Developer Documentation[4].
Note: when attaching journalctl output to bug reports, please do not use -x.
-u, --unit=UNIT|PATTERN
Show messages for the specified systemd unit UNIT (such as a service unit), or for any of the units matched by PATTERN. If a pattern is specified, a list of unit names found in the
journal is compared with the specified pattern and all that match are used. For each unit name, a match is added for messages from the unit ("_SYSTEMD_UNIT=UNIT"), along with
additional matches for messages from systemd and messages about coredumps for the specified unit.
This parameter can be specified multiple times.
iftop显示的详细信息
第一行,是带宽,下面带有标尺,用来标示每个连接上的实时流量占用的带宽
中间部分,是所有的连接,默认显示的是主机名,可以通过参数显示ip,箭头表示数据方向
中间右侧三列,分别是该连接2s、10s、40s的平均流量
底部三行,分别表示发送、接收、汇总的流量
底部三行第2列,为iftop启动到现在的流量汇总
底部三行第3列,为峰值速率
第4列,为平均值
注意,流量单位为bit,非Byte
lscpu
查看机器上的cpu数量
lscpu看socket
Socket(s): 2
# 同理
grep 'physical id' /proc/cpuinfo | sort -u
按照cpu降序排序
ps aux --sort=-%cpu
# 按内存降序排列
ps aux --sort=-rss
mtr
my traceroute 结合ping和traceroute的网络诊断工具。traceroute默认使用UDP数据包探测,mtr 默认使用ICMP报文探测,ICMP在某些路由节点的优先级要比其他数据包低,所以测试得到的数据可能低于实际情况。
root@dev-k8s-master03:~# mtr -rn 192.168.1.1
Start: 2024-04-15T17:11:53+0800
HOST: dev-k8s-master03 Loss% Snt Last Avg Best Wrst StDev
1.|-- 192.168.1.1 0.0% 10 0.2 0.2 0.1 0.2 0.0
Loss% 丢包率
Snt 已发送数据包总数
Last 最后一个数据包的往返时间 单位ms
Avg 所有数据包往返时间平均值 单位ms
Best 所有数据包中往返时间的最小值 单位ms
Wrst 所有数据包中往返时间的最大值 单位ms
StDev 往返时间的标准差
批量删除小文件
使用rm -rf * 会卡
可以使用 find <需要清理删除小文件的目录> -type f -delete
可以使用rsync命令,新建一个空文件夹
nohup rsync --delete-before -d /data/null/ /opt/app/oracle/admin/crmdb/adump/ &
创建空文件夹
mkdir empty_dir
# 执行同步文件夹
root@MCAiR01:/data0# rsync -a --delete empty_dir/ lukengyu/
监控磁盘io
root@MCAiR01:~# iostat -dx 5 /dev/sda
Linux 5.4.0-110-generic (MCAiR01) 2024年07月11日 _x86_64_ (24 CPU)
Device r/s w/s rkB/s wkB/s rrqm/s wrqm/s %rrqm %wrqm r_await w_await aqu-sz rareq-sz wareq-sz svctm %util
sda 0.28 0.13 2.29 5.00 0.28 1.12 50.46 89.28 3.25 13.91 0.00 8.22 37.31 2.16 0.09
Device r/s w/s rkB/s wkB/s rrqm/s wrqm/s %rrqm %wrqm r_await w_await aqu-sz rareq-sz wareq-sz svctm %util
sda 346.80 338.60 2800.00 13069.60 342.20 2895.40 49.67 89.53 2.45 17.99 6.06 8.07 38.60 1.32 90.32
ps
-e查看所有进程
o 自定义输出格式
etime 进程运行时间
cmd 启动进程的命令
ps -eo pid,etime,cmd