{"id":19770184,"url":"https://github.com/haiker2011/useful-shell","last_synced_at":"2026-04-20T05:01:40.900Z","repository":{"id":82418454,"uuid":"150702096","full_name":"haiker2011/useful-shell","owner":"haiker2011","description":":hammer: 收集自己常用的shell运维脚本","archived":false,"fork":false,"pushed_at":"2019-02-18T05:52:22.000Z","size":28,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-12T09:39:31.173Z","etag":null,"topics":["devops","linux","shell-scripts","ubuntu"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/haiker2011.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-28T07:25:59.000Z","updated_at":"2024-09-26T12:33:57.000Z","dependencies_parsed_at":"2023-06-15T15:00:15.299Z","dependency_job_id":null,"html_url":"https://github.com/haiker2011/useful-shell","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/haiker2011/useful-shell","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haiker2011%2Fuseful-shell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haiker2011%2Fuseful-shell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haiker2011%2Fuseful-shell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haiker2011%2Fuseful-shell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/haiker2011","download_url":"https://codeload.github.com/haiker2011/useful-shell/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haiker2011%2Fuseful-shell/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32033717,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T00:18:06.643Z","status":"online","status_checked_at":"2026-04-20T02:00:06.527Z","response_time":94,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["devops","linux","shell-scripts","ubuntu"],"created_at":"2024-11-12T04:47:08.423Z","updated_at":"2026-04-20T05:01:40.894Z","avatar_url":"https://github.com/haiker2011.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# :hammer: useful-shell\n收集自己常用的shell运维脚本\n\n## 1. 统计行数\n```sh\n# 统计test.txt行数\ncat test.txt |wc -l\n\n# 统计test.txt行数\nwc -l test.txt\n```\n\n## 2. 删除文件空行\n```sh\n# 删除文档filename中空行\ncat filename | sed -e '/^$/d' \u003e filename\n\n# 多行内容显示在一行中\ncat filename |xargs echo\n\n# 删除文件中包含特定字符串的行\n# 删除test.txt文件包含“abc”和“efg”字符串的行，然后将结果存到new_test.txt\nsed -e '/abc/d;/efg/d' test.txt \u003e new_test.txt\n```\n\n## 3. `jq`处理json\n```sh\n# 下载安装jq\nsudo apt install jq\n\n# 提取json数据中nc_news_url和cont字段\njq -c '{nc_news_url:.nc_news_url,cont:.cont}' test.txt \u003e newtest.txt\n\n# 格式化输出\njq -r . test.txt\n\n# 输出id字段\necho ${test.txt} |jq -r '.id'\n```\n\n## 4. 文件拆分\n```sh\n# 将一个大文件拆分为多个文件\n# 文件拆分为大小为2G，拆分文件的前缀为test.tar.gz. ，默认拆分为test.tar.gz.aa,ab,ac...\ncat test.tar.gz | split -b 2G - test.tar.gz.\n\n# 将多个拆分的文件合并为一个文件\ncat test.tar.gz.a* \u003e test.tar.gz\n```\n\n## 5. 文件去重\n```sh\n# sort 去重，全局去重\nsort -u test.txt\n```\n\n ```sh\n sort test.txt | uniq\n ```\n\n```sh\n# 去除连续的重复行\nuniq test.txt\n```\n\n## 6. 文件交集和差集\n```sh\n# 两个文件的交集\ngrep -F -f a.txt b.txt | sort | uniq\n```\n\n```sh\n# 两个文件的差集\n# B-A\ngrep -F -v -f a.txt b.txt | sort | uniq\n```\n\n```sh\n# A-B\ngrep -F -v -f b.txt a.txt | sort | uniq\n```\n\n## 7. Redis操作\n\n```sh\n# 登录Redis\nredis-cli\n```\n\n```sh\n# 清空数据库\nflushall\n```\n\n```sh\n# 查看所有key\nkeys *\n```\n\n```sh\n# 导出Redis数据库\nredis-dump –u 127.0.0.1:6379 \u003e db.rdb\n```\n\n## 8. 手动添加jar到maven仓库\n\n```sh\n# 手动添加jar到maven仓库\nmvn install:install-file -DgroupId=cn.com.test -DartifactId=test -Dversion=1.0.0 -Dpackaging=jar -Dfile=test.jar\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaiker2011%2Fuseful-shell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhaiker2011%2Fuseful-shell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaiker2011%2Fuseful-shell/lists"}