Useful scripts
🐌 useful scripts for making developer's everyday life easier and happier, involved java, shell etc.
🐌 useful scripts for making developer's everyday life easier and happier, involved java, shell etc. The project is written primarily in Shell, distributed under the Apache License 2.0 license, first published in 2013. It has gained significant community traction with 7,527 stars and 2,805 forks on GitHub. Key topics include: bash, developers-everyday-life, java, option-parser, python.
<div align="center"><a href="#dummy"><img src="https://github.com/oldratlee/useful-scripts/assets/1063891/990d7ab3-1a84-4024-b1c6-4c8d441dcfc6" alt="🐌 useful-scripts"></a></div>
<p align="center"> <a href="https://github.com/oldratlee/useful-scripts/actions/workflows/ci.yaml"><img src="https://img.shields.io/github/actions/workflow/status/oldratlee/useful-scripts/ci.yaml?branch=dev-3.x&logo=github&logoColor=white" alt="Github Workflow Build Status"></a> <a href="https://github.com/oldratlee/useful-scripts/releases"><img src="https://img.shields.io/github/release/oldratlee/useful-scripts.svg" alt="GitHub release"></a> <a href="https://www.apache.org/licenses/LICENSE-2.0.html"><img src="https://img.shields.io/github/license/oldratlee/useful-scripts?color=4D7A97&logo=apache" alt="License"></a> <a href="https://github.com/oldratlee/useful-scripts/stargazers"><img src="https://img.shields.io/github/stars/oldratlee/useful-scripts?style=flat" alt="GitHub Stars"></a> <a href="https://github.com/oldratlee/useful-scripts/fork"><img src="https://img.shields.io/github/forks/oldratlee/useful-scripts?style=flat" alt="GitHub Forks"></a> <a href="https://github.com/oldratlee/useful-scripts/issues"><img src="https://img.shields.io/github/issues/oldratlee/useful-scripts" alt="GitHub issues"></a> <a href="https://github.com/oldratlee/useful-scripts/graphs/contributors"><img src="https://img.shields.io/github/contributors/oldratlee/useful-scripts" alt="GitHub Contributors"></a> <a href="https://github.com/oldratlee/useful-scripts"><img src="https://img.shields.io/github/repo-size/oldratlee/useful-scripts" alt="GitHub repo size"></a> </p>🐌 useful scripts for making developer's everyday life easier and happier, involved java, shell etc.
👉 平时有用的手动操作做成脚本,以便捷地使用,让开发的日常生活更轻松些。 💕
欢迎 👏 💖
- 提问,提交 Issue
- 分享平时自己常用但没有写成脚本的功能(即需求、想法),提交Issue
- 优化改进,Fork 后提通过 Pull Request 贡献代码
- 提供的自己好用脚本实现,Fork 后提通过 Pull Request 提供
本仓库的脚本(如Java相关脚本)在阿里等公司(如随身云,见awesome-scripts仓库说明)的线上生产环境部署使用。
如果你的公司有部署使用,欢迎使用通过 Issue:who's using | 用户反馈收集 告知,方便互相交流反馈~ 💗
<a href="#dummy"><img src="https://github.com/oldratlee/useful-scripts/assets/1063891/82f2d184-ca16-4c37-b053-07f21fd8aef1" alt="repo-icon" width="20%" align="right" /></a>
<!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> <!-- END doctoc generated TOC please keep comment here to allow auto update -->
🔰 快速下载&使用
bashsource <(curl -fsSL https://raw.githubusercontent.com/oldratlee/useful-scripts/release-3.x/test/self-installer.sh)
更多下载&使用方式,参见下载使用。
📚 使用文档
☕ Java相关脚本
- show-busy-java-threads
用于快速排查Java的CPU性能问题(top us值过高),自动查出运行的Java进程中消耗CPU多的线程,并打印出其线程栈,从而确定导致性能问题的方法调用。 - show-duplicate-java-classes
找出jar文件和class目录中的重复类。用于排查Java类冲突问题。 - find-in-jars
在目录下所有jar文件里,查找类或资源文件。
🐚 Shell相关脚本
Shell使用加强:
- c
原样命令行输出,并拷贝标准输出到系统剪贴板,省去CTRL+C操作,优化命令行与其它应用之间的操作流。 - coat and taoc
彩色cat/tac出文件行,方便人眼区分不同的行。 - a2l
按行彩色输出参数,方便人眼查看。 - uq
不重排序输入完成整个输入行的去重。相比系统的uniq命令加强的是可以跨行去重,不需要排序输入。 - ap and rp
批量转换文件路径为绝对路径/相对路径,会自动跟踪链接并规范化路径。 - cp-into-docker-run
一个Docker使用的便利脚本。拷贝本机的执行文件到指定的docker container中并在docker container中执行。 - tcp-connection-state-counter
统计各个TCP连接状态的个数。用于方便排查系统连接负荷问题。 - xpl and xpf
在命令行中快速完成 在文件浏览器中 打开/选中 指定的文件或文件夹的操作,优化命令行与其它应用之间的操作流。
Shell开发/测试加强:
- echo-args
输出脚本收到的参数,在控制台运行时,把参数值括起的括号显示成 红色,方便人眼查看。用于调试脚本参数输入。 - console-text-color-themes.sh
显示Terminator的全部文字彩色组合的效果及其打印方式,用于开发Shell的彩色输出。 - parseOpts.sh
命令行选项解析库,加强支持选项有多个值(即数组)。
🎓 Developer Guide
为用户提供有用的功能,当然是这个库的首要的价值体现和存在理由。
但作为一个开源项目,每个人都可以看到源码实现,这个库或许能做得更多。
🎯 面向开发者的目标
- 将
Shell/Bash作为线上生产环境使用的专业编程语言。 - 期望体现
Shell/Bash脚本 生产环境级的严谨开发方式与最佳实践,进而有可能示例与改善在生产环境中Shell脚本的质量状况。
PS:
- 虽然上面是自己期望的目标,但自己在
Shell语言上一定会有很多理解和使用上的问题、在这些实现脚本中也会很多需要的改进,可以一起学习、讨论与实践~ 💕 - 这个库中脚本的实现也有使用
Python。
关于Shell脚本
命令行(CLI)几乎是每个程序员每天都在使用的工具。相比图形界面工具(GUI),命令行有着自己不可替代的便利性和优越性。
命令行里写出来其实就是Shell脚本,可以说每个开发者会写Shell脚本(或多或少)。在生产环境的功能实现中,也常会看到Shell脚本(虽然不如主流语言那么常见)。
可能正因为上面所说的Shell脚本的便利性和大众性:
Shell脚本有不少是顺手实现的(包括生产环境用的Shell脚本);Shell脚本的实现常常可能质量不高,会引发线上严重的故障。
🚦 开发约定
在这个库中的Shell脚本:
- 统一使用
Bash 3.2+; - 面向生产环境,尽可能使用严谨安全的开发方式。
Shell用Bash的原因是:
- 目前仍然是主流的
Shell,并且在不同环境基本上都缺省部署了。 - 在
Google的Shell风格指南中,明确说到了:Bash是唯一被允许执行的shell脚本语言。 - 统一用
Bash,可以避免不同Shell之间差异所带来的风险与没有收益的复杂性。- 有大量的
Shell实现,sh、bash、zsh、fish、csh、tcsh、ksh、ash、dash…… - 不同的
Shell有各种差异,深坑勿入。
- 有大量的
- 个人系统学习过的是
Bash,比较理解熟悉。
PS: 虽然交互Shell个人已经使用Zsh + oh-my-zsh,但在严谨的Shell脚本开发时还是使用Bash。
📚 Shell学习与开发的资料
更多资料参见 子文档。
- 🛠️ 开发规范与工具
Google Shell Style Guide| 中文版koalaman/shellcheck:ShellCheck, a static analysis tool for shell scriptsmvdan/sh(shfmt):shfmtformats shell programs
- 👷
Bash/Shell最佳实践与安全编程文章- Use the Unofficial Bash Strict Mode (Unless You Looove Debugging)
- Bash Pitfalls: 编程易犯的错误 - 团子的小窝:Part 1 | Part 2 | Part 3 | Part 4 | 英文原文:Bash Pitfalls
- 不要自己去指定
sh的方式去执行脚本
- 🎶 Tips
- 让你提升命令行效率的 Bash 快捷键 【完整版】
补充:ctrl + x, ctrl + e就地打开文本编辑器来编辑当前命令行,对于复杂命令行特别有用 - 应该知道的Linux技巧 | 酷 壳 - CoolShell
- 简洁的 Bash Programming 技巧 - 团子的小窝:Part 1 | Part 2 | Part 3
- 让你提升命令行效率的 Bash 快捷键 【完整版】
- 💎 系统学习 — 看文章、了解Tips完全不能替代系统学习才能真正理解并专业开发!
- 《Bash Pocket Reference》
力荐!说明简单直接结构体系的佳作,专业Bash编程必备!且16年的第二版更新到了新版的Bash 4 - 《学习bash》 上面那本的展开版
- 官方资料
bash man| 中文版- Bash Reference Manual - gnu.org | 中文版
Bash参考手册,讲得全面且有深度,比如会全面地讲解不同转义的区别、命令的解析过程,这有助统一深入的方式认识Bash整个执行方式和过程。这些内容在其它书中往往不会讲(因为复杂难于深入浅出的讲解),但却一通百通的关键。
- Advanced Bash-Scripting Guide: An in-depth exploration of the art of shell scripting.
- 命令行的艺术 -
jlevy/the-art-of-command-line awesome-lists/awesome-bash: A curated list of delightful Bash scripts and resources.alebcay/awesome-shell: A curated list of awesome command-line frameworks, toolkits, guides and gizmos.- 更多书籍参见个人整理的书籍豆列
Bash/Shell
- 《Bash Pocket Reference》
Contributors
Showing top 12 contributors by commit count.
