{"id":22965750,"url":"https://github.com/mirror4s/missing-semester","last_synced_at":"2026-01-11T03:04:09.440Z","repository":{"id":244146425,"uuid":"814114652","full_name":"MirRoR4s/Missing-Semester","owner":"MirRoR4s","description":"Missing Semester 学习总结/核心知识点汇总","archived":false,"fork":false,"pushed_at":"2024-06-26T02:52:27.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-02T04:29:48.532Z","etag":null,"topics":["computer-science","tools-techniques"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MirRoR4s.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-06-12T11:17:49.000Z","updated_at":"2024-06-26T02:52:30.000Z","dependencies_parsed_at":"2024-06-13T05:18:24.888Z","dependency_job_id":"f4372ca6-e1ef-4175-a831-88c14f531c71","html_url":"https://github.com/MirRoR4s/Missing-Semester","commit_stats":null,"previous_names":["mirror4s/missing-semester"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MirRoR4s/Missing-Semester","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MirRoR4s%2FMissing-Semester","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MirRoR4s%2FMissing-Semester/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MirRoR4s%2FMissing-Semester/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MirRoR4s%2FMissing-Semester/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MirRoR4s","download_url":"https://codeload.github.com/MirRoR4s/Missing-Semester/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MirRoR4s%2FMissing-Semester/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28274285,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T02:08:32.518Z","status":"ssl_error","status_checked_at":"2026-01-11T02:08:32.093Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["computer-science","tools-techniques"],"created_at":"2024-12-14T20:16:21.472Z","updated_at":"2026-01-11T03:04:09.427Z","avatar_url":"https://github.com/MirRoR4s.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Missing Semester\n\n## 前言\n\n记录课后习题的解决方案。\n\n- 所用操作系统是 `Unubtu 22.04`，shell 环境是普通的 `bash` shell。\n\n## 1. 课程概览与 shell\n\n- shell 会从环境变量 `$PATH` 中搜索执行程序的路径（基于程序的名称搜索）\n- `which` 用于确定某个程序名代表的是哪个具体的程序\n- 为进入某个文件夹，需要具备该文件夹以及其父文件夹的“**搜索**”权限（以“可执行” x 权限表示）。\n- shellbang：`#!` 后跟解释器绝对路径\n\n---\n\n## 2. [shell 工具与脚本](https://missing.csail.mit.edu/2020/shell-tools/)\n\n```bash\nls -a # 不忽略以 . 开头的项（linux 中 . 开头的项会被隐藏）\n\nls -h -l -s # -l 使用长列表格式，-s 打印文件大小，-h 指示打印大小时用 234M、1K 这样的格式\n\nls -t # 以时间顺序排序所列出的信息，默认是字典序\n\nls --color=always # 着色输出，默认就是这个配置\n\n\n```\n\n\u003e 以下都针对 bash shell 而言\n\n- 为变量赋值： `foo=bar`\n- 访问变量值： `$foo`\n\n\u003e 注意 `foo = bar` （使用空格隔开）无法正确工作。因为解释器会调用程序 `foo` 并将 `=` 和 `bar` 作为参数。在 shell 脚本中使用空格会起到分割参数的作用，有时可能会造成混淆，请务必多加检查。\n\n- `$0` - 脚本名\n- `$1` 到 `$9` - 脚本的参数。 `$1` 是第一个参数，依此类推。\n- `$@` - 所有参数\n- `$#` - 参数个数\n- `$?` - 前一个命令的返回值\n- `$$` - 当前脚本的进程识别码\n- `!!` - 完整的上一条命令，包括参数。常见应用：当你因为权限不足执行命令失败时，可以使用 `sudo !!` 再尝试一次。\n- `$_` - 上一条命令的最后一个参数。如果你正在使用的是交互式 shell，你可以通过按下 Esc 之后键入 . 来获取这个值。\n\n- 命令返回 0 表示正常执行，返回非 0 表示有错误发生。\n\n- `true` 程序的返回码永远是 0，`false` 程序的返回码永远是 1。\n\n- 命令替换（command substitution）：以变量的形式获取一个命令的输出。如 `$( CMD )` 会被替换为 `CMD` 命令的输出\n\n- 进程替换（process substitution）， `\u003c( CMD )` 会执行 `CMD` 并将结果输出到一个临时文件中，并将 `\u003c( CMD )` 替换成**临时文件名**。这在我们希望返回值通过文件而不是 STDIN 传递时很有用。例如， `diff \u003c(ls foo) \u003c(ls bar)` 会显示文件夹 foo 和 bar 中文件的区别。\n\n- shell 通配（globbing）：基于文件扩展名展开表达式\n- 花括号 `{}`：当你有一系列的指令，其中包含一段公共子串时，可以用花括号来自动展开这些命令。这在批量移动或转换文件时非常方便。\n\n```bash\nconvert image.{png,jpg}\n# 会展开为\nconvert image.png image.jpg\n```\n\n- `find` 命令：递归地搜索符合条件的文件\n\n```bash\n# 查找所有名称为src的文件夹\nfind . -name src -type d\n# 查找所有文件夹路径中包含test的python文件\nfind . -path '*/test/*.py' -type f\n# 查找前一天修改的所有文件\nfind . -mtime -1\n# 查找所有大小在500k至10M的tar.gz文件\nfind . -size +500k -size -10M -name '*.tar.gz'\n```\n\n除了列出所寻找的文件之外，find 还能对所有查找到的文件进行操作，这能极大地简化一些单调的任务。\n\n```bash\n# 删除全部扩展名为.tmp 的文件\nfind . -name '*.tmp' -exec rm {} \\;\n# 查找全部的 PNG 文件并将其转换为 JPG\nfind . -name '*.png' -exec convert {} {}.jpg \\;\n```\n\n- grep 命令：对输入文本进行匹配\n\ngrep 有很多选项：\n\n- `-C` ：获取查找结果的上下文（Context）；\n- `-v`：对结果进行反选（Invert）即输出不匹配的结果。\n\n`grep -C 5`：输出匹配结果前后五行。\n\n- `-R` ：递归地进入子目录并搜索所有的文本文件。\n\n- `Ctrl+R` 对命令历史记录进行回溯搜索\n\n---\n\n## 3. vim 编辑器\n\n- `:e {文件名}`：打开要编辑的文件\n- `:help {标题}`：打开帮助文档，比如 `:help :w` 打开 `:w` 命令的帮助文档。\n- `~`：改变字符大小写\n- `da'` 删除一个单引号字符串，包括周围的单引号\n- 编辑 `~/.vimrc` 配置文件来自定义 vim\n- 8.0 后的 vim 有内置的插件管理器，为了扩展 vim 只需创建一个 `~/.vim/pack/vendor/start` 文件夹并将插件放入其中。\n- `:s`：替换命令。`:s /test/Test/g` 在整个文件中将 test 全局替换成 Test\n- `:sp`/`:vsp`：分割窗口\n\n---\n\n## 4. 数据整理\n\n- `sed`：基于 `ed` 的流编辑器\n- `.`：匹配除换行符之外的任意单个字符\n- 在 `*` 或 `+` 后跟一个 `?` 可使表达式变成**非贪婪**模式。（sed 不支持）\n- sed 的 -E 选项可启用扩展的正则表达式\n- sed 的替换命令：s/REGEX/SUBSTITUTION/\n- 被圆括号内的正则表达式匹配到的文本都会被存入一系列以编号区分的捕获组中。捕获组的内容可以在替换字符串时使用（`sed -E 's/REGEX/\\1'`）。可通过 `\\1` 引用第一个捕获组的内容。\n- `sort`：排序输入数据\n- `uniq -c`：将连续出现的行折叠为一行并用出现次数作为前缀\n- `sort -n`：按数字顺序排序输入（默认为 ASCII）\n\n## 6. [版本控制-Git](https://missing.csail.mit.edu/2020/version-control/)\n\n### 可视化版本历史\n\n一个版本对应一次提交，所以可视化版本历史就是可视化提交（commit）历史。\n\n通过 `git log --graph --all --oneline --decorate` 可视化提交历史（以图形方式展示提交历史和分支结构。）。\n\n- --all：显示所有分支的提交历史，包括远程分支和分离头指针。\n- --graph：以图形方式显示提交历史和分支结构。\n- --oneline：以一行显示每个提交的简化信息。\n- --decorate：显示每个提交的引用，包括分支、标签等\n\n#### 参考资料\n\n- [Pro git 第二版 git log](https://git-scm.com/book/zh/v2/Git-%E5%9F%BA%E7%A1%80-%E6%9F%A5%E7%9C%8B%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2#log_options)\n- [Git 如何理解git log –all –graph –oneline –decorate的图形输出](https://geek-docs.com/git/git-questions/740_git_how_to_understand_the_graph_output_of_git_log_all_graph_oneline_decorate.htmlhttps://www.git-scm.com/docs/git-log/zh_HANS-CN)\n\n### 找出 README.md 的最后修改者\n\n可以通过 `git log` 和 `git blame` 来做，采用 log 做法的命令是：`git log -1 README.md`\n\n- -\\\u003cn\\\u003e：只显示最近的 n 次提交\n\n#### 参考资料\n\n[git 查看文件修改记录](https://geek-docs.com/git/git-questions/41_tk_1705454228.html)\n\n### 清除提交历史中的敏感信息\n\n最近的做法是利用 `git filter-repo` 这款工具\n\n- [从 commit 历史移除敏感文件](https://blog.csdn.net/yuanlaijike/article/details/89879525)\n\n#### 参考资料\n\n- \u003chttps://debugtalk.com/post/clean-sensitive-data-from-git-history-commits/\u003e\n\n- [git stash 相关](https://www.cnblogs.com/lifan-fineDay/p/16960584.html)\n- [gitconfig 配置别名](https://www.liaoxuefeng.com/wiki/896043488029600/898732837407424)\n- [gitignore 与 core_exlucdesfile] (\u003chttps://git-scm.com/docs/gitignore/zh_HANS-CN\u003e)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmirror4s%2Fmissing-semester","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmirror4s%2Fmissing-semester","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmirror4s%2Fmissing-semester/lists"}