13518219792

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

GitHub近70K星,命令行的艺术!

 今天给大家推荐一个GitHub开源项目《The Art of Command Line(命令行的艺术)》,这个开源项目曾经雄踞过 GitHub TOP 周榜,现在 69.5K Star !

我们提供的服务有:成都网站设计、成都网站建设、外贸网站建设、微信公众号开发、网站优化、网站认证、汾阳ssl等。为上千多家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的汾阳网站制作公司

GitHub地址:

https://github.com/jlevy/the-art-of-command-line

以下是其中文版README-zh.md内容,有需要的小伙伴赶紧去关注一波!

命令行的艺术

熟练使用命令行是一种常常被忽视,或被认为难以掌握的技能,但实际上,它会提高你作为工程师的灵活性以及生产力。本文是一份我在 Linux 上工作时,发现的一些命令行使用技巧的摘要。有些技巧非常基础,而另一些则相当复杂,甚至晦涩难懂。这篇文章并不长,但当你能够熟练掌握这里列出的所有技巧时,你就学会了很多关于命令行的东西了。这篇文章是许多作者和译者共同的成果。这里的部分内容 首次 出现 于 Quora, 但已经迁移到了 Github,并由众多高手做出了许多改进。如果你在本文中发现了错误或者存在可以改善的地方,请贡献你的一份力量。

一、前言

涵盖范围:

注意事项:

二、基础

三、日常使用

 
 
 
 
  1. find . -name '*.py' | xargs grep some_function 
  2.       cat hosts | xargs -I{} ssh root@{} hostname 
 
 
 
 
  1. set -euo pipefail 
  2. trap "echo 'error: Script failed: see failed command above'" ERR 
 
 
 
 
  1. # do something in current dir 
  2.       (cd /some/other/dir && other-command) 
  3.       # continue in original dir 
 
 
 
 
  1. diff /etc/hosts <(ssh somehost cat /etc/hosts) 
 
 
 
 
  1.       # 在这里写代码 
 
 
 
 
  1. TCPKeepAlive=yes 
  2.       ServerAliveInterval=15 
  3.       ServerAliveCountMax=6 
  4.       Compression=yes 
  5.       ControlMaster auto 
  6.       ControlPath /tmp/%r@%h:%p 
  7.       ControlPersist yes 
 
 
 
 
  1. stat -c '%A %a %n' /etc/timezone 
 
 
 
 
  1. >>> 2+3 

四、文件及数据处理

 
 
 
 
  1. perl -pi.bak -e 's/old-string/new-string/g' my-files-*.txt 
 
 
 
 
  1. # 将文件、目录和内容全部重命名 foo -> bar: 
  2.       repren --full --preserve-case --from foo --to bar . 
  3.       # 还原所有备份文件 whatever.bak -> whatever: 
  4.       repren --renames --from '(.*)\.bak' --to '\1' *.bak 
  5.       # 用 rename 实现上述功能(若可用): 
  6.       rename 's/\.bak$//' *.bak 
 
 
 
 
  1. mkdir empty && rsync -r --delete empty/ some-dir && rmdir some-dir 
 
 
 
 
  1. uconv -f utf-8 -t utf-8 -x '::Any-Lower; ::Any-NFD; [:Nonspacing Mark:] >; ::Any-NFC; ' < input.txt > o 
 
 
 
 
  1. getfacl -R /some/path > permissions.txt 
  2. setfacl --restore=permissions.txt 

五、系统调试

六、单行脚本

一些命令组合的例子:

 
 
 
 
  1. sort a b | uniq > c   # c 是 a 并 b 
  2. sort a b | uniq -d > c   # c 是 a 交 b 
  3. sort a b b | uniq -u > c   # c 是 a - b 
 
 
 
 
  1. awk '{ x += $3 } END { print x }' myfile 
 
 
 
 
  1. find . -type f -ls 
 
 
 
 
  1. egrep -o 'acct_id=[0-9]+' access.log | cut -d= -f2 | sort | uniq -c | sort -rn 
 
 
 
 
  1. function taocl() { 
  2.         curl -s https://raw.githubusercontent.com/jlevy/the-art-of-command-line/master/README-zh.md| 
  3.           pandoc -f markdown -t html | 
  4.           iconv -f 'utf-8' -t 'unicode' | 
  5.           xmlstarlet fo --html --dropdtd | 
  6.           xmlstarlet sel -t -v "(html/body/ul/li[count(p)>0])[$RANDOM mod last()+1]" | 
  7.           xmlstarlet unesc | fmt -80 
  8.       } 

七、冷门但有用

八、仅限 OS X 系统

以下是仅限于 OS X 系统的技巧。

九、仅限 Windows 系统

以下是仅限于 Windows 系统的技巧。

9.1、在 Winodws 下获取 Unix 工具

9.2、实用 Windows 命令行工具

9.3、Cygwin 技巧

十、更多资源

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:用于数据科学的一些命令和工具,摘自同名书籍。


文章题目:GitHub近70K星,命令行的艺术!
分享路径:http://cdbrznjsb.com/article/ccdodpc.html

其他资讯

让你的专属顾问为你服务