MIT-The-Missing-Semester-Studynote
Lecture 1 - The Shell#
- cd ~: change work directory to users’ home.
- cd -: change work directory to last work directory.
- pwd: print work directory, print the work directory now.
- ls -l: show file list and info in work directory, “rwx” means read, right, execute (for owner, group and others), “t/T” is sticky bit only shows in others, which can stop user from removing or renaming the file.
- mv [origin_filename] [new_filename]: move file or rename file.
- Ctrl+L: clear screen.
- cat: means concatenate
- cat [filename]: print file’s text to screen
- cat [filename1] [filename2]: concatenate file’s text
- <: input text
- >: output text
- <<: add text
- |: pipe. set a command’s stdout as another command’s stdin.
- tail: show the end of file.
- tail -f: follow the file’s changes.
- tail -n [num]: show the endly num lines of file.
- $ dollar means user, # means root.
- tee: read bytes from stdin and output to stdout.
- example: ls -l | tee output.log
Lecture 2 - Shell Tools and Scripting#
- Shell just like a programming language. Blankspace is important in shell.
- $foo = bar: set a variable.
- “”: string in here will be formatted. “Value is $foo”
mcd (){
mkdir -p “$1”
}- 判断逻辑与 Python 相似。
- “$(pwd)” in string: execute the “pwd” as command, then print the output in string.
- “$@” in string: use all parameters which sent to script.
Lecture 3 - Editors (vim)#
Different modes
- normal mode(esc, view things)
- insert mode(i, edit things)
- replace mode(r key)
- visual mode(v key, move cursor and select things as block)
- command line mode(: key)
start vim
- vim
- vim filename
keys
- h(move left), l(move right), j(move down), k(move up)
- ^ [times] before here: do the same thing times repeatly.
- e: move to the end of this word
- 0: move to the begin of a line.
- $: move to the end of a line.
- U: goes up.
- D: goes down.
- G: move to the end of the file.
- gg: move to the begin of the file.
- L: move the cursor to the end line that’s shown on the screen.
- M: move the cursor to the middle line that’s shown on the screen.
- H: move the cursor to the middle line that’s shown on the screen.
- f[char]: jump to next first char of the line.
- F[char]: jump to last first char of the line.
- r[char]: replace the char on cursor to char.
- o: open a new line on cursor and turn into insert mode.
- O: open a new line on cursor’s last line and turn into insert mode.
- x: delete the char.
- d(e,1,2,3,..)w: delete x words.
- c(e,1,2,3,..)w: delete x words and turn into insert mode.
- DD: delete the line.
- CC: delete the line and turn into insert mode.
- q(in command line mode): quit now tab. if no tab exists, quit vim.
- w(in command line mode): save file.
- wq(in command line mode): save file and quit vim.
- help [key](in command line mode): open help manual about the key.
- tabnew(in command line mode): open a new tab.
- u: undo last change.
- r: redo last change.
- y: copy.
- yw: copy the word on cursor.
- yy: copy the line.
- p: paste.
- /[word] + Enter: search.
- .:repear last command.
buffers, tabs and windows
Lecture 4 - Data Wrangling#
- regular expressions
- | grep [text]: filter something.
- uniq -c: 去除相邻的重复行。
- sort [-r]: 以行为单位排序输出结果(默认依照 ASCII 码排序)。
- wc: word count. 统计指定文件中的字节数。
- tail: 查看文件的末尾部分(默认显示后十行)。
- awk: 处理结构化文本。
- paste: 将多个文件的内容按列合并在一起。
- bc: basic calculator 数学计算器。
- gnuplot: 命令行绘图程序。
- xargs: 将标准输入转换成命令行参数, 然后传递给另一个命令执行。
- sed: stream editor. 逐行读取文本流,以给定规则对每一行进行编辑,输出编辑后的结果。
s(substitute)/要查找的内容/要替换成的内容/g(global)
Lecture 5 - Command-line Environment#
- Ctrl+C: send a sigint to program.
- Ctrl+: send a sigquit to program.
- nohup: 程序在后台开始运行。
- jobs: 查看当前进行的工作。
- kill %[num]: 停止指定进程。
tmux
- tmux a: 重连最后分离的会话
- tmux a -t [name]: 连接指定会话
- tmux new -s [name]: 命名新会话
- tmux: 启动新会话
- Ctrl+B D: 分离当前会话
- Ctrl+B 0-9: 跳转到第n个窗口
- Ctrl+B ,: 重命名当前窗口
- Ctrl+B c: 创建新窗口
- Ctrl+B &: 关闭当前窗口
- Ctrl+B %/“: 垂直/水平分割窗格
- Ctrl+B 方向键: 移动到指定方向窗格
- Ctrl+B x: 关闭当前窗格
- Ctrl+B [: 进入复制模式(类似vim)
- Ctrl+B ]: 粘贴复制的内容
alias
- alias alias_name=”command_to_alias arg1 arg2”
- 临时忽略一个别名 \ls
- unalias alias_name: 完全禁用一个别名
- alias alias_name: 查看别名定义
- alias: 列出已定义的别名
- 若需要别名持久化,需要将其添加到Shell的启动配置文件中
ssh
- ssh username@hostname
- ssh username@hostname command
- ssh端口转发: ssh -L 9999:localhost:8888 username@hostname
Lecture 6 - Version Control#
Git
- git init: 在当前目录创建一个新的 Git 仓库。
- git status: 显示当前工作目录和暂存区的状态。
- git add [filename]: 将指定文件的当前更改添加到暂存区。
- git commit: 根据暂存区的内容创建一个新的提交。
- git log: 显示当前分支的提交历史记录。
- git diff (hash) (branch) [filename]: 显示当前目录中相对于暂存区的更改。
- git checkout [branch]: 更新 HEAD 和工作目录以匹配指定的提交或分支。
- git cat-file -p [hash]: 查看提交信息/目录树/文件内容
Git 的分支与合并
- git branch: 列出所有本地分支。(-a 参数表示包括远程分支)
- git branch (branch_name): 创建一个新分支。
- git checkout -b [name]: 创建新分支并立即切换到该分支。
- git merge [name]: 将指定分支合并到当前所在分支。
- git rebase [base_branch]: 将当前分支上自从与 base_branch 分叉之后的所有提交在 base_branch 的最新提交之上重新应用一遍。
Git 远程操作
- git remote: 列出当前配置的所有远程仓库的简称(-v 参数表示同时显示URL)。
- git remote add [name] [url]: 添加一个新的远程仓库。
- git push [remote] [local branch]:[remote branch]: 将本地的对象和引用推送到指定远程仓库。(-u 参数表示建立跟踪关系)
- git clone [url]: 从指定 URL 下载一个完整的远程仓库副本到本地。
- git fetch [remote_name]: 从指定的远程仓库下载所有本地没有的对象和引用。
- git pull: 拉取远程更改并尝试合并到本地当前分支。
Git 撤销操作
- git commit –amend: 修改上一次提交。
- git reset HEAD [file]: 将文件从暂存区移除,但保留工作目录中的更改。
- git checkout – [file]: 丢弃工作目录中对指定文件的未暂存更改。
- git revert [commit_hash]: 创建一个新的逆提交(适用于撤销已经推送到公共分支的提交)。
Git 高级技巧
- git config: 配置Git。
- git clone –depth=1 [url]: 浅克隆,只下载最新代码。
Lecture 7 - Debugging and Profiling#
- printf 调试
- logging 记录(Python模块)
- debuggers
- 断点
- 步进
- 检查变量
- 调用栈
- 监视表达式
- pdb 是 Python 内置的命令行调试器。(现代调用:在Python中输入 breakpoint();
- ipdb: 较pdb更现代化, import ipdb;ipdb.set_trace();
linux 事件分析
- perf: 自带的系统级性能分析工具