使用不同的解释器「bash,zsh…」编写脚本的时候对于某些语法可能不同
example:Bash arrays are indexed from 0 to (length-1). Zsh arrays are indexed from 1 to length。
grep相关
1 | # 将展示结果的各个参数的header信息也展示出来 |
find相关
1 | # 使用-exec查找并执行正则匹配 |
批量处理文件的一个大概流程:
1 |
|
ps相关
1 | # 查看的时候把字段名字也展示出来,方便查看 |
一次批量删除redis中匹配的key
1 | redis-cli -h 192.168.4.4 -n 3 -a test --scan --pattern 'xboot:subsernorepeat:*' | xargs redis-cli -h 192.168.4.4 -n 3 -a test -n 3 del |
使用awk拼接sql
1 | # test 源文件 |
maven依赖相关
1 | # 项目依赖树 |
socket统计信息,端口使用相关
ss from iproute2
命令使用详细参考 这里
1 | # 说端口的时候要注意是什么协议下的端口 |
网络io监测相关
nload 命令 网路状态和各IP所使用的频宽。Detail
nethogs 命令 按进程或程序实时统计网络带宽使用率。它只能实时监控进程的网络带宽占用情况。Detail
dstat 命令 性能测试、基准测试和排除故障过程中可以很方便监控系统运行状况。可以将详细信息通过cvs输出到一个文件。Detail
sar 命令 Linux系统运行状态统计和性能分析工具,可从磁盘IO、CPU负载、内存使用等多个维度对系统活动进行报告。Detail
iptraf 命令 会有简单界面显示出来详细信息 Detail
iftop 命令
tcpdump 抓包命令 Detail
RX==receive,接收,从开启到现在接收封包的情况,是下行流量。
TX==Transmit,发送,从开启到现在发送封包的情况,是上行流量。
1 | # 经Mac下测试使用 |
词典的使用
aspell 命令对于各种文件内容进行拼写检查
1 | # 经Mac下测试使用 |
进程文件打开情况
1 | # 29190 进程号 |
磁盘情况查看
du是面向文件的命令,只计算被文件占用的空间,不计算文件系统 metadata 占用的空间。
df则是基于文件系统总体来计算,通过文件系统中未分配空间来确定系统中已经分配空间的大小。
df命令可以获取硬盘占用了多少空间,还剩下多少空间,它也可以显示所有文件系统对i节点和磁盘块的使用情况。
1 | df -hl 查看磁盘剩余空间 |
ab的使用
ab就是Apache Benchmark的缩写,Apache组织开发的一款web压力测试工具,优点是使用方便,统计功能强大。一些参数分析参考这里:https://www.jianshu.com/p/6175456a55be 当然可以直接
man ab
1 | # 经Mac下测试使用 |
nc的使用
Netcat(often abbreviated to nc) is a featured networking utility which **reads and writes data across network connections, using the TCP/IP protocol.**It is designed to be a reliable “back-end” tool that can be used directly or easily driven by other programs and scripts. At the same time, it is a feature-rich network debugging and exploration tool, since it can create almost any kind of connection you would need and has several interesting built-in capabilities
1 | # 经Mac下测试使用 |
网络相关
路由相关:route,traceroute,mtr
一些常用的处理文件的脚本
从一次面试决定开始记录,提交shell编写能力,想到可以从leecode上面看一些shell题目
另一方面是对于一些简单的命令去使用和理解
文本中出现某些字符频率排名
1 | cat num.xkx | sort | uniq -c | sort -nrk 1 | awk -F ' ' '{print $2}' | head -5 |
参考
- Post title: 常用的shell脚本和一些好用的命令
- Create time: 2020-08-05 13:45:09
- Post link: 2020/08/05/frequent-shell-script/
- Copyright notice: All articles in this blog are licensed under BY-NC-SA unless stating additionally.