the-art-of-command-line README

The project's README from github.com/jlevy/the-art-of-command-line. As one markdown file: README.md.

🌍 Čeština ∙ Deutsch ∙ Ελληνικά ∙ English ∙ Español ∙ Français ∙ Indonesia ∙ Italiano ∙ 日本語 ∙ 한국어 ∙ polski ∙ Português ∙ Română ∙ Русский ∙ Slovenščina ∙ Українська ∙ 简体中文 ∙ 繁體中文

The Art of Command Line

Note: I'm planning to revise this and looking for a new co-author to help with expanding this into a more comprehensive guide. While it's very popular, it could be broader and a bit deeper. If you like to write and are close to being an expert on this material and willing to consider helping, please drop me a note at josh (0x40) holloway.com. –jlevy, Holloway. Thank you!

![curl -s 'https://raw.githubusercontent.com/jlevy/the-art-of-command-line/master/README.md' | egrep -o '\w+' | tr -d '`' | cowsay -W50](cowsay.png)

Fluency on the command line is a skill often neglected or considered arcane, but it improves your flexibility and productivity as an engineer in both obvious and subtle ways. This is a selection of notes and tips on using the command-line that we've found useful when working on Linux. Some tips are elementary, and some are fairly specific, sophisticated, or obscure. This page is not long, but if you can use and recall all the items here, you know a lot.

This work is the result of many authors and translators. Some of this originally appeared on Quora, but it has since moved to GitHub, where people more talented than the original author have made numerous improvements. Please submit a question if you have a question related to the command line. Please contribute if you see an error or something that could be better!

Meta

Scope:

Notes:

Basics

Everyday use

      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)
{
      # Your code here
}
cat <<EOF
input
on multiple lines
EOF
      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

Processing files and data

the-art-of-command-line (jlevy/the-art-of-command-line)

Searching Database…

这是什么?这是一份单页指南,收集了在 Linux 和其他类 Unix 系统上使用 Bash 的必备命令行技巧、小窍门和笔记,内容从入门一直讲到高级脚本编写和调试。
这是从头读到尾的教程,还是更像参考手册?内容按部分组织(基础、日常使用、文件和数据处理、系统调试、单行命令、冷门但实用、仅限 macOS、仅限 Windows),你可以通读,也可以直接跳到需要的主题;知道命令名称后,还可以到别处查询。
初学者应该从哪里开始?从“基础”部分开始:完整阅读 man bash 页面,选一个文本编辑器(简单上手用 nano,进阶用户用 Vim 或 Emacs),并学习如何用 man 和 apropos 查找文档。
跟着学需要什么特殊工具吗,还是只要一个终端就行?只需要一个带 Bash 的标准 Unix/Linux 终端;部分技巧会用到可选的额外工具,可通过 apt、yum、dnf、pacman、pip 或 brew 安装。
这里的内容也适用于 macOS 或 Windows 吗?不全部适用。本指南默认面向 Linux,只在单独的专门部分介绍 macOS 和 Windows 特有的内容;许多其他技巧在别的系统上也能用,但不保证一定可以。
这是给完全的新手看的,还是给有经验的系统管理员看的?两者都适合。本指南追求内容全面而简洁,无论你是刚接触 Shell 的新手,还是已经有一定经验的人,都能从中受益。
这份指南主要关注哪种 Shell?主要关注交互式 Bash,不过很多技巧也适用于其他 Shell,以及一般的 Bash 脚本编写。
它会讲脚本编写的最佳实践,而不只是交互式使用吗?会的。它讲解了 Bash 脚本编写的一些习惯,比如用 set -e、set -u、set -o pipefail 和 trap 处理错误,还有变量展开和引号使用中的常见陷阱。
有没有推荐用来理解不熟悉命令的工具?有。它推荐使用 Explainshell 来拆解一条命令的选项和管道各自的作用,也推荐用 curl cheat.sh/command 快速查看速查表。
这份指南有其他语言版本吗?有。它已被翻译成多种语言,包括捷克语、德语、希腊语、西班牙语、法语、日语、韩语、波兰语、葡萄牙语、罗马尼亚语、俄语、乌克兰语,以及简体中文和繁体中文。
Creator
jlevy
Size
2.7 MB
Stars
162.5K
Updated
CommitJul 12
Age
11y
Commits · 90 Days