Java成长之路

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

2020-03-13  本文已影响0人  Java_老男孩

今天给大家推荐一个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 系统

以下是仅限于 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:用于数据科学的一些命令和工具,摘自同名书籍。
http://datascienceatthecommandline.com/#tools

来源Java后端
链接:https://mp.weixin.qq.com/s/fOdrwyq_zzhWsmMB6EVY8A

上一篇 下一篇

猜你喜欢

热点阅读