今天给大家推荐一个GitHub开源项目《The Art of Command Line(命令行的艺术)》,这个开源项目曾经雄踞过 GitHub TOP 周榜,现在 69.5K Star !
GitHub地址:
https://github.com/jlevy/the-art-of-command-line
以下是其中文版README-zh.md内容,有需要的小伙伴赶紧去关注一波!
熟练使用命令行是一种常常被忽视,或被认为难以掌握的技能,但实际上,它会提高你作为工程师的灵活性以及生产力。本文是一份我在 Linux 上工作时,发现的一些命令行使用技巧的摘要。有些技巧非常基础,而另一些则相当复杂,甚至晦涩难懂。这篇文章并不长,但当你能够熟练掌握这里列出的所有技巧时,你就学会了很多关于命令行的东西了。这篇文章是许多作者和译者共同的成果。这里的部分内容 首次 出现 于 Quora, 但已经迁移到了 Github,并由众多高手做出了许多改进。如果你在本文中发现了错误或者存在可以改善的地方,请贡献你的一份力量。
涵盖范围:
注意事项:
find?.?-name?'*.py'?|?xargs?grep?some_function???????cat?hosts?|?xargs?-I{}?ssh?root@{}?hostname?
set?-euo?pipefail?trap?"echo?'error:?Script?failed:?see?failed?command?above'"?ERR?
#?do?something?in?current?dir???????(cd?/some/other/dir?&&?other-command)???????#?continue?in?original?dir?
diff?/etc/hosts?<(ssh?somehost?cat?/etc/hosts)?
{???????#?在这里写代码?}?
TCPKeepAlive=yes???????ServerAliveInterval=15???????ServerAliveCountMax=6???????Compression=yes???????ControlMaster?auto???????ControlPath?/tmp/%r@%h:%p???????ControlPersist?yes?
stat?-c?'%A?%a?%n'?/etc/timezone?
>>>?2+3?5?
perl?-pi.bak?-e?'s/old-string/new-string/g'?my-files-*.txt?
#?将文件、目录和内容全部重命名?foo?->?bar:???????repren?--full?--preserve-case?--from?foo?--to?bar?.???????#?还原所有备份文件?whatever.bak?->?whatever:???????repren?--renames?--from?'(.*)\.bak'?--to?'\1'?*.bak???????#?用?rename?实现上述功能(若可用):???????rename?'s/\.bak$//'?*.bak?
mkdir?empty?&&?rsync?-r?--delete?empty/?some-dir?&&?rmdir?some-dir?
uconv?-f?utf-8?-t?utf-8?-x?'::Any-Lower;?::Any-NFD;?[:Nonspacing?Mark:]?>;?::Any-NFC;?'?<?input.txt?>?o?
getfacl?-R?/some/path?>?permissions.txt?setfacl?--restore=permissions.txt?
一些命令组合的例子:
sort?a?b?|?uniq?>?c???#?c?是?a?并?b?sort?a?b?|?uniq?-d?>?c???#?c?是?a?交?b?sort?a?b?b?|?uniq?-u?>?c???#?c?是?a?-?b?
awk?'{?x?+=?$3?}?END?{?print?x?}'?myfile?
find?.?-type?f?-ls?
egrep?-o?'acct_id=[0-9]+'?access.log?|?cut?-d=?-f2?|?sort?|?uniq?-c?|?sort?-rn?
function?taocl()?{?????????curl?-s?https://raw.githubusercontent.com/jlevy/the-art-of-command-line/master/README-zh.md|???????????pandoc?-f?markdown?-t?html?|???????????iconv?-f?'utf-8'?-t?'unicode'?|???????????xmlstarlet?fo?--html?--dropdtd?|???????????xmlstarlet?sel?-t?-v?"(html/body/ul/li[count(p)>0])[$RANDOM?mod?last()+1]"?|???????????xmlstarlet?unesc?|?fmt?-80???????}?
以下是仅限于 OS X 系统的技巧。
以下是仅限于 Windows 系统的技巧。
1、awesome-shell:一份精心组织的命令行工具及资源的列表。
https://github.com/alebcay/awesome-shell
2、awesome-osx-command-line:一份针对 OS X 命令行的更深入的指南。
https://github.com/herrbischoff/awesome-osx-command-line
3、Strict mode:为了编写更好的脚本文件。
http://redsymbol.net/articles/unofficial-bash-strict-mode/
4、shellcheck:一个静态 shell 脚本分析工具,本质上是 bash/sh/zsh 的 lint。
https://github.com/koalaman/shellcheck
5、Filenames and Pathnames in Shell:有关如何在 shell 脚本里正确处理文件名的细枝末节。
http://www.dwheeler.com/essays/filenames-in-shell.html
6、Data Science at the Command Line:用于数据科学的一些命令和工具,摘自同名书籍。
领取专属 10元无门槛券
私享最新 技术干货