Missing L2 useful tools
date: 2020-3-4
[^Asides]:说实话,所有的工具和efficient techniques都需要不断尝试才能让这些技巧起到更好的作用。
Find how to use commands
既然无法学会记住所有命令那么不妨试着去快速上手某些命令。
man命令
但当man太过于详细时,一些有趣的工具比如tldr工具,要比man工具更加好用一些。
Tldr give examples use cases of a command so you can quickly figure out which options to use.
可以尝试利用homebrew在macos的平台下载安装.
Find files
find命令可以帮助我们递归寻找
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27find
Find files or directories under the given directory tree, recursively.
- Find files by extension:
find root_path -name '*.ext'
- Find files by matching multiple patterns:
find root_path -name '*pattern_1*' -or -name '*pattern_2*'
- Find directories matching a given name, in case-insensitive mode:
find root_path -type d -iname *lib*
- Find files matching a path pattern:
find root_path -path '**/lib/**/*.ext'
- Find files matching a given pattern, excluding specific paths:
find root_path -name '*.py' -not -path '*/site-packages/*'
- Find files matching a given size range:
find root_path -size +500k -size -10M
- Run a command for each file (use `{}` within the command to access the filename):
find root_path -name '*.ext' -exec wc -l {} \;
- Find files modified in the last 7 days, and delete them:
find root_path -mtime -7 -delete当然,find的syntax不是那么好记的。
part of the shell philosophy is good to use alternatives
毕竟我们只能调用自己能记得住的命令。
fd*则是find命令避免了一些tricky语法的比较好的替代。
Locate 命令:实际通过目录结构寻找东西,c.f.数据库索引
Find Code
利用Linux自带的grep 命令我们可以更好的匹配我们的目标字符串和input text.
同样的利用 tldr grep我们可以得到很多grep命令。
grep -R: recursive finding.
grep -R 的alternative: ack, ag ,rg;
rg: ripgrip
查找过去到现在已存在的命令
Find shell cmds
*history * cmd
history | grep [string]: 则是比较好的衔接我L1和L2之间的例子。
Ctrl+R: perform backwards search through history.
After pressing ctrl+r, you can type a subset you want to match for cmds in your history.
A nice addition on top of Ctrl+r: interactive grep: fzf
很多命令需要自己尝试。
当你start一个cmd以空格开始时,这条命令的记录就不会被记录到你的shell history之中,这对你输入任何cmds with sensitive information的时候很有用
if you make the mistake of not adding the leading space you can always remove the entry by editing you .bash_history or .zhistory.
Directory Navigation
- ln -s
- fasd: ranks files and directories by frecency
- Overview of a directory structure: tree, broot
[^Asides]:每个lecture notes后面都有exercise是很好的练习。