├── .gitignore ├── LICENSE ├── README.md ├── devops ├── README.md ├── ansible-learning-notes.md ├── saltstack-learning-notes.md └── terraform-learning-notes.md ├── linux&unix ├── assets │ └── packet-flow-in-netfilter-and-general-networking.png ├── file │ ├── Large-scale cluster management at Google with Borg.pdf │ ├── Network_Protocol_Diagram.jpg │ ├── TCP-IP_Network_Protocol_Diagram.pdf │ ├── network-protocol-map-2016-en.pdf │ └── network-protocol-map-2016-zh.pdf ├── img │ └── 2015 │ │ ├── 05 │ │ ├── vi-vim-cheat-sheet-sch.gif │ │ ├── vi-vim-cheat-sheet.gif │ │ └── vim_cheat_sheet_for_programmers_print.png │ │ └── 06 │ │ ├── primary-extended-logical-partition.png │ │ └── view-ubuntu-version-and-kernel-version.png ├── linux-commands.md ├── shell-script-learning-notes.md ├── tmux-learning-notes.md ├── ubuntu-linux-study-guideline.md └── vim-learning-notes.md ├── macos ├── assets │ └── 2022-05-15-00-19-40.png └── mac-os-study-guideline.md ├── sre └── container-learning-notes.md └── windows ├── img ├── powershell_dsc_pull_push_mode.png └── powershellgetArchitecture.png ├── powershell-learning-notes.md └── windows-command-line-utilities.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 概要 2 | 3 | 学习Linux相关运维知识,能够帮助成为更优秀的工程师。这也是这个repo诞生的原因。 4 | 5 | # 学习准备 6 | 7 | 1. 参考[golang-dev-vm](https://github.com/EthanCai/golang-dev-vm)准备一个linux虚拟机。 8 | 9 | # Linux & Unix 10 | 11 | Linux & Unix的操作系统: 12 | 13 | - Linux 14 | - [CentOS](https://www.centos.org/) 15 | - [Wiki](https://wiki.centos.org/) 16 | - [Ubuntu Linux](https://ubuntu.com/) 17 | - [Ubuntu Help Document](https://help.ubuntu.com/) 18 | - [Debian](https://www.debian.org/) 19 | - [ArchLinux](https://www.archlinux.org/) 20 | - [Kali Linux](https://www.kali.org/) 21 | - Unix 22 | - [FreeBSD](https://www.freebsd.org/) 23 | - [FreeBSD China](https://www.freebsdchina.org/) 24 | - [Minix](http://www.minix3.org/): MINIX是一种基于微内核架构的类UNIX计算机操作系统,由Andrew S. Tanenbaum发明。MINIX最初发布于1987年,开放全部源代码给大学教学和研究工作 25 | - Container Operating Systems 26 | - [Clear Linux](https://clearlinux.org/): The Clear Linux Project for Intel Architecture is a project that is building a Linux OS distribution for various cloud use cases. The goal of Clear Linux OS is to showcase the best of Intel Architecture technology, from low-level kernel features to more complex items that span across the entire operating system stack. 27 | - [Fedora CoreOS](https://getfedora.org/en/coreos?stream=stable) 28 | - Other 29 | - [Plan9](http://plan9.bell-labs.com/plan9/): 来自Bell实验室的概念网络操作系统。 30 | - [VxWorks](http://www.windriver.com/products/vxworks/): 参考[VxWork介绍及编程](http://www.embhelp.com/drew/mypage/VxWorks.htm) 31 | 32 | 33 | 学习笔记: 34 | 35 | - [Ubuntu Linux学习笔记](./linux&unix/ubuntu-linux-study-guideline.md) 36 | - [Shell脚本学习笔记](./linux&unix/shell-script-learning-notes.md) 37 | - [Linux命令](./linux%26unix/linux-commands.md) 38 | - [Tmux学习笔记](./linux&unix/tmux-learning-notes.md) 39 | - [Vim学习笔记](./linux&unix/vim-learning-notes.md) 40 | 41 | 42 | 阅读路径: 43 | 44 | 1. Step 1 45 | - A Practical Guide to Ubuntu Linux, 3rd, Mark G. Sobell 46 | - [鸟哥的Linux私房菜](http://cn.linux.vbird.org/) 47 | - C语言程序设计:现代方法 48 | - Practical Vim 49 | - Linux Shell Scripting Cookbook 50 | - Linux命令行与Shell编程大全 51 | - UNIX/Linux系统管理技术手册 52 | 2. Step 2 53 | - Unix环境高级编程 54 | - Unix网络编程 卷1:套接字联网API 55 | - Unix网络编程 卷2:进程间通信 56 | - Begin Linux Programming 57 | - Professional Linux Programming 58 | 3. Step 3 59 | - Understanding the Linux Kernel 60 | - Linux Kernel Development 61 | - Professional Linux Kernel Architecture 62 | - Linux内核源代码情景分析 63 | 4. 扩展学习 64 | - Windows Internals 65 | - Windows内核原理和实现 66 | 67 | # DevOps 68 | 69 | - [Container技术学习](./devops/container-learning-notes.md) 70 | - [Ansible学习笔记](./devops/ansible-learning-notes.md) 71 | - [SaltStack学习笔记](./devops/saltstack-learning-notes.md) 72 | 73 | # SRE 74 | 75 | - [Container技术学习](./sre/container-learning-notes.md) 76 | 77 | # MacOS 78 | 79 | - [Mac OS学习笔记](./macos/mac-os-study-guideline.md) 80 | 81 | # Windows 82 | 83 | - [PowerShell学习笔记](./windows/powershell-learning-notes.md) 84 | - [Windows命令行学习笔记](./windows/windows-command-line-utilities.md) 85 | 86 | 87 | # 参考 88 | 89 | ## 国内的专业Linux网站 90 | 91 | - [ChinaUnix](http://www.chinaunix.net/) 92 | - [Linux伊甸园论坛](http://www.linuxeden.com/) 93 | 94 | ## 国外著名Linux网站 95 | 96 | - [Linux](http://www.Linux.com/): 学习Linux的最好网站,也是Linux使用经验的汇聚地 97 | - [Linux Online](http://www.Linux.org/): 最权威的Linux网站,文章讨论无所不包,软件硬件应有尽有 98 | - [《Linux Journal》](http://www.Linuxjournal.com/): 很棒的Linux专业杂志 99 | - [Linux Foundation Blog](https://www.linuxfoundation.org/blog/) 100 | - [Apache](http://www.apache.org): 全球占有率最高的Web服务器:Apache的网站,学习它的最好场所 101 | - [Linux Kernel](http://www.kernel.org): Linux核心的网站,有着很齐全的Linux的核心的各种版本 102 | - [opensource.com](https://opensource.com/) 103 | 104 | ## Linux Desktop 105 | 106 | - [kde](http://www.kde.org/): KDE的大本营 107 | - [深度Linux](https://www.deepin.org/en/) 108 | 109 | ## Run Windows Apps in Linux 110 | 111 | - [Wine](https://www.winehq.org/): 在 Linux,BSD,Solaris 和 Mac OS X 上运行 Windows 应用。 112 | - [Longene龙井](http://www.longene.org/index.php): Longene是一个自由、开源的操作系统项目,目的是要把Linux的内核扩充成一个既支持Linux应用、也支持Windows应用,既支持Linux设备驱动、也支持Windows设备驱动的兼容内核;使用户可以直接在Linux操作系统上高效运行Windows应用。 113 | - [Winebottler](http://winebottler.kronenberg.org/): 封装Wine,使可以运行在MacOS上 114 | -------------------------------------------------------------------------------- /devops/README.md: -------------------------------------------------------------------------------- 1 | # 相关概念 2 | 3 | ## 什么是DevOps 4 | 5 | DevOps 是一套实践、工具和文化理念,可以实现软件开发团队和 IT 团队之间的流程自动化和集成。它强调团队赋能、跨团队沟通和协作以及技术自动化。 6 | 7 | ## 什么是SCM 8 | 9 | Configuration Management,简称CM。配置管理过程是对处于不断演化、完善过程中的软件产品的管理过程。一致性、可追溯性,使产品极大程度地与用户需求相吻合。它通过控制、记录、追踪对软件的修改和每个修改生成的软件组成部件来实现对软件产品的管理功能。 10 | 11 | > Configuration management (CM) is a systems engineering process for establishing and maintaining consistency of a product's performance, functional, and physical attributes with its requirements, design, and operational information throughout its life.[1][2] The CM process is widely used by military engineering organizations to manage changes throughout the system lifecycle of complex systems, such as weapon systems, military vehicles, and information systems. Outside the military, the CM process is also used with IT service management as defined by ITIL, and with other domain models in the civil engineering and other industrial engineering segments such as roads, bridges, canals, dams, and buildings.[3][4][5] 12 | 13 | Software Configuration Management,简称SCM。SCM是软件工程中如何跟踪和管理软件变化的技术。 14 | 15 | > In software engineering, software configuration management (SCM or S/W CM) is the task of tracking and controlling changes in the software, part of the larger cross-disciplinary field of configuration management. SCM practices include revision control and the establishment of baselines. If something goes wrong, SCM can determine what was changed and who changed it. If a configuration is working well, SCM can determine how to replicate it across many hosts. 16 | 17 | 随着系统越来越复杂,除了要保证交付质量,通常还面临需求变化、开发时间不充足、人员素质技能有差别等挑战,所有的挑战决定了需要采用系统化的方法来保证整个工程开发过程的顺利进行。这就是CM和SCM诞生的原因。 18 | 19 | SCM的目的包括: 20 | 21 | * Configuration identification - Identifying configurations, configuration items and baselines. 22 | * Configuration control - Implementing a controlled change process. This is usually achieved by setting up a change control board whose primary function is to approve or reject all change requests that are sent against any baseline. 23 | * Configuration status accounting - Recording and reporting all the necessary information on the status of the development process. 24 | * Configuration auditing - Ensuring that configurations contain all their intended parts and are sound with respect to their specifying documents, including requirements, architectural specifications and user manuals. 25 | * Build management - Managing the process and tools used for builds. 26 | * Process management - Ensuring adherence to the organization's development process. 27 | * Environment management - Managing the software and hardware that host the system. 28 | * Teamwork - Facilitate team interactions related to the process. 29 | * Defect tracking - Making sure every defect has traceability back to the source. 30 | 31 | ## 什么是 Infrastructure as Code 32 | 33 | 34 | # 参考 35 | 36 | - DevOps 37 | - [关于 DevOps 你必须知道的 11 件事](http://www.infoq.com/cn/articles/11devops) 38 | - [DevOps:打破开发运维的屏障](https://www.atlassian.com/zh/devops) 39 | - SCM 40 | - [Wikipedia - Configuration Management](https://en.wikipedia.org/wiki/Configuration_management) 41 | - [Wikipedia - Software configuration management](https://en.wikipedia.org/wiki/Software_configuration_management) 42 | - [Comparison of open-source configuration management software](https://en.wiki2.org/wiki/Comparison_of_open-source_configuration_management_software) 43 | - Infrastructure As Code 44 | - [RedHat - What is Infrastructure as Code (IaC)?](https://www.redhat.com/en/topics/automation/what-is-infrastructure-as-code-iac) 45 | -------------------------------------------------------------------------------- /devops/ansible-learning-notes.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EthanCai/linux-system-ops/0bcfd206908ff3293a17c782ddb8a3aac1f23752/devops/ansible-learning-notes.md -------------------------------------------------------------------------------- /devops/saltstack-learning-notes.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EthanCai/linux-system-ops/0bcfd206908ff3293a17c782ddb8a3aac1f23752/devops/saltstack-learning-notes.md -------------------------------------------------------------------------------- /devops/terraform-learning-notes.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EthanCai/linux-system-ops/0bcfd206908ff3293a17c782ddb8a3aac1f23752/devops/terraform-learning-notes.md -------------------------------------------------------------------------------- /linux&unix/assets/packet-flow-in-netfilter-and-general-networking.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EthanCai/linux-system-ops/0bcfd206908ff3293a17c782ddb8a3aac1f23752/linux&unix/assets/packet-flow-in-netfilter-and-general-networking.png -------------------------------------------------------------------------------- /linux&unix/file/Large-scale cluster management at Google with Borg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EthanCai/linux-system-ops/0bcfd206908ff3293a17c782ddb8a3aac1f23752/linux&unix/file/Large-scale cluster management at Google with Borg.pdf -------------------------------------------------------------------------------- /linux&unix/file/Network_Protocol_Diagram.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EthanCai/linux-system-ops/0bcfd206908ff3293a17c782ddb8a3aac1f23752/linux&unix/file/Network_Protocol_Diagram.jpg -------------------------------------------------------------------------------- /linux&unix/file/TCP-IP_Network_Protocol_Diagram.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EthanCai/linux-system-ops/0bcfd206908ff3293a17c782ddb8a3aac1f23752/linux&unix/file/TCP-IP_Network_Protocol_Diagram.pdf -------------------------------------------------------------------------------- /linux&unix/file/network-protocol-map-2016-en.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EthanCai/linux-system-ops/0bcfd206908ff3293a17c782ddb8a3aac1f23752/linux&unix/file/network-protocol-map-2016-en.pdf -------------------------------------------------------------------------------- /linux&unix/file/network-protocol-map-2016-zh.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EthanCai/linux-system-ops/0bcfd206908ff3293a17c782ddb8a3aac1f23752/linux&unix/file/network-protocol-map-2016-zh.pdf -------------------------------------------------------------------------------- /linux&unix/img/2015/05/vi-vim-cheat-sheet-sch.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EthanCai/linux-system-ops/0bcfd206908ff3293a17c782ddb8a3aac1f23752/linux&unix/img/2015/05/vi-vim-cheat-sheet-sch.gif -------------------------------------------------------------------------------- /linux&unix/img/2015/05/vi-vim-cheat-sheet.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EthanCai/linux-system-ops/0bcfd206908ff3293a17c782ddb8a3aac1f23752/linux&unix/img/2015/05/vi-vim-cheat-sheet.gif -------------------------------------------------------------------------------- /linux&unix/img/2015/05/vim_cheat_sheet_for_programmers_print.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EthanCai/linux-system-ops/0bcfd206908ff3293a17c782ddb8a3aac1f23752/linux&unix/img/2015/05/vim_cheat_sheet_for_programmers_print.png -------------------------------------------------------------------------------- /linux&unix/img/2015/06/primary-extended-logical-partition.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EthanCai/linux-system-ops/0bcfd206908ff3293a17c782ddb8a3aac1f23752/linux&unix/img/2015/06/primary-extended-logical-partition.png -------------------------------------------------------------------------------- /linux&unix/img/2015/06/view-ubuntu-version-and-kernel-version.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EthanCai/linux-system-ops/0bcfd206908ff3293a17c782ddb8a3aac1f23752/linux&unix/img/2015/06/view-ubuntu-version-and-kernel-version.png -------------------------------------------------------------------------------- /linux&unix/linux-commands.md: -------------------------------------------------------------------------------- 1 | - [1. 网络](#1-网络) 2 | - [2. 数据传输](#2-数据传输) 3 | - [3. 文档处理](#3-文档处理) 4 | - [4. CPU](#4-cpu) 5 | - [5. 内存](#5-内存) 6 | - [6. 进程](#6-进程) 7 | - [7. 磁盘管理](#7-磁盘管理) 8 | - [8. 性能优化](#8-性能优化) 9 | - [9. 安全](#9-安全) 10 | - [10. 专题](#10-专题) 11 | - [11. 参考](#11-参考) 12 | 13 | 14 | # 1. 网络 15 | 16 | 设备&路由: 17 | 18 | - ip: 用于显示与配置网卡参数。作为Linux系统下一款好用的网卡参数配置工具,ip命令除了常规操作外,还可以对主机的路由、网络设备、策略路由以及隧道信息进行查看。 19 | - [ip命令 – 显示与配置网卡参数](https://www.linuxcool.com/ip) 20 | - [16 Linux ip command examples to configure network interfaces (cheatsheet)](https://www.golinuxcloud.com/linux-ip-command/) 21 | - [https://www.golinuxcloud.com/ip-route-command-in-linux/](https://www.golinuxcloud.com/ip-route-command-in-linux/) 22 | - ifconfig: 显示或设置网络设备参数信息 23 | - [ifconfig命令 – 显示或设置网络设备参数信息](https://www.linuxcool.com/ifconfig) 24 | - route 25 | - [第二章、基础网络概念 | 鸟哥的linux私房菜](http://cn.linux.vbird.org/linux_server/0110network_basic_3.php#tcpip_network_route) 26 | - [第八章、路由观念与路由器设定 | 鸟哥的linux私房菜](http://cn.linux.vbird.org/linux_server/0230router_1.php) 27 | - iptables: a user-space utility program that allows a system administrator to configure the IP packet filter rules of the Linux kernel firewall, implemented as different Netfilter modules. The filters are organized in different tables, which contain chains of rules for how to treat network traffic packets. 28 | - [Iptables详解](https://blog.csdn.net/reyleon/article/details/12976341) 29 | - https://en.wikipedia.org/wiki/Iptables 30 | - ![](./assets/packet-flow-in-netfilter-and-general-networking.png) 31 | - https://www.netfilter.org/documentation/index.html 32 | - https://www.frozentux.net/iptables-tutorial/iptables-tutorial.html 33 | - https://wiki.archlinux.org/title/iptables 34 | - [iptables vs route](http://superuser.com/questions/419659/iptables-vs-route) 35 | - iftop: 用来监控网卡的实时流量、反向解析IP、显示端口信息 36 | - [Linux流量监控工具 - iftop (最全面的iftop教程)](https://www.vpser.net/manage/iftop.html) 37 | 38 | 39 | DNS&连通性: 40 | 41 | - DNS lookup utility 42 | - nslookup 43 | - 参考[Linux and Unix - nslookup command](http://www.computerhope.com/unix/unslooku.htm) 44 | - dig 45 | - 参考[Linux and Unix - dig command](http://www.computerhope.com/unix/dig.htm) 46 | - host 47 | - 参考[Linux and Unix - host command](http://www.computerhope.com/unix/host.htm) 48 | - ping: 测试网络连通性 49 | - [ping命令 – 测试主机间网络连通性](https://www.linuxcool.com/ping) 50 | - [15+ ping command examples in Linux](https://www.golinuxcloud.com/ping-command-linux) 51 | - traceroute: 追踪数据包在网络上的传输时的全部路径 52 | - [每天一个linux命令(55):traceroute命令](https://www.cnblogs.com/peida/archive/2013/03/07/2947326.html) 53 | - [traceroute命令 – 追踪数据包在网络上的传输时的全部路径](https://www.linuxcool.com/traceroute) 54 | - mtr: 全称 my traceroute,是一个把 ping 和 traceroute 合并到一个程序的网络诊断工具 55 | - [mtr的用法](https://mp.weixin.qq.com/s/90rHRd8ZjrWc6pv6H1gYtQ) 56 | - [MTR工具使用说明与结果分析](https://help.aliyun.com/document_detail/98706.html) 57 | 58 | 状态统计: 59 | 60 | - netstat: 显示网络状态,例如网络连接状态、路由表信息、接口状态、NAT、多播成员等等 61 | - [netstat命令 – 显示网络状态](https://www.linuxcool.com/netstat) 62 | - [20 netstat command examples in Linux [Cheat Sheet]](https://www.golinuxcloud.com/netstat-command-in-linux/) 63 | - ss: 获取socket统计信息,优势在于它能够显示更多更详细的有关TCP和连接状态的信息,而且比netstat更快 64 | - [man page](https://man7.org/linux/man-pages/man8/ss.8.html) 65 | - [How to Use the ss Command on Linux](https://www.howtogeek.com/681468/how-to-use-the-ss-command-on-linux/) 66 | - [Probe Your Linux Sockets With ss](https://www.linux.com/learn/intro-to-linux/2017/4/probe-your-linux-sockets-ss) 67 | - pathchar: 确定网络路径特征 68 | - tcpdump: 网络数据包嗅探器 69 | - [home web site of tcpdump](https://www.tcpdump.org/) 70 | - [Let's learn tcpdump!](https://jvns.ca/tcpdump-zine.pdf) 71 | - [tcpdump命令详解](https://www.cnblogs.com/ggjucheng/archive/2012/01/14/2322659.html) 72 | - ngrep: grep命令的网络版,用于搜寻指定的数据包 73 | - [github.com/jpr5/ngrep](https://github.com/jpr5/ngrep) 74 | - [ngrep - wikipedia](https://en.wikipedia.org/wiki/Ngrep) 75 | - [What is ngrep and How to Use It?](https://linuxhint.com/how-to-use-ngrep/) 76 | - [ngrep - network grep ](http://ngrep.sourceforge.net/usage.html) 77 | - tcpkit: 支持用 lua 脚本分析网络数据包的工具,附带简单协议解析(Redis/Memcached)和延时统计 78 | - https://github.com/git-hulk/tcpkit 79 | - wireshark: a popular open source graphical user interface (GUI) tool for analyzing packets 80 | - [Wireshark基本介绍和学习TCP三次握手](https://www.cnblogs.com/TankXiao/archive/2012/10/10/2711777.html) 81 | - [Wireshark 的抓包和分析,看这篇就够了!](https://mp.weixin.qq.com/s/poo59EGr-V6hC84goESaiA) 82 | - [【技术流】Wireshark对HTTPS数据的解密](https://zhuanlan.zhihu.com/p/36669377) 83 | - [Decrypting SSL/TLS Traffic with Wireshark](https://linuxhint.com/decrypt-ssl-tls-wireshark/) 84 | - tshark: tshark是wireshark网络分析工具下的一个分支,主要用于命令行环境进行抓包、分析,尤其对协议深层解析时,tcpdump难以胜任的场景中 85 | - [tshark.dev](https://tshark.dev/)complete guide to working with packet captures on the command-line 86 | - [网络分析利器wireshark命令版(1):tshark简介](https://segmentfault.com/a/1190000018886363) 87 | - [网络分析利器wireshark命令版(2):tshark使用示例](https://segmentfault.com/a/1190000018886731) 88 | - [Use Wireshark at the Linux command line with TShark](https://opensource.com/article/20/1/wireshark-linux-tshark) 89 | 90 | 91 | # 2. 数据传输 92 | 93 | - rsync 94 | - [官方文档](https://rsync.samba.org/documentation.html) 95 | - [rsync udr——远程大文件传输加速](https://mp.weixin.qq.com/s?__biz=MzUxMDQxMDMyNg==&mid=2247484620&idx=1&sn=ea286199de2572391194428bb58909b5&chksm=f9022ff5ce75a6e3442ccbc4a9e1cadf10c56d760f8fbef0434297d9bd4ddc4152c3ebb33da9&scene=21#wechat_redirect) 96 | - [Running rsync as a daemon](https://www.jveweb.net/en/archives/2011/01/running-rsync-as-a-daemon.html) 97 | - [centos下安装rsync](https://www.jianshu.com/p/0df0633613d8) 98 | - [Rsync : Sync Files/Directories](https://www.server-world.info/en/note?os=CentOS_7&p=rsync) 99 | - wdt: WDT(Warp speed Data Transfer),多链路数据传输,基于TCP协议;是FaceBook开源的一个项目,其目的是在尽量减少资源(CPU/内存等)消耗的情况下,利用多个TCP路径提高两个系统之间传送文件的效率。 100 | - [大文件传输利器WDT,跨网、跨国效果非常赞](https://mp.weixin.qq.com/s/uRHsnckaAtJ_nEHyLFyGgw) 101 | - curl 102 | - [Documentation](https://curl.se/docs/) 103 | - [The Art Of Scripting HTTP Requests Using Curl](https://curl.se/docs/httpscripting.html) 104 | - [阮一峰——curl网站开发指南](http://www.ruanyifeng.com/blog/2011/09/curl.html) 105 | 106 | 107 | # 3. 文档处理 108 | 109 | - find 110 | - [Classic SysAdmin: How to Search for Files from the Linux Command Line](https://www.linuxfoundation.org/blog/classic-sysadmin-how-to-search-for-files-from-the-linux-command-line/) 111 | - [Beyond Finding Stuff with the Linux find Command](https://www.linux.com/topic/desktop/beyond-finding-stuff/) 112 | - [find命令 – 根据路径和条件搜索指定文件](https://www.linuxcool.com/find) 113 | - [How to audit permissions with the find command](https://www.redhat.com/sysadmin/audit-permissions-find) 114 | - jq: jq is a lightweight and flexible command-line JSON processor. 115 | - [tutorial](https://stedolan.github.io/jq/tutorial/) 116 | - xargs 117 | - [xargs 命令教程](https://www.ruanyifeng.com/blog/2019/08/xargs-tutorial.html) 118 | - grep 119 | - [Using Grep & Regular Expressions to Search for Text Patterns in Linux](https://www.digitalocean.com/community/tutorials/using-grep-regular-expressions-to-search-for-text-patterns-in-linux) 120 | - [How To Use grep Command In Linux / UNIX With Practical Examples](https://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/) 121 | - [Regular expressions in grep ( regex ) with examples](https://www.cyberciti.biz/faq/grep-regular-expressions/) 122 | - [Linux grep 命令](https://www.runoob.com/linux/linux-comm-grep.html) 123 | - [Linux中的Grep命令使用实例](https://cloud.tencent.com/developer/article/1554542) 124 | - ack 125 | - [Linux: Ack 用法, Ack 文档](https://justcode.ikeepstudying.com/2020/10/linux-ack-%E7%94%A8%E6%B3%95-ack-%E6%96%87%E6%A1%A3/) 126 | - [官方文档](https://beyondgrep.com/documentation/) 127 | - awk 128 | - [awk 入门教程](http://www.ruanyifeng.com/blog/2018/11/awk.html) 129 | - [AWK 简明教程](https://coolshell.cn/articles/9070.html) 130 | - [The GNU Awk User’s Guide](https://www.gnu.org/software/gawk/manual/gawk.html) 131 | - [30 Examples for Awk Command in Text Processing](https://likegeeks.com/awk-command/) 132 | - [How To Use the AWK language to Manipulate Text in Linux](https://www.digitalocean.com/community/tutorials/how-to-use-the-awk-language-to-manipulate-text-in-linux?utm_source=DigitalOcean_Newsletter) 133 | - [Why you should learn just a little Awk](https://gregable.com/2010/09/why-you-should-know-just-little-awk.html) 134 | - sed 135 | - [SED 简明教程](https://coolshell.cn/articles/9104.html) 136 | - [Sed - An Introduction and Tutorial by Bruce Barnett](https://www.grymoire.com/Unix/Sed.html) 137 | - [Intermediate Sed: Manipulating Streams of Text in a Linux Environment](https://www.digitalocean.com/community/tutorials/intermediate-sed-manipulating-streams-of-text-in-a-linux-environment) 138 | 139 | 140 | 141 | # 4. CPU 142 | 143 | 144 | - top 145 | - [理解CPU利用率](https://www.jianshu.com/p/f595ee986b55?hmsr=toutiao.io&utm_medium=toutiao.io&utm_source=toutiao.io) 146 | - [30 Top Command Examples for Monitoring in Linux](https://linoxide.com/linux-command/linux-top-command-examples-screenshots/) 147 | - [How Do I Find Out Linux CPU Utilization?](https://www.cyberciti.biz/tips/how-do-i-find-out-linux-cpu-utilization.html) 148 | - [top命令](https://www.cnblogs.com/peida/archive/2012/12/24/2831353.html) 149 | - [每天一个linux命令(44):top命令](https://www.cnblogs.com/peida/archive/2012/12/24/2831353.html) 150 | - htop 151 | - sysstat 152 | - mpstat 153 | 154 | 155 | # 5. 内存 156 | 157 | - vmstat: Virtual Meomory Statistics(虚拟内存统计), 可对操作系统的虚拟内存、进程、CPU活动进行监视. 它是对系统的整体情况进行统计, 但不能针对某个进程进行深入分析 158 | - [vmstat 命令](https://blogread.cn/it/article/3902?f=wb_news) 159 | 160 | 161 | # 6. 进程 162 | 163 | - lsof: 用于查看进程开打的文件,打开文件的进程,进程打开的端口(TCP、UDP) 164 | - `man lsof` 165 | - [lsof 命令使用指南](https://mp.weixin.qq.com/s?__biz=MzI3MTI2NzkxMA==&mid=2247486509&idx=1&sn=942d2f3ad6d18db2e0db02ef8b03a7c2&chksm=eac52d04ddb2a412c970acef315b1ce41243ff953cdd500b8260639c943a3d0c467fbefce8a1&scene=21#wechat_redirect) 166 | - ps 167 | - pstree 168 | - kill 169 | - ulimit: provides control over the resources available to the shell and to processes started by it, on systems that allow such control 170 | - https://phoenixnap.com/kb/ulimit-linux-command 171 | - https://ss64.com/bash/ulimit.html 172 | - prlimit: get and set process resource limits 173 | - https://manpages.ubuntu.com/manpages/xenial/man1/prlimit.1.html 174 | - pgrep 175 | - fg/bg 176 | - [Linux - 请允许我静静地后台运行](http://blog.jobbole.com/111850/) 177 | 178 | 179 | # 7. 磁盘管理 180 | 181 | - df/du 182 | - [Linux下查看文件和文件夹大小的df和du命令](https://yayu.org/look.php?id=162) 183 | - iostat: 收集和展示系统输入和输出存储设备统计的简单工具 184 | - iotop: 监控和显示实时的磁盘 I/O 输入和输出和程序进程 185 | 186 | # 8. 性能优化 187 | 188 | - sar: System Activity Reporter(系统活动情况报告)的缩写。sar工具将对系统当前的状态进行取样,然后通过计算数据和比例来表达系统的当前运行状态。它的特点是可以连续对系统取样,获得大量的取样数据;取样数据和分析的结果都可以存入文件,所需的负载很小。 189 | - [sar 找出系统瓶颈的利器](https://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/sar.html) 190 | - [10 Useful Sar (Sysstat) Examples for UNIX / Linux Performance Monitoring](https://www.thegeekstuff.com/2011/03/sar-examples/) 191 | - [20 sar command examples in Linux [Cheat Sheet]](https://www.golinuxcloud.com/sar-command-in-linux/) 192 | - perf: TCP/IP栈跟踪:连接、数据包、丢包、延时 193 | - [perf Examples](https://www.brendangregg.com/perf.html) 194 | - [How to use perf tool for tracing similar to dtrace](https://www.thegeekdiary.com/how-to-use-perf-tool-for-tracing-similar-to-dtrace/) 195 | - DTrace: DTrace is a comprehensive dynamic tracing framework originally created by Sun Microsystems for troubleshooting kernel and application problems on production systems in real time 196 | - [wiki2 - DTrace](https://wiki2.org/en/DTrace) 197 | - [DTrace Tools](https://www.brendangregg.com/dtrace.html) 198 | - Berkeley Packet Filter: The Berkeley Packet Filter (BPF) is a technology used in certain computer operating systems for programs that need to, among other things, analyze network traffic (and eBPF is an extended BPF JIT virtual machine in the Linux kernel). 199 | - [Wiki2 - BPF](https://wiki2.org/en/EBPF+Newton) 200 | 201 | 202 | # 9. 安全 203 | 204 | - nmap 205 | - [Understanding Nmap by using hping](https://medium.com/@reginaldlaurent/understanding-nmap-by-using-hping-c27e6b613bd9) 206 | - [Comparison of Nmap, Netcat, Hping3 tools](https://titanwolf.org/Network/Articles/Article?AID=43618944-204a-4ac9-a982-2f163db31e89) 207 | - [NMAP 常用扫描简介(一)](https://mp.weixin.qq.com/s?__biz=MjM5NjQ4MjYwMQ==&mid=2664608847&idx=1&sn=5d98128987ce41aaf92028aac20383f4&chksm=bdce8f098ab9061f582e37a63c9901783577654f87a240b37372282e911288ce6b671b8180bb&scene=0&key=24d0ae311a85eefa32abe6c5b5c7cf5962630da7717bcaa1e18153031255be627971e084606566e6faf43eee1ea331d68034bf7d276796d8c7941a024ff821eca1880bd757e2aa85ac02acdc8f998da8&ascene=0&uin=MjYxMzYyNzA0MA%3D%3D&devicetype=iMac+MacBookPro11%2C4+OSX+OSX+10.12.4+build(16E195)&version=12020110&nettype=WIFI&fontScale=100&pass_ticket=6Hb1hWILMRJHL9uGhy9pAbkGJHl5duMbl9l1zltmQzBvNtmcDolgjXush5at2jq1) 208 | - [Linux常用网络工具:批量主机服务扫描之nmap](https://www.linuxdiyf.com/linux/12486.html) 209 | - [Informative guide to NC (Ncat) command in Linux](https://thelinuxgurus.com/informative-guide-to-nc-ncat-command-in-linux/) 210 | 211 | 212 | 213 | # 10. 专题 214 | 215 | - 查看TCP连接数 216 | - https://my.oschina.net/u/1169079/blog/397705 217 | - TCP常见故障排查 218 | - https://ms2008.github.io/2018/06/01/tcp-troubleshooting/ 219 | - 查看网络流量 220 | - 监控总体带宽使用――nload、bmon、slurm、bwm-ng、cbm、speedometer和netload 221 | - 监控总体带宽使用(批量式输出)――vnstat、ifstat、dstat和collectl 222 | - 每个套接字连接的带宽使用――iftop、iptraf、tcptrack、pktstat、netwatch和trafshow 223 | - 每个进程的带宽使用――nethogs 224 | - [数据科学家的命令行技巧](https://linux.cn/article-10342-1.html) 225 | - [三种系统监控工具对比:top vs Htop vs Glances](https://mp.weixin.qq.com/s/_YdwciFT6qu5_kUIyylR2g) 226 | - 在多个Linux上执行命令 227 | - https://www.tecmint.com/run-commands-on-multiple-linux-servers/ 228 | - https://serverfault.com/questions/161690/distributed-grep 229 | 230 | 231 | # 11. 参考 232 | 233 | 手册 234 | - [Linux命令大全(手册)](https://www.linuxcool.com/) 235 | - [Linux Tools Quick Tutorial](https://linuxtools-rst.readthedocs.io/) 236 | - [100+ Linux commands cheat sheet & examples](https://www.golinuxcloud.com/linux-commands-cheat-sheet/) 237 | - [每天一个linux命令目录](https://www.cnblogs.com/peida/archive/2012/12/05/2803591.html) 238 | - 性能优化 239 | - [Linux Performance](https://www.brendangregg.com/linuxperf.html) 240 | - [性能之巅:Linux 网络性能分析工具](https://www.infoq.cn/article/linux-networking-performance-analytics/) 241 | - [性能不好怎么办?对着清单撸一遍](https://mp.weixin.qq.com/s?__biz=MzAwNjY4NTQ4MA==&mid=2651174290&idx=1&sn=288518f030801f4d90878e806546487c&scene=1&srcid=0721NBPW2U9bCAlMyD6IR9uY&from=singlemessage&isappinstalled=0#wechat_redirect) 242 | - [中文翻译:用十条命令在一分钟内检查Linux服务器性能](http://www.infoq.com/cn/news/2015/12/linux-performance/) 243 | -------------------------------------------------------------------------------- /linux&unix/shell-script-learning-notes.md: -------------------------------------------------------------------------------- 1 | 2 | - [1. 常用系统变量 Common System Variables](#1-常用系统变量-common-system-variables) 3 | - [2. 符号化的内置命令 Builtin commands that are symbols](#2-符号化的内置命令-builtin-commands-that-are-symbols) 4 | - [3. 控制结构 Control Structures](#3-控制结构-control-structures) 5 | - [3.1. if...else pattern](#31-ifelse-pattern) 6 | - [3.2. if...then...else pattern](#32-ifthenelse-pattern) 7 | - [3.3. if...then...elif pattern](#33-ifthenelif-pattern) 8 | - [3.4. for...in pattern](#34-forin-pattern) 9 | - [3.5. for pattern](#35-for-pattern) 10 | - [3.6. while pattern](#36-while-pattern) 11 | - [3.7. until pattern](#37-until-pattern) 12 | - [3.8. break and continue pattern](#38-break-and-continue-pattern) 13 | - [3.9. case pattern](#39-case-pattern) 14 | - [3.10. select pattern](#310-select-pattern) 15 | - [4. 文件描述符 File Descriptors](#4-文件描述符-file-descriptors) 16 | - [5. 参考 References](#5-参考-references) 17 | 18 | 19 | 20 | 21 | # 1. 常用系统变量 Common System Variables 22 | 23 | - `$0`: 当前shell程序的名字 24 | - `$1`~`$9`: 命令行上的第一到第九个参数 25 | - `$#`: 命令行上的参数个数 26 | - `$*`: 命令行上的所有参数 27 | - `$@`: 分别用双引号引用命令行上的所有参数 28 | - `$$`: 当前进程的进程标识号(PID) 29 | - `$?`: 上一条命令的退出状态 30 | - `$!`: 最后一个后台进程的进程标识号 31 | 32 | # 2. 符号化的内置命令 Builtin commands that are symbols 33 | 34 | - `()`: subshell 35 | - `$()`: command substitution 36 | - `(())`: arithmetic evaluation 37 | - `$(())`: arithmetic expansion 38 | - `[]`: test command 39 | - `[[]]`: conditional expression, as the modern variant of the classic test command 40 | 41 | 42 | # 3. 控制结构 Control Structures 43 | 44 | ## 3.1. if...else pattern 45 | 46 | pattern: 47 | 48 | ```bash 49 | if test-command 50 | then 51 | commands 52 | fi 53 | ``` 54 | 55 | example: 56 | 57 | ```bash 58 | echo check arguments amounts 59 | if [ $# -eq 0 ] 60 | then 61 | echo "You must supply at least one argument." 62 | exit 1 63 | fi 64 | echo "Program running..." 65 | 66 | echo check whether file is an ordinary file 67 | if [ -f "$1" ] 68 | then 69 | echo "$1 is an ordinary file in the working directory" 70 | else 71 | echo "$1 is NOT an ordinary file in the working directory" 72 | fi 73 | ``` 74 | 75 | ## 3.2. if...then...else pattern 76 | 77 | pattern: 78 | 79 | ```bash 80 | if test-command 81 | then 82 | commands 83 | else 84 | commands 85 | fi 86 | ``` 87 | 88 | example: 89 | 90 | ```bash 91 | if [ $# -eq 0 ] 92 | then 93 | echo "Usage: out [-v] filenames..." 1>&2 94 | exit 1 95 | fi 96 | 97 | if [ "$1" = "-v" ] 98 | then 99 | shift 100 | less -- "$@" 101 | else 102 | cat -- "$@" 103 | fi 104 | ``` 105 | 106 | ## 3.3. if...then...elif pattern 107 | 108 | pattern: 109 | 110 | ```bash 111 | if test-command 112 | then 113 | commands 114 | elif test-command 115 | then 116 | commands 117 | ... 118 | else 119 | commands 120 | fi 121 | ``` 122 | 123 | example: 124 | 125 | ```bash 126 | echo -n "word 1: " 127 | read word1 128 | echo -n "word 2: " 129 | read word2 130 | echo -n "word 3: " 131 | read word3 132 | if [ "$word1" = "$word2" -a "$word2" = "$word3" ] 133 | then 134 | echo "Match: words 1, 2, & 3" 135 | elif [ "$word1" = "$word2" ] 136 | then 137 | echo "Match: words 1 & 2" 138 | elif [ "$word1" = "$word3" ] 139 | then 140 | echo "Match: words 1 & 3" 141 | elif [ "$word2" = "$word3" ] 142 | then 143 | echo "Match: words 2 & 3" 144 | else 145 | echo "No Match" 146 | fi 147 | ``` 148 | 149 | ## 3.4. for...in pattern 150 | 151 | pattern: 152 | 153 | ```bash 154 | for loop-index in argument-list 155 | do 156 | commands 157 | done 158 | ``` 159 | 160 | example: 161 | 162 | ```bash 163 | for fruit in apples oranges pears bananas 164 | do 165 | echo "$fruit" 166 | done 167 | echo "Task complete." 168 | ``` 169 | 170 | ```bash 171 | for i in * 172 | do 173 | if [ -d "$i" ] 174 | then 175 | echo "$i" 176 | fi 177 | done 178 | ``` 179 | 180 | ## 3.5. for pattern 181 | 182 | the loop-index takes on the value of each of the command- line arguments, one at a time. 183 | 184 | pattern: 185 | 186 | ```bash 187 | for loop-index 188 | do 189 | commands 190 | done 191 | ``` 192 | 193 | example: 194 | 195 | ```bash 196 | if [ $# -eq 0 ] 197 | then 198 | echo "Usage: whos id..." 1>&2 199 | exit 1 200 | fi 201 | 202 | for id 203 | do 204 | mawk -F: '{print $1, $5}' /etc/passwd | 205 | grep -i "$id" 206 | done 207 | ``` 208 | 209 | ## 3.6. while pattern 210 | 211 | pattern: 212 | 213 | ```bash 214 | while test-command 215 | do 216 | commands 217 | done 218 | ``` 219 | 220 | example: 221 | 222 | ```bash 223 | number=0 224 | while [ "$number" -lt 10 ] 225 | do 226 | echo -n "$number" 227 | ((number +=1)) 228 | done 229 | ``` 230 | 231 | ## 3.7. until pattern 232 | 233 | pattern: 234 | 235 | ```bash 236 | until test-command 237 | do 238 | commands 239 | done 240 | ``` 241 | 242 | example: 243 | 244 | ```bash 245 | secretname=zach 246 | name=noname 247 | echo "Try to guess the secret name!" 248 | echo 249 | until [ "$name" = "$secretname" ] 250 | do 251 | echo -n "Your guess: " 252 | read name 253 | done 254 | echo "Very good." 255 | ``` 256 | 257 | ## 3.8. break and continue pattern 258 | 259 | example: 260 | 261 | ```bash 262 | for index in 1 2 3 4 5 6 7 8 9 10 263 | do 264 | if [ $index -le 3 ] ; then 265 | echo "continue" 266 | continue 267 | fi 268 | 269 | echo $index 270 | 271 | if [ $index -ge 8 ] ; then 272 | echo "break" 273 | break 274 | fi 275 | done 276 | ``` 277 | 278 | ## 3.9. case pattern 279 | 280 | pattern: 281 | 282 | ```bash 283 | case test-string in 284 | pattern-1) 285 | commands-1 286 | ;; 287 | pattern-2) 288 | commands-2 289 | ;; 290 | pattern-3) 291 | commands-3 292 | ;; 293 | esac 294 | ``` 295 | 296 | example: 297 | 298 | ```bash 299 | echo -n "Enter A, B, or C: " 300 | read letter 301 | case "$letter" in 302 | A) 303 | echo "You entered A" 304 | ;; 305 | B) 306 | echo "You entered B" 307 | ;; 308 | C) 309 | echo "You entered C" 310 | ;; 311 | *) 312 | echo "You did not enter A, B, or C" 313 | ;; 314 | esac 315 | ``` 316 | 317 | ## 3.10. select pattern 318 | 319 | pattern: 320 | 321 | ```bash 322 | select varname [in arg...] 323 | do 324 | commands 325 | done 326 | ``` 327 | 328 | example: 329 | 330 | ```bash 331 | PS3="Choose your favorite fruit from these possibilities: " 332 | select FRUIT in apple banana blueberry kiwi orange watermelon STOP 333 | do 334 | if [ "$FRUIT" == "" ]; then 335 | echo -e "Invalid entry.\n" 336 | continue 337 | elif [ $FRUIT = STOP ]; then 338 | echo "Thanks for playing!" 339 | break 340 | fi 341 | 342 | echo "You chose $FRUIT as your favorite." 343 | echo -e "That is choice number $REPLY.\n" 344 | done 345 | ``` 346 | 347 | # 4. 文件描述符 File Descriptors 348 | 349 | 参考: 350 | 351 | - [I/O Redirection](http://www.tldp.org/LDP/abs/html/io-redirection.html) 352 | - [Bash: file descriptors](http://stackoverflow.com/questions/15606296/bash-file-descriptors) 353 | 354 | ```bash 355 | usage () 356 | { 357 | if [ $# -ne 2 ]; then 358 | echo "Usage: $0 file1 file2" 2>&1 359 | exit 1 360 | fi 361 | } 362 | 363 | echo # Default temporary directory 364 | : ${TEMPDIR:=/tmpdescrip} 365 | 366 | echo #Check argument count' 367 | usage "$@" 368 | 369 | echo # Set up temporary files for sorting 370 | file1=$TEMPDIR/$$.file1 371 | file2=$TEMPDIR/$$.file2 372 | 373 | echo # Sort 374 | sort $1 > $file1 375 | sort $2 > $file2 376 | 377 | echo # Open $file1 and $file2 for reading. Use file descriptors 3 and 4. 378 | exec 3<$file1 379 | exec 4<$file2 380 | 381 | echo #Read the first line from each file to figure out how to start. 382 | read Line1 <&3 383 | status1=$? 384 | read Line2 <&4 385 | status2=$? 386 | 387 | echo #Strategy: while there is still input left in both files: 388 | echo #Output the line that should come first. 389 | echo #Read a new line from the file that line came from. 390 | while [ $status1 -eq 0 -a $status2 -eq 0 ] 391 | do 392 | if [[ "$Line2" > "$Line1" ]]; then 393 | echo -e "1.\t$Line1" 394 | read -u3 Line1 395 | status1=$? 396 | else 397 | echo -e "2.\t$Line2" 398 | read -u4 Line2 399 | status2=$? 400 | fi 401 | done 402 | 403 | echo #Now one of the files is at end-of-file. 404 | echo #Read from each file until the end. 405 | echo #First file1:' 406 | while [ $status1 -eq 0 ] 407 | do 408 | echo -e "1.\t$Line1" 409 | read Line1 <&3 410 | status1=$? 411 | done 412 | 413 | echo #Next file2: 414 | while [[ $status2 -eq 0 ]] 415 | do 416 | echo -e "2.\t$Line2" 417 | read Line2 <&4 418 | status2=$? 419 | done 420 | 421 | echo #Close and remove both input files 422 | exec 3<&- 4<&- 423 | rm -f $file1 $file2 424 | exit 0 425 | ``` 426 | 427 | 428 | # 5. 参考 References 429 | 430 | - Shell Tutorial 431 | - [Gnu Bash Reference](http://www.gnu.org/software/bash/manual/bashref.html) 432 | - [The-art-of-command-line](https://github.com/jlevy/the-art-of-command-line) 433 | - [The Bash Hackers Wiki](http://wiki.bash-hackers.org/start) 434 | - [Linux Shell Scripting Tutorial (LSST) v2.0](https://bash.cyberciti.biz/guide/Main_Page) 435 | - [Pure Bash Bible](https://github.com/dylanaraps/pure-bash-bible): A collection of pure bash alternatives to external processes 436 | - [Shell & Utilities: Detailed Toc](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/contents.html) 437 | - [Advanced Bash-Scripting Guide](https://tldp.org/LDP/abs/html/) 438 | - 其它地址: [Advanced Bash-Scripting Guide](https://linux.die.net/abs-guide/index.html) 439 | html) 440 | - Collection of bash scripts 441 | - [Bash-Oneliner](https://github.com/onceupon/Bash-Oneliner) 442 | - [Bash-Snippets](https://github.com/alexanderepstein/Bash-Snippets) 443 | - Tools 444 | - [Explain Shell](http://explainshell.com/) 445 | - [ShellCheck](https://www.shellcheck.net/) 446 | - Libraries 447 | - [shunit2](https://github.com/kward/shunit2) 448 | - [shflags](https://github.com/kward/shflags) 449 | - [log4sh](https://github.com/kward/log4sh) 450 | - [bats](https://github.com/sstephenson/bats) 451 | - IBM DeveloperWorks 452 | - [Bash parameters and parameter expansions](https://developer.ibm.com/tutorials/l-bash-parameters/) 453 | - [Bash test and comparison functions](https://developer.ibm.com/tutorials/l-bash-test/) 454 | - [Controlling the duration of scheduled jobs](https://www.ibm.com/developerworks/linux/library/l-job-terminating/) 455 | - [Creating a pixel ruler from the command line](https://www.ibm.com/developerworks/library/l-pixelruler/index.html) 456 | - [Finding rootfs during boot](https://developer.ibm.com/tutorials/l-boot-rootfs/) 457 | - [Job scheduling with cron and at](https://www.ibm.com/developerworks/library/l-job-scheduling/index) 458 | - Other 459 | - [Awesome Shell](https://github.com/alebcay/awesome-shell) 460 | -------------------------------------------------------------------------------- /linux&unix/tmux-learning-notes.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EthanCai/linux-system-ops/0bcfd206908ff3293a17c782ddb8a3aac1f23752/linux&unix/tmux-learning-notes.md -------------------------------------------------------------------------------- /linux&unix/ubuntu-linux-study-guideline.md: -------------------------------------------------------------------------------- 1 | - [1. Preface](#1-preface) 2 | - [2. Glossary](#2-glossary) 3 | - [3. Install Ubuntu Linux](#3-install-ubuntu-linux) 4 | - [3.1. 目标](#31-目标) 5 | - [3.2. 内容](#32-内容) 6 | - [3.3. Shell基本命令](#33-shell基本命令) 7 | - [3.3.1. df](#331-df) 8 | - [3.3.2. du](#332-du) 9 | - [3.4. 练习](#34-练习) 10 | - [4. Basic Shell Knowledge](#4-basic-shell-knowledge) 11 | - [4.1. 目标](#41-目标) 12 | - [4.2. 内容](#42-内容) 13 | - [4.3. Shell基本命令](#43-shell基本命令) 14 | - [4.3.1. Display system manual: man](#431-display-system-manual-man) 15 | - [4.3.2. Search the whatis database for stringss: apropos](#432-search-the-whatis-database-for-stringss-apropos) 16 | - [4.3.3. A menu-based hypetext system: info, pinfo](#433-a-menu-based-hypetext-system-info-pinfo) 17 | - [4.3.4. 账号间的切换、提权至root](#434-账号间的切换提权至root) 18 | - [4.3.5. Base Utilites: ls, cat, rm, less, more](#435-base-utilites-ls-cat-rm-less-more) 19 | - [4.3.6. Working with files: cp, mv, head, tail, sort, uniq, diff, file](#436-working-with-files-cp-mv-head-tail-sort-uniq-diff-file) 20 | - [4.3.7. Find something: find, mlocate, locate, which, grep](#437-find-something-find-mlocate-locate-which-grep) 21 | - [4.3.8. Manipulate text: awk, sed, ack](#438-manipulate-text-awk-sed-ack) 22 | - [4.3.9. More commands: echo, date](#439-more-commands-echo-date) 23 | - [5. Install and Manage Packages](#5-install-and-manage-packages) 24 | - [5.1. 目标](#51-目标) 25 | - [5.2. 内容](#52-内容) 26 | - [5.3. Shell命令](#53-shell命令) 27 | - [5.3.1. Debian package management system: dpkg](#531-debian-package-management-system-dpkg) 28 | - [5.3.2. Advanced Package Tool: apt](#532-advanced-package-tool-apt) 29 | - [5.3.3. aptitude](#533-aptitude) 30 | - [5.3.4. git](#534-git) 31 | - [5.3.5. wget](#535-wget) 32 | - [5.4. 练习](#54-练习) 33 | - [5.4.1. 如何升级系统,安装最新的补丁和最新版本的软件](#541-如何升级系统安装最新的补丁和最新版本的软件) 34 | - [5.4.2. 修改Ubuntu Software Repository的下载地址](#542-修改ubuntu-software-repository的下载地址) 35 | - [5.4.3. 查找软件包](#543-查找软件包) 36 | - [5.4.4. 下载软件包](#544-下载软件包) 37 | - [5.4.5. 安装软件包](#545-安装软件包) 38 | - [5.4.6. 更新源](#546-更新源) 39 | - [5.4.7. 更新已经安装的软件包](#547-更新已经安装的软件包) 40 | - [5.4.8. 移除软件包](#548-移除软件包) 41 | - [5.4.9. 自动移除软件包](#549-自动移除软件包) 42 | - [5.4.10. 清除下载的软件包](#5410-清除下载的软件包) 43 | - [6. SSH - Secure Shell](#6-ssh---secure-shell) 44 | - [6.1. 目标](#61-目标) 45 | - [6.2. 内容](#62-内容) 46 | - [6.3. Shell基本命令](#63-shell基本命令) 47 | - [6.3.1. SSH](#631-ssh) 48 | - [6.3.2. 本地和远程操作系统之间拷贝文件: `scp`, `sftp`, `sshfs`, `rsync`](#632-本地和远程操作系统之间拷贝文件-scp-sftp-sshfs-rsync) 49 | - [6.3.3. Record a shell session: `script`](#633-record-a-shell-session-script) 50 | - [6.3.4. Convert linux and macos files to windows format: `todos`, `fromdos`](#634-convert-linux-and-macos-files-to-windows-format-todos-fromdos) 51 | - [6.4. 练习](#64-练习) 52 | - [7. Vim Usage](#7-vim-usage) 53 | - [7.1. 目标](#71-目标) 54 | - [7.2. 内容](#72-内容) 55 | - [8. Advanced Vim Usage](#8-advanced-vim-usage) 56 | - [8.1. 目标](#81-目标) 57 | - [8.2. 内容](#82-内容) 58 | - [9. File, Directory, User, User Group, Authority](#9-file-directory-user-user-group-authority) 59 | - [9.1. 目标](#91-目标) 60 | - [9.2. 内容](#92-内容) 61 | - [10. Compress and Uncompress Files](#10-compress-and-uncompress-files) 62 | - [10.1. 目标](#101-目标) 63 | - [10.2. 内容](#102-内容) 64 | - [10.3. 练习](#103-练习) 65 | - [10.3.1. `bzip2`, `bunzip2`, `bzcat`命令练习](#1031-bzip2-bunzip2-bzcat命令练习) 66 | - [10.3.2. `tar`命令练习](#1032-tar命令练习) 67 | - [11. Process](#11-process) 68 | - [11.1. 目标](#111-目标) 69 | - [11.2. 内容](#112-内容) 70 | - [11.3. Shell基本命令](#113-shell基本命令) 71 | - [12. Basic Network Management](#12-basic-network-management) 72 | - [12.1. 目标](#121-目标) 73 | - [12.2. 内容](#122-内容) 74 | - [12.3. Shell命令](#123-shell命令) 75 | - [12.4. 练习](#124-练习) 76 | - [12.4.1. 修改OS的hostname](#1241-修改os的hostname) 77 | - [12.4.2. 设置DNS服务的服务地址](#1242-设置dns服务的服务地址) 78 | - [12.4.3. 如何配置网卡和IP地址](#1243-如何配置网卡和ip地址) 79 | - [12.4.4. 从Internet更新ubuntu本地的时间](#1244-从internet更新ubuntu本地的时间) 80 | - [12.5. 切换网络后,强制更新网卡IP](#125-切换网络后强制更新网卡ip) 81 | - [13. Writing Shell Scripts](#13-writing-shell-scripts) 82 | - [13.1. 目标](#131-目标) 83 | - [13.2. 基本概念](#132-基本概念) 84 | - [13.2.1. 交互式shell和非交互式shell、登录shell和非登录shell的区别](#1321-交互式shell和非交互式shell登录shell和非登录shell的区别) 85 | - [13.2.2. 语法](#1322-语法) 86 | - [13.3. Shell命令](#133-shell命令) 87 | - [13.4. 练习](#134-练习) 88 | - [13.4.1. 如何让你的shell脚本更健壮和更可靠](#1341-如何让你的shell脚本更健壮和更可靠) 89 | - [14. Schedule Tasks](#14-schedule-tasks) 90 | - [14.1. 目标](#141-目标) 91 | - [14.2. 内容](#142-内容) 92 | - [14.2.1. 参考](#1421-参考) 93 | - [14.2.2. cron的坑](#1422-cron的坑) 94 | - [14.2.3. cron和anacron的区别](#1423-cron和anacron的区别) 95 | - [14.2.4. Crontab文件](#1424-crontab文件) 96 | - [14.2.4.1. 系统crontab文件](#14241-系统crontab文件) 97 | - [14.2.4.2. 用户crontab文件](#14242-用户crontab文件) 98 | - [14.2.5. anacron配置文件](#1425-anacron配置文件) 99 | - [15. FAQ](#15-faq) 100 | - [15.1. 如何安装中文语言支持及中文输入法](#151-如何安装中文语言支持及中文输入法) 101 | - [15.2. 如何给Ubuntu Linux Virutal Machine安装VMWare Tools](#152-如何给ubuntu-linux-virutal-machine安装vmware-tools) 102 | - [15.3. 如何给Ubuntu Linux Virtual Machine安装VirtualBox Additions](#153-如何给ubuntu-linux-virtual-machine安装virtualbox-additions) 103 | - [15.4. 如何给Ubuntu Linux Virtual Machine安装Parallel Tools](#154-如何给ubuntu-linux-virtual-machine安装parallel-tools) 104 | - [15.5. 使用命令`man wget > man-wget.txt`把命令文档输入到文本文件后,打开man-wget.txt,发现有很多重复字符,或者乱码?](#155-使用命令man-wget--man-wgettxt把命令文档输入到文本文件后打开man-wgettxt发现有很多重复字符或者乱码) 105 | 106 | 107 | # 1. Preface 108 | 109 | 面向开发的Ubuntu Linux快速学习手册,掌握基本Ubuntu Linux操作和管理 110 | 111 | # 2. Glossary 112 | 113 | - **PG2UL**: 代表Pratical Guide to Ubuntu Linux, 3rd 114 | 115 | 116 | # 3. Install Ubuntu Linux 117 | 118 | ## 3.1. 目标 119 | 120 | - 了解Ubuntu各版本的区别 121 | - 安装Ubuntu Desktop 12.04和Ubuntu Server 12.04 122 | - 熟悉常见目录的用途 123 | - 了解mount point的概念 124 | - 熟悉primary partition、extended partition、logical partition的概念 125 | 126 | ## 3.2. 内容 127 | 128 | - Ubuntu各个release版本的区别,参考下面几篇文章: 129 | - [List of Ubuntu releases](https://en.wiki2.org/wiki/List_of_Ubuntu_releases) 130 | - [Ubuntu Release](https://wiki.ubuntu.com/Releases) 131 | - [Download Link of Ubuntu Releases](http://releases.ubuntu.com/) 132 | - Ubuntu每个release的不同edition的区别(参考PG2UL, page 32) 133 | - **DVD**: The DVD is a live/install DVD. The DVD includes all software packages supported by Ubuntu, not just those installed by default. 134 | - **Desktop CD**: The Desktop CD is a live/install CD 135 | - **Alternate CD**: The Alternate Install CD is not a live CD; it is intended for special installations only. It presents more advanced installation options than the Desktop CD does. This CD is available for PC and 64-bit PC architectures, uses the textual installer, and installs an Ubuntu system that displays either a graphical or a textual interface. 136 | - **Server CD**: The Server CD is not a live CD; it is intended for installation only. 137 | - **Minimal CD**: Not an official edition, the Minimal CD is small (5–20 megabytes) and provides a quick installation. 138 | - Linux下的各种文件系统的区别 139 | - [Ext2、Ext3和Ext4之间的区别](http://misujun.blog.51cto.com/2595192/883949) 140 | - Linux目录层级结构,及常见目录(参考PG2UL, page 39) 141 | ```bash 142 | rwxr-xr-x 2 root root 4096 Jul 28 11:46 bin/ 143 | drwxr-xr-x 3 root root 4096 Jul 28 10:28 boot/ 144 | drwxr-xr-x 17 root root 4240 Jul 28 11:48 dev/ 145 | drwxr-xr-x 90 root root 4096 Jul 28 18:25 etc/ 146 | drwxr-xr-x 3 root root 4096 May 10 02:02 home/ 147 | drwxr-xr-x 21 root root 4096 May 10 02:01 lib/ 148 | drwxr-xr-x 2 root root 4096 Jul 8 01:10 lib64/ 149 | drwx------ 2 root root 16384 May 10 01:56 lost+found/ 150 | drwxr-xr-x 4 root root 4096 May 10 01:56 media/ 151 | drwxr-xr-x 2 root root 4096 Apr 11 2014 mnt/ 152 | drwxr-xr-x 2 root root 4096 Feb 19 03:33 opt/ 153 | dr-xr-xr-x 407 root root 0 Jul 28 11:48 proc/ 154 | drwx------ 2 root root 4096 May 10 01:56 root/ 155 | drwxr-xr-x 18 root root 680 Jul 28 18:26 run/ 156 | drwxr-xr-x 2 root root 12288 Jul 28 11:46 sbin/ 157 | drwxr-xr-x 2 root root 4096 Feb 19 03:33 srv/ 158 | dr-xr-xr-x 13 root root 0 Jul 28 17:24 sys/ 159 | drwxrwxrwt 2 root root 4096 Jul 28 19:17 tmp/ 160 | drwxr-xr-x 10 root root 4096 May 10 01:56 usr/ 161 | drwxr-xr-x 12 root root 4096 May 10 02:01 var/ 162 | ``` 163 | - Mount Points(参考PG2UL, page 35) 164 | - The directory that you mount a filesystem on is called a mount point. 165 | - 通过`mount`命令查看分区 166 | - `/etc/fstab`: The file that holds the information relating partitions to mount points 167 | - Primary, extended and logical partitions(参考PG2UL, page 34,把这三个概念讲的很清楚) 168 | - 一个Disk最多有4个Primary partitions 169 | - 只能把4个Primary partitions中的一个划分为多个logical partitions,这个被划分的primary partition就叫extended partition 170 | - 示意图 ![](./img/2015/06/primary-extended-logical-partition.png) 171 | - LVM: Logical Volume Manager 172 | - 阅读[浅谈Linux磁盘存储管理续](http://ixdba.blog.51cto.com/2895551/562111/) 173 | - 阅读[LVM (简体中文) - ArchLinux Wiki](https://wiki.archlinux.org/index.php/LVM_%28%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87%29) 174 | - 阅读[RAID](https://wiki.archlinux.org/index.php/RAID) 175 | - 阅读[Software RAID and LVM](https://wiki.archlinux.org/index.php/Software_RAID_and_LVM) 176 | 177 | ## 3.3. Shell基本命令 178 | 179 | ### 3.3.1. df 180 | 181 | `df`: 检查linux服务器的文件系统的磁盘空间占用情况,可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息。 182 | 183 | - 参考 [每天一个linux命令(33):df 命令](http://www.cnblogs.com/peida/archive/2012/12/07/2806483.html) 184 | 185 | ### 3.3.2. du 186 | 187 | `du`: 也是查看使用空间的,但是与`df`命令不同的是`du`命令是对文件和目录磁盘使用的空间的查看。 188 | 189 | - 参考 [每天一个linux命令(34):du 命令](http://www.cnblogs.com/peida/archive/2012/12/10/2810755.html) 190 | 191 | ## 3.4. 练习 192 | 193 | - 手动安装Ubuntu Desktop 14.04 194 | - 手动安装Ubuntu Server 14.04 195 | - 自动化安装Ubuntu Linux 196 | - [PXE - Preboot eXecution Environment](https://en.wiki2.org/wiki/Preboot_Execution_Environment) 197 | - [Cobbler](https://cobbler.github.io/) 198 | - [Cobbler Quickstart Guide](https://cobbler.github.io/manuals/quickstart/) 199 | - [运维自动化之Cobbler系统安装详解](http://os.51cto.com/art/201109/288604_all.htm) 200 | - [使用 Cobbler 自动化和管理系统安装](http://www.ibm.com/developerworks/cn/linux/l-cobbler/index.html) 201 | - 查看Ubuntu的版本和Linux内核版本 202 | - `cat /etc/issue` 203 | - `sudo lsb_release -a` 204 | - `uname -r` 205 | - 执行结果见下图:![](./img/2015/06/view-ubuntu-version-and-kernel-version.png) 206 | 207 | 208 | 209 | # 4. Basic Shell Knowledge 210 | 211 | ## 4.1. 目标 212 | 213 | - 掌握Shell基本概念 214 | - 掌握基本的Shell命令 215 | 216 | ## 4.2. 内容 217 | 218 | - 基础概念 219 | - [重定向](http://www.php100.com/html/webkaifa/Linux/2010/0430/6470.html): the various ways you can cause the shell to alter where standard input of a command comes from and where standard output goes to. 220 | - 理解符号 `<`, `>`, `>>` 221 | - [管道](http://wenku.baidu.com/view/5a7aeff4f61fb7360b4c65ba.html): The shell uses a pipe to connect standard output of one command to standard input of another command. 222 | - 理解符号 `|` 223 | - 理解filter: A filter is a command that processes an input stream of data to produce an output stream of data. 比如`sort`、`tee`。 224 | - [Linux命令之tee - 重定向输出到多个文件](http://codingstandards.iteye.com/blog/833695) 225 | - [linux sort 命令详解](http://www.cnblogs.com/51linux/archive/2012/05/23/2515299.html) 226 | - 通配符`?`, `*`, `[]` 227 | - `ls memo?` 228 | - `ls t*` 229 | - `lpr part[01235]`, `lpr part[0-35]`, `ls *[^ab]` 230 | - 推荐的Shell 231 | - 一般Linux发行版默认的shell是bash,但这里推荐Linux推荐安装zsh + [oh-my-zsh](http://ohmyz.sh/),理由如下: 232 | - zsh vs bash 233 | - [Zsh和Bash,究竟有何不同](https://www.soimort.org/posts/163/) 234 | - [Zsh shell-for-humans](http://www.slideshare.net/juandebravo/zsh-shellforhumans-27933808?related=2) 235 | - [Why zsh is Cooler than Your Shel](http://www.slideshare.net/brendon_jag/why-zsh-is-cooler-than-your-shell?related=1) 236 | - 安装oh-my-zsh 237 | - 先确认os中是否安装了zsh,如果没有安装,先安装zsh, `sudo apt-get install zsh` 238 | - 按照[http://ohmyz.sh/](http://ohmyz.sh/)的方法安装oh-my-zsh 239 | - 如果安装完成后,默认的shell不是zsh,按照如下操作: 240 | - 执行`sudo chsh -s /bin/zsh` 241 | - 重启系统,打开terminal,oh-my-zsh就生效了 242 | - Windows下安装 243 | - [Xshell](http://www.netsarang.com/products/xsh_overview.html) 244 | - 或 SecureCRT 245 | - 或 Putty 246 | - MacOS下安装 247 | - [oh-my-zsh](http://ohmyz.sh/) 248 | - [iTerm2](https://www.iterm2.com/index.html) 249 | - [Tmux](http://tmux.sourceforge.net/) 250 | - [TMUX Manual](http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man1/tmux.1?query=tmux&sec=1) 251 | - 在后台进程管理 252 | - `ls -l | lpr &` 253 | - Control-Z: You can suspend a foreground job (stop it from running) by pressing the suspend key, usually CONTROL-Z. The shell then stops the process and disconnects standard input from the keyboard. You can put a suspended job in the background and restart it by using the `bg` command followed by the job number. You do not need to specify the job number when there is only one stopped job. 254 | - `jobs`: view background jobs 255 | - `fg`: connect the key-board to a program running in the background, bring it to the fore- ground. 256 | - `kill`: kill process like `kill 18228`, kill background job like `kill %1` 257 | - 参考[Linux后台进程管理](http://blog.csdn.net/fengyifei11228/article/details/5737371) 258 | 259 | ## 4.3. Shell基本命令 260 | 261 | ### 4.3.1. Display system manual: man 262 | 263 | ### 4.3.2. Search the whatis database for stringss: apropos 264 | 265 | ### 4.3.3. A menu-based hypetext system: info, pinfo 266 | 267 | ### 4.3.4. 账号间的切换、提权至root 268 | 269 | - sudo: 用户身份提权 270 | - su: 切换用户身份 271 | 272 | 参考: 273 | - [Linux 下以其他用户身份运行程序—— su、sudo、runuser](https://www.cnblogs.com/bodhitree/p/6018369.html) 274 | 275 | ### 4.3.5. Base Utilites: ls, cat, rm, less, more 276 | 277 | - `ls`: list the names of files 278 | - `cat`: display a text files 279 | - `rm`: delete a files 280 | - `less`, `more`: display a text file one screen at a time 281 | 282 | ### 4.3.6. Working with files: cp, mv, head, tail, sort, uniq, diff, file 283 | 284 | - `cp`: copy file 285 | - `mv`: move file, change the name of file 286 | - `head`: diplay the beginning of a file 287 | - `tail`: display the end of a file,参考[tail命令](http://www.cnblogs.com/peida/archive/2012/11/07/2758084.html) 288 | - `sort`: sort lines of text,参考[sort命令](http://roclinux.cn/?p=1350) 289 | - `uniq`: remove duplicate lines from a file,参考[uniq命令](http://www.linuxso.com/command/uniq.html) 290 | - `diff`: compare two files,参考[diff命令](http://www.cnblogs.com/peida/archive/2012/12/12/2814048.html) 291 | - `file`: determine file type 292 | 293 | ### 4.3.7. Find something: find, mlocate, locate, which, grep 294 | 295 | - `find`: walk a file hierarchy, [每天一个linux命令(19):find 命令概览](http://www.cnblogs.com/peida/archive/2012/11/13/2767374.html) 296 | - find filenames quickly 297 | - `mlocate`: ubuntu, centos下使用此命令,使用前需要执行`updatedb`命令创建`/var/lib/mlocate/mlocate.db`索引文件 298 | - `locate`: MacOS使用此命令,使用前需要执行`sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist`创建`/var/db/locate.database`索引文件 299 | - `which`, `whereis`: locate a utility 300 | - `grep`: [每天一个linux命令(39):grep 命令](http://www.cnblogs.com/peida/archive/2012/12/17/2821195.html) 301 | 302 | ### 4.3.8. Manipulate text: awk, sed, ack 303 | 304 | - `awk`: awk是一个强大的文本分析工具,相对于grep的查找,sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大。 305 | - [linux awk命令详解](http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858470.html) 306 | - [simple awk tutorial](http://www.hcs.harvard.edu/~dholland/computers/awk.html) 307 | - `sed`: edit text 308 | - [linux中sed的用法](http://www.cnblogs.com/emanlee/archive/2013/09/07/3307642.html) 309 | - `ack`: a tool like grep, optimized for programmers 310 | - [Offical website](http://beyondgrep.com/) 311 | 312 | ### 4.3.9. More commands: echo, date 313 | 314 | - `echo`: display text 315 | - `date`: display the time and date,参考[date命令](http://www.cnblogs.com/peida/archive/2012/12/12/2814048.html) 316 | 317 | 318 | 319 | # 5. Install and Manage Packages 320 | 321 | ## 5.1. 目标 322 | 323 | - 安装和管理包 324 | - 掌握`dpkg`, `apt`, `aptitude`命令 325 | 326 | ## 5.2. 内容 327 | 328 | - Repository: Repositories hold collections of software packages and related information, including headers that describe each package and provide information on other packages the package depends on. Ubuntu maintains repositories for each of its releases. 329 | - main: Ubuntu-supported open-source software 330 | - universe: Community-maintained open-source software 331 | - multiverse: Software restricted by copyright or legal issues 332 | - restricted: Proprietary device drivers 333 | - partner: Packages that are not part of Ubuntu; offered by other vendors 334 | - backports: Packages from later releases of Ubuntu that are not available for an earlier release 335 | - `/etc/apt/sources.list`: specifies the repositories APT searches when you ask it to find or install a package. 336 | - 通过命名修改repository地址为中国访问更快的"mirrors.yun-idc.com": `sudo sed -i 's/archive.ubuntu.com/mirrors.yun-idc.com/g' /etc/apt/sources.list` 337 | - APT local package indexes is in `/var/lib/apt/lists` directory. APT uses these files to determine whether the packages on the system, and those in its cache, are the most recent versions. 338 | - `/var/cache/apt/archives` directory holds recently downloaded deb files 339 | - The aptitude utility keeps very readable logs in `/var/log/aptitude` 340 | - 参考内容 341 | - [包管理系统指南](http://wiki.ubuntu.org.cn/包管理系统指南) 342 | - [Ubuntu服务器管理指南 - 包管理](https://help.ubuntu.com/lts/serverguide/package-management.html) 343 | - PG2UL, page 517, chapter 13 - downloading and installing software 344 | 345 | ## 5.3. Shell命令 346 | 347 | ### 5.3.1. Debian package management system: dpkg 348 | 349 | dpkg主要是对本地的软件包进行管理,本地软件包包括已经在本地安装的软件包和已经下载但还没有安装的 deb 文件,不解决依赖关系。 350 | 351 | ### 5.3.2. Advanced Package Tool: apt 352 | 353 | - apt和dpkg的用途比较:APT downloads software packages, while dpkg installs, removes, maintains, manages dependencies of, and reports on software packages. 354 | - apt的命令包含 355 | - `apt-get`: 主要负责软件包的在线安装与升级,低层对 deb 包的处理还是用的 dpkg,解决依赖关系 356 | - `apt-cache`: 主要用来查询软件包的状态和依赖关系 357 | - `apt-file`: 主要负责查询软件包名称和软件包包含的文件(值得注意的是它要自己同步) 358 | 359 | ### 5.3.3. aptitude 360 | 361 | - Ubuntu desktop 14.04中,并没有默认安装aptitude,需要执行`sudo apt-get install aptitude`来安装 362 | - `aptitude install`: install package and its dependencies 363 | - `aptitude remove`: remove package and its dependencies, but not include configuration 364 | - `aptitude purge`: remove package and its dependencies, configuration 365 | - `aptitude search`: looks for packages with names that match a pattern 366 | - `aptitude clean`: Deletes all packages from the APT cache 367 | 368 | 参考: 369 | - [Aptitude](https://help.ubuntu.com/lts/serverguide/aptitude.html) 370 | 371 | ### 5.3.4. git 372 | 373 | - 阅读 374 | - [Pro Git (En)](https://git-scm.com/book/en/v2) 375 | - [Pro Git中文版](http://iissnan.com/progit/) 376 | 377 | ### 5.3.5. wget 378 | 379 | - 在线html文档,访问[wget html document](http://www.gnu.org/software/wget/manual/wget.html) 380 | 381 | ## 5.4. 练习 382 | 383 | ### 5.4.1. 如何升级系统,安装最新的补丁和最新版本的软件 384 | 385 | GUI操作 386 | 387 | 1. System Settings -> Softwares&Updates -> Select best download server,选择最佳的软件更新服务器 388 | 1. 然后按Alt+F2组合键调出运行命令框,然后键入`update-manager -d`,然后升级系统 389 | 390 | 终端操作 391 | 392 | 1. `sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autoclean` 393 | 2. `sudo apt-get update && sudo aptitude full-upgrade && sudo apt-get autoclean` 394 | 395 | ### 5.4.2. 修改Ubuntu Software Repository的下载地址 396 | 397 | 参考: 398 | 399 | 1. GUI操作参考[Linux开发环境搭建与使用——ubuntu更新设置](http://blog.csdn.net/tennysonsky/article/details/44221433) 400 | 1. Bash操作参考:[Repositories/CommandLine](https://help.ubuntu.com/community/Repositories/CommandLine) 401 | 402 | Ubuntu uses apt for package management. Apt stores a list of repositories or software channels in the file 403 | 404 | ```bash 405 | /etc/apt/sources.list 406 | ``` 407 | 408 | and in any file with the suffix .list under the directory 409 | 410 | ```bash 411 | /etc/apt/sources.list.d/ 412 | ``` 413 | 414 | See `man sources.list` for more about this storage mechanism. 415 | 416 | By editing these files from the command line, we can add, remove, or temporarily disable software repositories. 417 | 418 | 将`sources.list`中默认下载地址改为从阿里云下载地址: 419 | 420 | ```bash 421 | $ sudo sed -i 's/http\:\/\/archive\.ubuntu\.com/http\:\/\/mirrors\.yun-idc\.com/g' /etc/apt/sources.list 422 | 423 | $ sudo sed -i 's/http\:\/\/us\.archive\.ubuntu\.com/http\:\/\/mirrors\.yun-idc\.com/g' /etc/apt/sources.list 424 | 425 | $ sudo sed -i 's/http\:\/\/cn\.archive\.ubuntu\.com/http\:\/\/mirrors\.yun-idc\.com/g' /etc/apt/sources.list 426 | ``` 427 | 428 | ### 5.4.3. 查找软件包 429 | 430 | `aptitude search`命令的查找结果一般如下: 431 | 432 | ```bash 433 | ➜ ~ aptitude search '~ivim' 434 | i vim - Vi IMproved - enhanced vi editor 435 | i vim-common - Vi IMproved - Common files 436 | i A vim-runtime - Vi IMproved - Runtime files 437 | i vim-tiny - Vi IMproved - enhanced vi editor - compact version 438 | ``` 439 | 440 | The letter in the first column of each entry indicates the status of the package on the system: 441 | - `i` for installed 442 | - `c` for removed except for configuration files 443 | - `p` for purged (package and configuration files removed) 444 | - `v` for a **virtual package** (When you install certain packages, aptitude queries you and, if you agree, installs more than one package. You are either installing a package with dependencies or a virtual package, also called a metapackage. A **virtual package** is not a software package, but rather a metapackage that depends on other packages. Virtual pack- ages facilitate the installation of software that requires multiple packages.) 445 | 446 | A second letter in the first column indicates a stored action that will be performed on the package. 447 | An `A` appearing as the third letter means the package was automatically installed. 448 | 449 | 450 | ```bash 451 | dpkg --get-selections pattern #查找软件包名称包含 pattern 的软件包,可以在后面用 grep install/deinstall 来选择是否已经被 remove 的包(曾经安装过了的) 452 | apt-cache search pattern #查找软件包名称和描述包含 pattern 的软件包 (可以是安装了也可以是没有安装),可以用参数来限制是否已经安装 453 | aptitude search '~ipattern' #查找已经安装的软件包 454 | aptitude search '~cpattern' #查找已经被 remove 的软件包,还有配置文件存在 455 | aptitude search '~npattern' #查找软件包名称包含 pattern 的软件包 (可以是安装了也可以是没有安装) 456 | aptitude search '!~i~npattern' #查找还没有安装的软件包名字包含 pattern 的软件包。(前面的 ! 是取反的意思,反划线是 escape 符号) 457 | 注:还有很多用法,可以去看看我在 forum 中写的帖子 [aptitude Search Patterns](http://forum.ubuntu.org.cn/viewtopic.php?f=52&t=259550) 458 | 459 | apt-cache depends package #查找名称是 package 软件包的依赖关系 460 | aptitude search '~R~npackage' #查找名称是 package 软件包的依赖关系,可以同时看到是不是已经安装 461 | 462 | apt-cache rdepends package #查找哪些软件包依赖于名称是 package 软件包 463 | aptitude search '~D~npackage' #查找哪些软件包依赖于名称是 package 软件包 464 | 465 | dpkg -I package_name.deb #参数是大写i,查找已经下载但末安装的 package_name.deb 软件包的信息 466 | dpkg -l package #参数是小写L,查找已经安装软件包 package 的信息,精简 467 | apt-cache show pattern ##查找软件包pattern的信息 (可以是安装了也可以是没有安装) 468 | aptitude show ~npattern #显示名称是 pattern 软件包的信息(可以是安装了也可以是没有安装) 469 | 470 | apt-cache policy pattern #显示 pattern 软件包的策略(可以是安装了也可以是没有安装) 471 | apt-cache showpkg pattern #显示pattern 软件包的其它信息(可以是安装了也可以是没有安装) 472 | 473 | dpkg -S pattern #查找已经安装的文件 pattern 属于哪个软件包 474 | apt-file search pattern #查找文件 pattern 属于哪个软件包(可以是安装了也可以是没有安装) 475 | 476 | dpkg -c package_name.deb #查找已经下载但末安装的 package.deb 软件包包含哪些文件 477 | dpkg -L package #查找已经安装 package 软件包包含哪些文件 478 | apt-file show pattern #查找 pattern 软件包(可以是安装了也可以是没有安装)包含哪些文件 479 | ``` 480 | 481 | ### 5.4.4. 下载软件包 482 | 483 | ```bash 484 | apt-get install package -d #下载软件包 485 | aptitude download pattern #同上,不同的是下载的是符合 pattern 的软件包,后面不再指出 486 | ``` 487 | 488 | ### 5.4.5. 安装软件包 489 | 490 | ```bash 491 | dpkg -i package_name.deb #安装本地软件包,不解决依赖关系 492 | apt-get install package #在线安装软件包 493 | aptitude install pattern #同上 494 | 495 | apt-get install package --reinstall #重新安装软件包 496 | apitude reinstall package #同上 497 | ``` 498 | 499 | ### 5.4.6. 更新源 500 | 501 | ```bash 502 | apt-get update #更新源 503 | aptitude update #同上 504 | ``` 505 | 506 | ### 5.4.7. 更新已经安装的软件包 507 | 508 | ```bash 509 | apt-get upgrade #更新已经安装的软件包 510 | aptitude safe-upgrade #同上 511 | ``` 512 | 513 | ### 5.4.8. 移除软件包 514 | 515 | ```bash 516 | dpkg -r package #删除软件包 517 | apt-get remove package #同上 518 | aptitude remove package #同上 519 | 520 | dpkg -P #删除软件包及配置文件 521 | apt-get remove package --purge #删除软件包及配置文件 522 | apitude purge pattern #同上 523 | ``` 524 | 525 | ### 5.4.9. 自动移除软件包 526 | 527 | ```bash 528 | apt-get autoremove #删除不再需要的软件包。aptitude 没有,它会自动解决这件事 529 | ``` 530 | 531 | ### 5.4.10. 清除下载的软件包 532 | 533 | ```bash 534 | apt-get clean #清除 /var/cache/apt/archives 目录 535 | aptitude clean #同上 536 | 537 | apt-get autoclean #清除 /var/cache/apt/archives 目录,不过只清理过时的包 538 | aptitude autoclean #同上 539 | ``` 540 | 541 | 542 | 543 | # 6. SSH - Secure Shell 544 | 545 | ## 6.1. 目标 546 | 547 | - 远程控制linux 548 | - Shell基本命令 549 | 550 | ## 6.2. 内容 551 | 552 | - 简介 553 | - OpenSSH is a freely available version of the Secure Shell (SSH) protocol family of tools for remotely controlling, or transferring files between, computers. Traditional tools used to accomplish these functions, such as `telnet` or `rcp`, are **insecure** and **transmit the user's password in cleartext when used**. OpenSSH provides a server daemon and client tools to facilitate **secure**, **encrypted** remote control and file transfer operations, effectively replacing the legacy tools. 554 | - OpenSSH服务器组组件`sshd`持续监听来自任何客户端工具的连接请求。当一个连接请求发生时,`sshd`根据客户端连接的类型来设置当前连接。例如,如果远程计算机是通过 ssh 客户端应用程序来连接的话,OpenSSH 服务器将在认证之后设置一个远程控制会话。如果一个远程用户通过 scp 来连接 OpenSSH 服务器,OpenSSH 服务器将在认证之后开始服务器和客户机之间的安全文件拷贝。OpenSSH 可以支持多种认证模式,包括纯密码、公钥以及Kerberos票据。 555 | - 参考 556 | - [SSH原理与运用(一)](http://www.ruanyifeng.com/blog/2011/12/ssh_remote_login.html) 557 | - [SSH原理与运用(二)](http://www.ruanyifeng.com/blog/2011/12/ssh_port_forwarding.html) 558 | - 安装 559 | - ubuntu默认并没有安装ssh服务,如果通过ssh链接ubuntu,需要自己手动安装ssh-server 560 | - 安装客户端: 561 | - `sudo apt-get install openssh-client` 562 | - 通过在bash中执行`ssh`验证客户端是否安装成功 563 | - 安装服务端: 564 | - `sudo apt-get install openssh-server` 565 | - 通过在bash中执行`ps -e | grep ssh`验证服务是否安装成功 566 | - 配置服务端 567 | - 配置文件保存在`/etc/ssh/sshd_config` 568 | - 查看手册通过`man sshd_config` 569 | - 配置完成后重启服务通过`sudo service ssh restart` 570 | - 参考 571 | - [OpenSSH-Server(Ubuntu Server Document)](https://help.ubuntu.com/lts/serverguide/openssh-server.html) 572 | - [Generate a new ssh key and adding it to ssh agent](https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/#platform-linux) 573 | - 终端与本地文件的传输,具体用法见 **Shell基本命令** 574 | - `scp` 575 | - `sftp` 576 | - `sshfs` 577 | - `rsync` 578 | - 了解Linux下的语言编码、文件编码、终端编码之间的关系 579 | - [Linux下查看文件编码,文件或文件名编码格式转换](http://blog.sina.com.cn/s/blog_6fe0d70d0101du41.html) 580 | - [Linux中文乱码解决办法](http://www.mutouxiaogui.cn/blog/?p=21) 581 | - [Linux终端中文显示乱码](http://skypegnu1.blog.51cto.com/8991766/1545449) 582 | - 参考: 583 | - [mac下SSH免密码登录远程服务器](http://cssor.com/mac-ssh-auto-login-server.html) 584 | - [让进程在断开SSH连接后依然保持运行](https://www.ibm.com/developerworks/cn/linux/l-cn-nohup/) 585 | - [Ubuntu Document - OpenSSH 服务器](https://help.ubuntu.com/lts/serverguide/openssh-server.html) 586 | 587 | ## 6.3. Shell基本命令 588 | 589 | ### 6.3.1. SSH 590 | 591 | - 参考 592 | - [25个必须记住的SSH命令](http://os.51cto.com/art/201011/235252.htm) 593 | 594 | ### 6.3.2. 本地和远程操作系统之间拷贝文件: `scp`, `sftp`, `sshfs`, `rsync` 595 | 596 | - 参考 597 | - [详解linux scp命令的应用](http://os.51cto.com/art/201003/187301.htm) 598 | - [how-to-copy-files-from-one-machine-to-another-using-ssh](http://unix.stackexchange.com/questions/106480/how-to-copy-files-from-one-machine-to-another-using-ssh) 599 | 600 | ### 6.3.3. Record a shell session: `script` 601 | 602 | ### 6.3.4. Convert linux and macos files to windows format: `todos`, `fromdos` 603 | 604 | ## 6.4. 练习 605 | 606 | - 安装SSH Server或者SSH Client 607 | - 在客户端操作系统上通过SSH连接Ubuntu Server 608 | - Mac OS X上使用Terminal 609 | - Windows上使用Putty、Xshell 610 | - Ubuntu上安装openssh-client 611 | - 通过scp向server传送文件 612 | - 通过scp从server获取文件 613 | 614 | 615 | 616 | # 7. Vim Usage 617 | 618 | ## 7.1. 目标 619 | 620 | - 掌握Vim基本操作 621 | 622 | ## 7.2. 内容 623 | 624 | - 阅读[vim基本操作](./vim-learning-notes.md) 625 | 626 | 627 | 628 | # 8. Advanced Vim Usage 629 | 630 | ## 8.1. 目标 631 | 632 | - 精通Vim操作 633 | 634 | ## 8.2. 内容 635 | 636 | - to add 637 | 638 | 639 | 640 | # 9. File, Directory, User, User Group, Authority 641 | 642 | ## 9.1. 目标 643 | 644 | - 文件、目录、用户、用户组、权限 645 | - Shell基本命令 646 | 647 | ## 9.2. 内容 648 | 649 | - Linux下的用户与组的关系、如何管理用户和组 650 | - [Linux用户和用户组管理](http://www.chinaunix.net/old_jh/4/438660.html) 651 | - [浅谈Linux用户权限管理之一(用户与组的概念)](http://ixdba.blog.51cto.com/2895551/531787/) 652 | - [浅谈Linux用户权限管理之二(用户管理工具)](http://ixdba.blog.51cto.com/2895551/531793) 653 | - [浅谈Linux用户权限管理之三(文件与权限的设定)](http://ixdba.blog.51cto.com/2895551/531799) 654 | - [Users and Groups](https://wiki.archlinux.org/index.php/Users_and_groups) 655 | - [Linux: Show The Groups a User Is In](http://www.cyberciti.biz/faq/linux-show-groups-for-user/) 656 | - 文件及目录的权限及含义,如何快速计算目录权限 657 | - `chmod`: change file modes or Access Control Lists 658 | - `chown`: change file owner or group 659 | - `ls -l`: display file permissions 660 | - `cd`: [每天一个linux命令(2):cd命令](http://www.cnblogs.com/peida/archive/2012/10/24/2736501.html) 661 | - 目录访问权限一些特殊的地方 662 | - Execute permission is redefined for a directory: It means that you can cd into the directory and/or examine files that you have permission to read from in the directory. It has nothing to do with executing a file. 663 | - 理解ACL 664 | - 系统自带的特殊目录及其作用 665 | - PG2UL, page 213 666 | - [Linux系统默认目录](http://blog.chinaunix.net/uid-30093414-id-4797285.html) 667 | - [Linux的学习--系统目录](http://www.cnblogs.com/CraryPrimitiveMan/p/4444037.html) 668 | - 理解硬链接(hard link)和符号链接(Symbolic link) 669 | - 文件类型与扩展名 670 | - [Linux文件类型与扩展名](http://www.cnblogs.com/peida/archive/2012/11/22/2781912.html) 671 | - PG2UL, page 501, Device Special Files 672 | - Obtaining user and system information 673 | - `who`: list users on the system 674 | - `finger`: list users on the system 675 | - `w`: list users on the system 676 | - `hostname`: display the system name 677 | 678 | # 10. Compress and Uncompress Files 679 | 680 | ## 10.1. 目标 681 | 682 | - 熟悉文件的压缩和解压 683 | 684 | ## 10.2. 内容 685 | 686 | 阅读PG2UL, page 174, Compressing and archiving files 687 | 688 | [rar tar gz zip 7z 有什么区别?](http://www.zhihu.com/question/26026741): 689 | 690 | > tar是Linux常见的一种归档文件(原生不包括压缩功能) 691 | > gzip是gnu/Linux的一种压缩文件工具,算法是基于 DEFLATE,文件是gz,可以和tar组合。 692 | > zip是一种规范开放的压缩文件,算法不定,但主要是用 DEFLATE 693 | > rar的算法专有,但发行时附送解码器允许解码器再开发,编码器专有 694 | > 7zip和zip差不多,算法不定,主要用bzip2和lzma,而且完全开源。 695 | > zip和7z更像是压缩容器,因为算法不是格式固定,允许支持其他压缩算法 696 | > The zip and unzip utilities are compatible with PKZIP, a Windows program that compresses and archives files. 697 | > 698 | > 大小与区别 699 | > tar是无压缩的,比压缩效率,gz的算法最原始,所以较低,其次zip,接着rar,7z两个主要算法基本上略优于rar,基本不相上下。 700 | > 701 | > 优缺点 702 | > 在Linux里面,tar一般和其他没有文件管理的压缩算法文件结合使用,用tar打包整个文件目录结构成一个文件,再用gz,bzip等压缩算法压缩成一次。也是Linux常见的压缩归档的处理方法。 703 | > 704 | > zip相对比较老,格式规范可知,所以积累了各种加解压实现,有较好的兼容性,不过现有文件格式相对而言比较落后,还有会有文件名乱码问题(因为文件名是用非Unicode编码) 705 | > rar和7z就新些,所用算法压缩效率也好很多,兼容性不及zip,不过rar的编码器有专利,但可以不制作编码器的情况使用或者再开发发行版的解码器(所以其他压缩管理工具可以调用rar的解码器来解压rar,但不能加压,百度云的在线解压rar可能是使用或者再开发过unrar文件),7z的文件和管理程序都是开源的,文件格式也比较好(支持Unicode文件名),两个主要压缩算法的性能都很好,只是差何时能普及而取代zip而已。 706 | 707 | - bzip2压缩 708 | - `bzip2`: compress a file 709 | - `bunzip2`: uncompress a file 710 | - `bzcat`: decompresses the compressed data and displays the decompressed data 711 | - `bzip2recover`: supports limited data recovery from media errors 712 | - gzip压缩 713 | - `gzip`: compresses a file 714 | - `gunzip` 715 | - `zcat` 716 | - xz压缩 717 | - [XZ utils](http://tukaani.org/xz/) : XZ Utils is free general-purpose data compression software with high compression ratio. XZ Utils were written for POSIX-like systems, but also work on some not-so-POSIX systems. XZ Utils are the successor to LZMA Utils. The core of the XZ Utils compression code is based on LZMA SDK, but it has been modified quite a lot to be suitable for XZ Utils. The primary compression algorithm is currently LZMA2, which is used inside the .xz container format. With typical files, XZ Utils create 30 % smaller output than gzip and 15 % smaller output than bzip2. 718 | - `xz` 719 | - `unxz` 720 | - `xzcat` 721 | - 7zip压缩 722 | - [7zip](http://www.7-zip.org/download.html) 723 | - linux、freebsd、macos下的port是p7zip,ubuntu下执行`sudo apt-get install p7zip-full`安装 724 | - 参考 725 | - [linux下的压缩解压软件7zip](http://www.linuxdiyf.com/viewarticle.php?id=193969) 726 | - [How to use 7zip on Linux command Line](https://www.ibm.com/developerworks/community/blogs/6e6f6d1b-95c3-46df-8a26-b7efd8ee4b57/entry/how_to_use_7zip_on_linux_command_line144?lang=en) 727 | - [p7zip - archlinux document](https://wiki.archlinux.org/index.php/P7zip) 728 | - zip压缩 729 | - zip: 参考[Linux zip command](http://linux.about.com/od/commands/l/blcmdl1_zip.htm) 730 | - unzip: 参考[Linux unzip command](http://linux.about.com/od/commands/l/blcmdl1_unzip.htm) 731 | - rar压缩 732 | - unrar: 参考[How To Extract RAR Files Under Linux](http://www.lifelinux.com/how-to-extract-rar-files-under-linux/) 733 | - `tar`: manipulate tape archives 734 | 735 | ## 10.3. 练习 736 | 737 | ### 10.3.1. `bzip2`, `bunzip2`, `bzcat`命令练习 738 | 739 | ```bash 740 | echo # 使用bzip2压缩文件默认会自动删除原文件,生成的压缩文件名是"[原文件名(包括扩展名)].bz2" 741 | $ bzip2 -v letter_e 742 | letter_e: 11680.00:1, 0.001 bits/byte, 99.99% saved, 584000 in, 50 out. 743 | 744 | $ ls -l 745 | -rw-rw-r-- 1 sam sam 50 2010-03-01 22:31 letter_e.bz2 746 | 747 | echo # 使用bunzip2解压文件会自动删除原压缩文件,原文件名去掉末尾的".bz2"就是生成的解压缩文件名 748 | $ bunzip -v letter_e.bz2 749 | 750 | $ bzcat letter_e.bz2 | head -2 751 | eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee 752 | eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee 753 | ``` 754 | 755 | ### 10.3.2. `tar`命令练习 756 | 757 | ```bash 758 | echo # === Combine files into one file === 759 | 760 | $ ls -l g b d 761 | -rw-r--r-- 1 zach other 1178 2010-08-20 14:16 b 762 | -rw-r--r-- 1 zach zach 3783 2010-08-20 14:17 d 763 | -rw-r--r-- 1 zach zach 1302 2010-08-20 14:16 g 764 | 765 | echo # –c (create), –v (verbose), and –f (write to or read from a file) 766 | $ tar -cvf all.tar g b d 767 | g 768 | b 769 | d 770 | 771 | $ ls -l all.tar 772 | -rw-r--r-- 1 zach zach 9728 2010-08-20 14:17 all.tar 773 | 774 | echo # –t option to display a table of contents for the archive 775 | $ tar -tvf all.tar 776 | -rw-r--r-- zach /zach 1302 2010-08-20 14:16 g 777 | -rw-r--r-- zach /other 1178 2010-08-20 14:16 b 778 | -rw-r--r-- zach /zach 3783 2010-08-20 14:17 d 779 | 780 | 781 | echo # === Extract files from combined file === 782 | 783 | $ ls -l mak* 784 | -rw-r--r-- 1 sam sam 1564560 2010-04-12 15:51 make-3.81.tar.gz 785 | 786 | $ gunzip mak* 787 | $ ls -l mak* 788 | -rw-r--r-- 1 sam sam 6072320 2010-04-12 15:51 make-3.81.tar 789 | 790 | echo # –x to extract files from a tar archive 791 | $ tar -xvf mak* 792 | make-3.81/ 793 | make-3.81/config/ 794 | make-3.81/config/dospaths.m4 795 | ... 796 | make-3.81/tests/run_make_tests.pl 797 | make-3.81/tests/test_driver.pl 798 | 799 | echo # ===combine the gunzip and tar commands=== 800 | 801 | echo # The –c option causes gunzip to send its output through the pipe instead of creating a file. The final hyphen (–) causes tar to read from standard input. 802 | $ gunzip -c make-3.81.tar.gz | tar -xvf - 803 | 804 | echo # –z option to cause tar to call gunzip 805 | $ tar -xvzf make-3.81.tar.gz 806 | 807 | echo # -j option to cause tar to call bzip2 808 | $ tar -xvjf make-3.81.tar.bz2 809 | ``` 810 | 811 | # 11. Process 812 | 813 | ## 11.1. 目标 814 | 815 | - 进程 816 | - 进程控制 817 | - 守护进程(daemon)和服务(service) 818 | 819 | ## 11.2. 内容 820 | 821 | - 基础概念 822 | - 进程 823 | - 进程号、父子进程关系 824 | - 僵尸进程: [Linux僵尸进程](http://coolshell.cn/articles/656.html) 825 | - 孤儿进程: [孤儿进程与僵尸进程](http://www.cnblogs.com/anker/p/3271773.html) 826 | - [信号](http://www.cnblogs.com/taobataoma/archive/2007/08/30/875743.html) 827 | - 守护进程和服务 828 | - 概念上的区别:系统为了某些功能必须要提供一些服务 (不论是系统本身还是网络方面),这个服务就称为 service。但是service的提供总是需要程序的运行吧!达成这个service的程序我们就称呼他为daemon!举例来说,达成循环型例行性工作排程服务 (service) 的程序为 crond 这个 daemon ! 829 | - daemon主要分为: 830 | - stand_alone,可以自行单独启动服务 831 | - super daemon,由一个特殊的 daemon 来统一管理 832 | - 参考 833 | - 阅读[鸟哥的Linux私房菜-认识系统服务](http://vbird.dic.ksu.edu.tw/linux_basic/0560daemons.php) 834 | - 实践 835 | - 通过/proc查看系统运行信息 836 | - [深入理解linux系统下proc文件系统内容](http://www.cnblogs.com/cute/archive/2011/04/20/2022280.html) 837 | - [使用 /proc 文件系统来访问 Linux 内核的内容](http://www.ibm.com/developerworks/cn/linux/l-proc.html) 838 | - 观察系统启动的服务 839 | - `netstat -tulp`: 找出目前系统开启的『网络服务』 840 | - `netstat -lnp`: 找出所有的有监听网络的服务 (包含 socket 状态) 841 | - `service --status-all`: 观察所有的服务状态 842 | - 通过`/etc/init.d`目录下的脚本控制服务 843 | - 用法:`Usage: /etc/init.d/networking {start|stop|reload|restart|force-reload}` 844 | - 通过`service`命令控制服务 845 | - `sudo service [service name] {start|stop|restart|status}` 846 | 847 | ## 11.3. Shell基本命令 848 | 849 | - `vmstat`: Report virtual memory statistics 850 | - `ps`: 使用PS查看进程信息,了解每一列的含义,掌握其参数 851 | - 参考 [每天一个linux命令(41):ps命令](http://www.cnblogs.com/peida/archive/2012/12/19/2824418.html) 852 | - `top`: 使用top查看系统负载,了解每一列的含义 853 | - 参考 [每天一个linux命令(44):top命令](http://www.cnblogs.com/peida/archive/2012/12/24/2831353.html) 854 | - `htop`: an interactive process viewer for Linux 855 | - [Linux下取代top的进程管理工具 htop](http://www.cnblogs.com/mchina/archive/2013/03/15/2858041.html) 856 | - [htop - an interactive process viewer for Linux](http://hisham.hm/htop/index.php?page=main) 857 | - `kill`: 通过kill给进程发送信号 858 | - 参考[每天一个linux命令(42):kill命令](http://www.cnblogs.com/peida/archive/2012/12/20/2825837.html) 859 | - [Linux进程间通信——使用信号](http://blog.csdn.net/ljianhui/article/details/10128731) 860 | - `lsof`: lsof(list open files)是一个列出当前系统打开文件的工具。在linux环境下,任何事物都以文件的形式存在,通过文件不仅仅可以访问常规数据,还可以访问网络连接和硬件。所以如传输控制协议 (TCP) 和用户数据报协议 (UDP) 套接字等,系统在后台都为该应用程序分配了一个文件描述符,无论这个文件的本质如何,该文件描述符为应用程序与基础操作系统之间的交互提供了通用接口。因为应用程序打开文件的描述符列表提供了大量关于这个应用程序本身的信息,因此通过lsof工具能够查看这个列表对系统监测以及排错将是很有帮助的。 861 | - 参考[每天一个linux命令(51):lsof命令](http://www.cnblogs.com/peida/archive/2013/02/26/2932972.html) 862 | 863 | 864 | 865 | # 12. Basic Network Management 866 | 867 | ## 12.1. 目标 868 | 869 | - 掌握基本网络管理概念和操作 870 | 871 | ## 12.2. 内容 872 | 873 | - 概念 874 | - [基础网络概念](http://vbird.dic.ksu.edu.tw/linux_server/0110network_basic.php) 875 | - 网络协议的层次结构 876 | - 参考[互联网协议入门(一)](http://www.ruanyifeng.com/blog/2012/05/internet_protocol_suite_part_i.html) 877 | - 参考[互联网协议入门(二)](http://www.ruanyifeng.com/blog/2012/06/internet_protocol_suite_part_ii.html) 878 | - IP协议,IP地址的分类,子网掩码 879 | - [如何理解ip路由和操作linux的路由表](http://linux.chinaunix.net/techdoc/net/2008/09/18/1033149.shtml) 880 | - TCP协议 881 | - UDP协议 882 | - 网络协议图 883 | - [常用网络通信协议结构图](./file/Network_Protocol_Diagram.jpg) 884 | - [TCP IP网络协议图](./file/TCP-IP_Network_Protocol_Diagram.pdf) 885 | - Network Protocol Map 886 | - [中文](./file/network-protocol-map-2016-zh.pdf) 887 | - [英文](./file/network-protocol-map-2016-en.pdf) 888 | - 参考 889 | - 常用文件传输方式及比较 890 | - [Linux 上的常用文件传输方式介绍与比较](http://www.ibm.com/developerworks/cn/linux/l-cn-filetransfer/) 891 | - [linux下不同服务器间数据传输(rcp,scp,rsync,ftp,sftp,lftp,wget,curl)](http://blog.csdn.net/emili/article/details/6858818) 892 | - [Linux常用网络指令](http://linux.vbird.org/linux_server/0140networkcommand.php) 893 | - [linux网络配置命令之ifconfig、ip和route](http://chrinux.blog.51cto.com/6466723/1188108) 894 | - [Linux and Unix ifconfig command](http://www.computerhope.com/unix/uifconfi.htm) 895 | - [iptables vs route](http://superuser.com/questions/419659/iptables-vs-route) 896 | - [NAT - Network Address Translation](http://www.karlrupp.net/en/computer/nat_tutorial) 897 | 898 | ## 12.3. Shell命令 899 | 900 | - `ifconfig` 901 | - 参考[每天一个linux命令(52):ifconfig命令](http://www.cnblogs.com/peida/archive/2013/02/27/2934525.html) 902 | - 参考[Linux and Unix - ifconfig command](http://www.computerhope.com/unix/uifconfi.htm) 903 | - `telnet` 904 | - 参考[Linux and Unix - telnet command](http://www.computerhope.com/unix/utelnet.htm) 905 | - `ping`: use ICMP 906 | - 参考[ping结果中TTL是什么意思](http://www.ezloo.com/2007/05/ping_ttl.html) 907 | - 参考[ping 命令详解](http://zhidao.baidu.com/question/13855241.html) 908 | - `traceroute`: traces a route over the internet 909 | - 参考[每天一个linux命令(55):traceroute命令](http://www.cnblogs.com/peida/archive/2013/03/07/2947326.html) 910 | - `mtr`: 'traceroute' and 'ping' in a single tool 911 | - 参考[mtr命令详解](http://xukaizijian.blog.163.com/blog/static/1704331192011023259812/) 912 | - `nslookup`, `host`, `dig`: DNS lookup utility 913 | - 参考[Linux and Unix - nslookup command](http://www.computerhope.com/unix/unslooku.htm) 914 | - 参考[Linux and Unix - host command](http://www.computerhope.com/unix/host.htm) 915 | - 参考[Linux and Unix - dig command](http://www.computerhope.com/unix/dig.htm) 916 | - `whois`: look up information about a internet site 917 | - 参考[Linux and Unix - whois command](http://www.computerhope.com/unix/uwhois.htm) 918 | - [站长之家 - whois查询](http://whois.chinaz.com/) 919 | - [Godaddy whois查询](https://who.godaddy.com/) 920 | - `netstat`: 921 | - 参考[每天一个linux命令(56):netstat命令](http://www.cnblogs.com/peida/archive/2013/03/08/2949194.html) 922 | - `ip` 923 | - 参考[Linux and Unix - ip command](http://www.computerhope.com/unix/ip.htm) 924 | - `iptables`: iptables is a user-space application program that allows a system administrator to configure the tables provided by the Linux kernel firewall (implemented as different Netfilter modules) and the chains and rules it stores. Different kernel modules and programs are currently used for different protocols; iptables applies to IPv4, ip6tables to IPv6, arptables to ARP, and ebtables to Ethernet frames. 925 | - 参考[百度百科-iptables](http://baike.baidu.com/view/504557.htm#1_1) 926 | - 参考[wikipedia - iptables](https://en.wiki2.org/wiki/Iptables) 927 | 928 | ## 12.4. 练习 929 | 930 | ### 12.4.1. 修改OS的hostname 931 | 932 | 参考[How do I change the hostname without a restart?](http://askubuntu.com/questions/87665/how-do-i-change-the-hostname-without-a-restart) 933 | 934 | `hostname`临时保存在内存,永久保存在`/etc/hostname`文件中,同时`/etc/hosts`文件中也配置了`hostname`对应的IP地址 935 | 936 | - 查看主机名`hostname` 937 | - 临时修改主机名,命令执行后即时生效`sudo hostname [yourhostname]`,重启后依然恢复原hostname 938 | - 永久修改主机名,将新的主机名写入,重启系统后生效`sudo vim /etc/hostname` 939 | - `hostnamectl`命令包含了临时修改hostname和修改`/etc/hostname`两种操作,但是不会修改`/etc/hosts`,所以执行`hostnamectl`命令后还需要手动修改`/etc/hosts`文件 940 | 941 | ```bash 942 | hostnamectl set-hostname new-hostname 943 | ``` 944 | 945 | ### 12.4.2. 设置DNS服务的服务地址 946 | 947 | 参考: 948 | 949 | - [/etc/resolv.conf](http://man7.org/linux/man-pages/man5/resolv.conf.5.html) 950 | - [Resolv.conf - Archlinux Wiki](https://wiki.archlinux.org/index.php/Resolv.conf) 951 | 952 | 编辑保存DNS信息的配置文件 953 | 954 | ```bash 955 | sudo pico /etc/resolv.conf 956 | ``` 957 | 958 | 最多可以使用3个DNS地址,内容如下 959 | 960 | ```bash 961 | nameserver xxx.xxx.xxx.xxx 962 | nameserver xxx.xxx.xxx.xxx 963 | nameserver xxx.xxx.xxx.xxx 964 | ``` 965 | 966 | 对`resolv.conf`文件的修改是即时生效的,可以使用`nslookup`命令进行测试。 967 | 968 | ### 12.4.3. 如何配置网卡和IP地址 969 | 970 | ubuntu的网卡配置信息放在`/etc/network/interfaces`中, 971 | 972 | ```bash 973 | sudo vim /etc/network/interfaces 974 | ``` 975 | 976 | 要通过dhcp获取ip,则添加如下内容: 977 | 978 | ```bash 979 | auto eth0 980 | iface eth0 inet dhcp 981 | ``` 982 | 983 | 如果配置静态ip,则添加如下内容: 984 | 985 | ```bash 986 | auto eth0 987 | iface eth0 inet static 988 | address 192.168.1.201 989 | netmask 255.255.255.0 990 | gateway 192.168.1.1 991 | ``` 992 | 993 | 需重启下网络服务使配置生效 994 | 995 | ```bash 996 | sudo /etc/init.d/networking restart 997 | ``` 998 | 999 | ### 12.4.4. 从Internet更新ubuntu本地的时间 1000 | 1001 | You can do so with `sudo ntpdate time.nist.gov` other servers include time.windows.com, etc. 1002 | http://www.pool.ntp.org/ lists time servers around the world. 1003 | 1004 | ## 12.5. 切换网络后,强制更新网卡IP 1005 | 1006 | To renew or release an IP address for the eth0 interface, enter: 1007 | 1008 | ```bash 1009 | $ sudo dhclient -r eth0 1010 | $ sudo dhclient eth0 1011 | ``` 1012 | 1013 | 1014 | 1015 | # 13. Writing Shell Scripts 1016 | 1017 | ## 13.1. 目标 1018 | 1019 | - Shell的基本概念及启动过程 1020 | - 编写Shell脚本 1021 | - 参考 1022 | - [The art of command line](https://github.com/jlevy/the-art-of-command-line) 1023 | - [Awesome Shell](https://github.com/alebcay/awesome-shell) 1024 | - [Gnu Bash Reference](http://www.gnu.org/software/bash/manual/bashref.html) 1025 | 1026 | ## 13.2. 基本概念 1027 | 1028 | ### 13.2.1. 交互式shell和非交互式shell、登录shell和非登录shell的区别 1029 | 1030 | > 参考[交互式shell和非交互式shell、登录shell和非登录shell的区别](http://smilejay.com/2012/10/interactive-shell-login-shell/) 1031 | 1032 | 首先,这是两个不同的维度来划分的,一个是是否交互式,另一个是是否登录。 1033 | 1034 | 交互式模式就是在终端上执行,shell等待你的输入,并且立即执行你提交的命令。这种模式被称作交互式是因为shell与用户进行交互。 1035 | 这种模式也是大多数用户非常熟悉的:登录、执行一些命令、退出。当你退出后,shell也终止了。 1036 | shell也可以运行在另外一种模式:非交互式模式,以shell script(非交互)方式执行。 1037 | 在这种模式下,shell不与你进行交互,而是读取存放在文件中的命令,并且执行它们。当它读到文件的结尾EOF,shell也就终止了。 1038 | 1039 | 可以通过打印“$-”变量的值(代表着当前shell的选项标志),查看其中的“i”选项(表示interactive shell)来区分交互式与非交互式shell。 1040 | 1041 | ```bash 1042 | $ echo $- 1043 | himBH 1044 | 1045 | $ ./test.sh 1046 | echo $- 1047 | hB 1048 | ``` 1049 | 1050 | - 登录shell:是需要用户名、密码登录后才能进入的shell(或者通过”–login”选项生成的shell)。 1051 | - 非登录shell:当然就不需要输入用户名和密码即可打开的Shell,例如:直接命令“bash”就是打开一个新的非登录shell,在Gnome或KDE中打开一个“终端”(terminal)窗口程序也是一个非登录shell。 1052 | 1053 | 执行exit命令,退出一个shell(登录或非登录shell);执行logout命令,退出登录shell(不能退出非登录shell)。 1054 | 1055 | ```bash 1056 | $ bash --login 1057 | $ logout 1058 | $ bash --login 1059 | $ exit 1060 | logout 1061 | 1062 | $ bash 1063 | $ logout 1064 | bash: logout: not login shell: use 'exit' 1065 | $ exit 1066 | exit 1067 | ``` 1068 | 1069 | > man bash: A login shell is one whose first character of argument zero is a -, or one started with the –login option. 1070 | 1071 | bash是 login shell 时,其进程名为”-bash“ 而不是”bash”。 比如下面的命令行演示: 1072 | 1073 | _在 login shell 中:_ 1074 | 1075 | ```bash 1076 | $ echo $0 1077 | -bash 1078 | $ ps -ef | grep '\-bash' | grep -v grep 1079 | root 16823 16821 0 May06 pts/0 00:00:00 -bash 1080 | perf 21135 21134 0 May07 pts/1 00:00:00 -bash 1081 | ``` 1082 | 1083 | _在一个非登陆shell中:_ 1084 | 1085 | ```bash 1086 | $ echo $0 1087 | /bin/bash 1088 | $ ps -ef | grep '\-bash' | grep -v grep 1089 | $ 1090 | ``` 1091 | 1092 | 对于Bash来说,登录shell(包括交互式登录shell和使用`–login`选项的非交互shell),它会首先读取和执行`/etc/profile`全局配置文件中的命令,然后依次查找`~/.bash_profile`、`~/.bash_login` 和 `~/.profile`这三个配置文件,读取和执行**这三个中的第一个存在且可读的文件**中命令。除非被`–noprofile`选项禁止了。 1093 | 1094 | 在非登录shell里,只读取`~/.bashrc`(和`/etc/bash.bashrc`、`/etc/bashrc`)文件,不同的发行版里面可能有所不同,如RHEL6.3中非登录shell仅执行了`~/.bashrc`文件(没有执行`/etc/bashrc`),而KUbuntu10.04中却依次执行了`/etc/bash.bashrc` 和 `~/.bashrc` 文件。 1095 | 1096 | 对于这些规则,可以直接在相应的配置文件中加一些`echo`命令来验证其真实性。 1097 | 1098 | ### 13.2.2. 语法 1099 | 1100 | 请阅读[Shell脚本语法](./shell-script-grammar.md) 1101 | 1102 | ## 13.3. Shell命令 1103 | 1104 | - `export` 1105 | - `source` 1106 | - `xargs`: construct argument list(s) and execute utility 1107 | - [Example xargs](http://examplenow.com/zh-cn/xargs/man1) 1108 | - [10 Xargs Command Examples in Linux / UNIX](http://www.thegeekstuff.com/2013/12/xargs-examples/) 1109 | 1110 | ## 13.4. 练习 1111 | 1112 | ### 13.4.1. 如何让你的shell脚本更健壮和更可靠 1113 | 1114 | 请阅读: 1115 | 1116 | - [Use the Unofficial Bash Strict Mode (Unless You Looove Debugging)](http://redsymbol.net/articles/unofficial-bash-strict-mode/) 1117 | - [How "Exit Traps" Can Make Your Bash Scripts Way More Robust And Reliable](http://redsymbol.net/articles/bash-exit-traps/) 1118 | 1119 | 1120 | 1121 | # 14. Schedule Tasks 1122 | 1123 | ## 14.1. 目标 1124 | 1125 | - 掌握cron 1126 | - 掌握anacron 1127 | - 掌握at 1128 | 1129 | ## 14.2. 内容 1130 | 1131 | ### 14.2.1. 参考 1132 | 1133 | - PG2UL,page 605,Scheduling Tasks 1134 | - [crontab 定时任务](http://linuxtools-rst.readthedocs.org/zh_CN/latest/tool/crontab.html) 1135 | - [linux Crontab 使用](http://www.oschina.net/questcion/234345_42400) 1136 | - [使用 Anacron 处理 Linux 关机问题](http://www.ibm.com/developerworks/cn/linux/l-anacron/index.html) 1137 | - [linux定时任务的设置](http://www.blogjava.net/freeman1984/archive/2010/09/23/332715.html) 1138 | 1139 | ### 14.2.2. cron的坑 1140 | 1141 | - crontab文件设置了任务的执行时间,此时间依赖当前os的系统时区。 1142 | 1143 | ### 14.2.3. cron和anacron的区别 1144 | 1145 | cron是用来控制循环执行的例行性工作的,可循环的时间为分钟、小时、每周、每月或每年等。比如我要设定机器每天早上8点进行备份,就可以用到这个服务。 1146 | 除非我们的机器保持每天都24小时开始,否则就会有些系统例行工作都没有人做了,这个时候就可以用到anacron了。 1147 | 1148 | anacron并不是用来取代cron的,anacron存在的目的就在于我们上面提到的,在处理非 24 小时一直启动的Linux系统的cron服务的执行! 1149 | 所以 anacron 并不能指定何时执行某项任务,而是以天为单位或者是在开机后立刻进行anacron的动作,他会去侦测停机期间应该进行但是并没有进行的cron服务, 1150 | 如果有就将该任务执行一遍,然后就自动停止。anacron脚本不会在OS使用电池作为电源时候运行。 1151 | 1152 | ### 14.2.4. Crontab文件 1153 | 1154 | 共有两种类型的 Cron 作业(即由 Cron 运行的程序):系统 Cron 作业,由系统运行,执行系统维护任务;另一种是 用户 Cron 作业,由用户创建,用于执行用户任务。 1155 | 对于这两种作业而言,系统 Cron 作业更加重要一些。这些作业可能包括清除 /tmp 中的陈旧文件、替换日志文件、更新垃圾邮件过滤规则,以及更新 locate 数据库。 1156 | 1157 | cron守护进程根据crontab文件中的配置执行定时任务。 1158 | 1159 | - 系统crontab文件保存在`/etc/cron.d`目录和`/etc/crontab`文件中 1160 | - 用户可以使用`crontab`工具设置个人的crontab文件,用户的crontab文件保存在`/var/spool/cron/crontabs`中 1161 | 1162 | #### 14.2.4.1. 系统crontab文件 1163 | 1164 | crontab文件设置命令的执行频率。 1165 | 1166 | `/etc/crontab`内容如下: 1167 | 1168 | ```bash 1169 | echo # /etc/crontab: system-wide crontab 1170 | echo # Unlike any other crontab you don't have to run the `crontab' 1171 | echo # command to install the new version when you edit this file 1172 | echo # and files in /etc/cron.d. These files also have username fields, 1173 | echo # that none of the other crontabs do. 1174 | 1175 | SHELL=/bin/sh 1176 | PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 1177 | 1178 | echo # m h dom mon dow user command 1179 | 17 * * * * root cd / && run-parts --report /etc/cron.hourly 1180 | 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) 1181 | 47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly ) 1182 | 52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly ) 1183 | ``` 1184 | 1185 | 最后4行命令的格式如下: 1186 | 1187 | > minute hour day-of-month month day-of-week user command 1188 | 1189 | The first five fields indicate when cron will execute the command: 1190 | 1191 | - The **minute** is the number of minutes after the start of the hour 1192 | - the **hour** is the hour of the day based on a 24-hour clock 1193 | - the **day-of-month** is a number from 1 to 31 1194 | - the **day-of-week** is a number from 0 to 7, with 0 and 7 indicating Sunday 1195 | - An asterisk (`*`) substitutes for any value in a field 1196 | - The user is the username or user ID of the user that the command will run as 1197 | 1198 | 除了`/etc/crontab`,cron守护进程还会读取`/etc/cron.d`下的配置文件。下面是`/etc/cron.d/anacron`的内容, 1199 | 这段配置告知`cron`每天7:30 AM运行`anacron`初始化脚本。这段初始化脚本只会在系统开机且不使用电池电源的时候运行`anacron`。 1200 | 1201 | ```bash 1202 | echo # /etc/cron.d/anacron: crontab entries for the anacron package 1203 | 1204 | SHELL=/bin/sh 1205 | PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 1206 | 1207 | 30 7 * * * root start -q anacron || : 1208 | ``` 1209 | 1210 | #### 14.2.4.2. 用户crontab文件 1211 | 1212 | - 用户crontab文件保存在`/var/spool/cron/crontabs/`目录下,并且以用户名命令 1213 | - 可以通过`crontab -l`查看当前用户的crontab文件 1214 | - 可以通过`crontab -e`创建或者编辑当前用户的crontab文件 1215 | - 可以通过`crontab -r`删除当前用户的crontab文件 1216 | 1217 | ### 14.2.5. anacron配置文件 1218 | 1219 | Anacron通过`/etc/anacrontab`文件进行控制。该文件可以包含注释行(使用一个前导散列符号`#`表示)、环境变量分配(比如`SHELL=/bin/bash`)和作业定义。 1220 | 1221 | `/etc/anacrontab`中的内容如下: 1222 | 1223 | ```bash 1224 | echo # /etc/anacrontab: configuration file for anacron 1225 | 1226 | echo # See anacron(8) and anacrontab(5) for details. 1227 | 1228 | SHELL=/bin/sh 1229 | PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 1230 | HOME=/root 1231 | LOGNAME=root 1232 | 1233 | echo # These replace cron's entries 1234 | 1 5 cron.daily run-parts --report /etc/cron.daily 1235 | 7 10 cron.weekly run-parts --report /etc/cron.weekly 1236 | @monthly 15 cron.monthly run-parts --report /etc/cron.monthly 1237 | ``` 1238 | 1239 | 最后三行记录的格式如下: 1240 | 1241 | > period delay identifier command 1242 | 1243 | - period是anacron执行命令的频率,单位为天 1244 | - delay是anacron启动后,多长时间执行命令,单位为分钟 1245 | - identifier是anacron用来记录上次什么时候执行命令的文件的文件名,文件保存在`/var/spool/anacron`文件夹下 1246 | 1247 | 1248 | 1249 | 1250 | # 15. FAQ 1251 | 1252 | ## 15.1. 如何安装中文语言支持及中文输入法 1253 | 1254 | [Ubuntu上的输入法情况](http://wiki.ubuntu.org.cn/%E4%B8%AD%E6%96%87%E8%BE%93%E5%85%A5%E6%B3%95): 1255 | 1256 | > Ubuntu上有IBus、Fcitx等开源的输入法框架,支持各种各样的引擎。 1257 | > Rime(中州韵输入法引擎)是一种流行的开源跨平台输入法,支持IBus和Fcitx框架。 1258 | > 搜狗输入法在2014年4月发布了Linux版本,使用Fcitx框架。 1259 | > 免费但不开源的小小输入法,也提供对Ubuntu的支持。 1260 | > 作为Chrome扩展的输入法:Google Input Tools 1261 | > 作为Firefox扩展的输入法:火输(Fireinput)。 1262 | > 可以直接在浏览器中使用的云输入法:搜狗云输入法、QQ云输入法等。 1263 | 1264 | 目前比较推荐Linux上的搜狗输入法:[下载地址](http://pinyin.sogou.com/linux/?r=pinyin) 1265 | 1266 | 搜过拼音的安装方法: 1267 | 1268 | - [Ubuntu 14.04安装搜狗拼音linux版应该注意的问题](http://blog.csdn.net/tao_627/article/details/24119037) 1269 | - [Ubuntu下安装搜狗拼音输入法](http://blog.csdn.net/rflyee/article/details/9472579) 1270 | 1271 | ## 15.2. 如何给Ubuntu Linux Virutal Machine安装VMWare Tools 1272 | 1273 | - 安装方法参考 1274 | - [Installing VMware Tools in an Ubuntu virtual machine (1022525)](http://kb.vmware.com/selfservice/microsites/search.do?cmd=displayKC&docType=kc&externalId=1022525) 1275 | - 卸载方法参考 1276 | - [Uninstalling and manually installing VMware Tools in VMware Fusion (1014522)](http://kb.vmware.com/selfservice/microsites/search.do?cmd=displayKC&docType=kc&externalId=1014522&sliceId=1&docTypeID=DT_KB_1_1&dialogID=672738403&stateId=1%200%20672744194) 1277 | - [VMware Tools Uninstaller in Ubuntu Guest Does Not Remove vmxnet Module (1004351)](http://kb.vmware.com/selfservice/microsites/search.do?cmd=displayKC&docType=kc&externalId=1004351&sliceId=1&docTypeID=DT_KB_1_1&dialogID=672738403&stateId=1%200%20672744194) 1278 | 1279 | ## 15.3. 如何给Ubuntu Linux Virtual Machine安装VirtualBox Additions 1280 | 1281 | 参考[How do I install Guest Additions in a VirtualBox VM?](http://askubuntu.com/questions/22743/how-do-i-install-guest-additions-in-a-virtualbox-vm) 1282 | 1283 | ## 15.4. 如何给Ubuntu Linux Virtual Machine安装Parallel Tools 1284 | 1285 | 参考[How do I install Parallels Tools in Ubuntu Virtual Machine?](http://kb.parallels.com/en/113394) 1286 | 1287 | ## 15.5. 使用命令`man wget > man-wget.txt`把命令文档输入到文本文件后,打开man-wget.txt,发现有很多重复字符,或者乱码? 1288 | 1289 | 将man手册查询命令输出到文本文件中,要求过滤掉控制字符^H(Backspace (退格)) 1290 | 1291 | `man chmod | col –b > /home/man_chmod.txt` 1292 | 1293 | col命令的使用方法见[col命名详解](http://myblog.jyc.edu.cn/?p=62) 1294 | -------------------------------------------------------------------------------- /linux&unix/vim-learning-notes.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | - [1. 使用Vim](#1-使用vim) 4 | - [1.1. 学习卡片](#11-学习卡片) 5 | - [1.2. `vimtutor`教程](#12-vimtutor教程) 6 | - [1.2.1. Chapter 1](#121-chapter-1) 7 | - [1.2.2. Chapter 2](#122-chapter-2) 8 | - [1.2.3. Chapter 3](#123-chapter-3) 9 | - [1.2.4. Chapter 4](#124-chapter-4) 10 | - [1.2.5. Chapter 5](#125-chapter-5) 11 | - [1.2.6. Chapter 6](#126-chapter-6) 12 | - [1.2.7. Chapter 7](#127-chapter-7) 13 | - [2. 配置Vim](#2-配置vim) 14 | - [2.1. 安装`spf13-vim`](#21-安装spf13-vim) 15 | - [3. 参考](#3-参考) 16 | 17 | 18 | 19 | 20 | # 1. 使用Vim 21 | 22 | ## 1.1. 学习卡片 23 | 24 | ![](./img/2015/05/vi-vim-cheat-sheet.gif) 25 | ![](./img/2015/05/vi-vim-cheat-sheet-sch.gif) 26 | ![](./img/2015/05/vim_cheat_sheet_for_programmers_print.png) 27 | 28 | ## 1.2. `vimtutor`教程 29 | 30 | ### 1.2.1. Chapter 1 31 | 32 | ```text 33 | Lesson 1 SUMMARY 34 | 35 | 36 | 1. The cursor is moved using either the arrow keys or the hjkl keys. 37 | h (left) j (down) k (up) l (right) 38 | 39 | 2. To start Vim from the shell prompt type: vim FILENAME 40 | 41 | 3. To exit Vim type: :q! to trash all changes. 42 | OR type: :wq to save the changes. 43 | 44 | 4. To delete the character at the cursor type: x 45 | 46 | 5. To insert or append text type: 47 | i type inserted text insert before the cursor 48 | A type appended text append after the line 49 | 50 | NOTE: Pressing will place you in Normal mode or will cancel 51 | an unwanted and partially completed command. 52 | ``` 53 | 54 | ### 1.2.2. Chapter 2 55 | 56 | ```text 57 | Lesson 2 SUMMARY 58 | 59 | 60 | 1. To delete from the cursor up to the next word type: dw 61 | 2. To delete from the cursor to the end of a line type: d$ 62 | 3. To delete a whole line type: dd 63 | 64 | 4. To repeat a motion prepend it with a number: 2w 65 | 5. The format for a change command is: 66 | operator [number] motion 67 | where: 68 | 69 | operator - is what to do, such as d for delete 70 | [number] - is an optional count to repeat the motion 71 | motion - moves over the text to operate on, such as w (word), 72 | $ (to the end of line), etc. 73 | 74 | 6. To move to the start of the line use a zero: 0 75 | 76 | 7. To undo previous actions, type: u (lowercase u) 77 | To undo all the changes on a line, type: U (capital U) 78 | To undo the undo's, type: CTRL-R 79 | ``` 80 | 81 | ### 1.2.3. Chapter 3 82 | 83 | ```text 84 | Lesson 3 SUMMARY 85 | 86 | 87 | 1. To put back text that has just been deleted, type p . This puts the 88 | deleted text AFTER the cursor (if a line was deleted it will go on the 89 | line below the cursor). 90 | 91 | 2. To replace the character under the cursor, type r and then the 92 | character you want to have there. 93 | 94 | 3. The change operator allows you to change from the cursor to where the 95 | motion takes you. eg. Type ce to change from the cursor to the end of 96 | the word, c$ to change to the end of a line. 97 | 98 | 4. The format for change is: 99 | 100 | c [number] motion 101 | 102 | ``` 103 | 104 | ### 1.2.4. Chapter 4 105 | 106 | ```text 107 | Lesson 4 SUMMARY 108 | 109 | 110 | 1. CTRL-G displays your location in the file and the file status. 111 | G moves to the end of the file. 112 | number G moves to that line number. 113 | gg moves to the first line. 114 | 115 | 2. Typing / followed by a phrase searches FORWARD for the phrase. 116 | Typing ? followed by a phrase searches BACKWARD for the phrase. 117 | After a search type n to find the next occurrence in the same direction 118 | or N to search in the opposite direction. 119 | CTRL-O takes you back to older positions, CTRL-I to newer positions. 120 | 121 | 3. Typing % while the cursor is on a (,),[,],{, or } goes to its match. 122 | 123 | 4. To substitute new for the first old in a line type :s/old/new 124 | To substitute new for all 'old's on a line type :s/old/new/g 125 | To substitute phrases between two line #'s type :#,#s/old/new/g 126 | To substitute all occurrences in the file type :%s/old/new/g 127 | To ask for confirmation each time add 'c' :%s/old/new/gc 128 | ``` 129 | 130 | ### 1.2.5. Chapter 5 131 | 132 | ```text 133 | Lesson 5 SUMMARY 134 | 135 | 136 | 1. :!command executes an external command. 137 | 138 | Some useful examples are: 139 | (MS-DOS) (Unix) 140 | :!dir :!ls - shows a directory listing. 141 | :!del FILENAME :!rm FILENAME - removes file FILENAME. 142 | 143 | 2. :w FILENAME writes the current Vim file to disk with name FILENAME. 144 | 145 | 3. v motion :w FILENAME saves the Visually selected lines in file 146 | FILENAME. 147 | 148 | 4. :r FILENAME retrieves disk file FILENAME and puts it below the 149 | cursor position. 150 | 151 | 5. :r !dir reads the output of the dir command and puts it below the 152 | cursor position. 153 | 154 | ``` 155 | 156 | ### 1.2.6. Chapter 6 157 | 158 | ```text 159 | Lesson 6 SUMMARY 160 | 161 | 1. Type o to open a line BELOW the cursor and start Insert mode. 162 | Type O to open a line ABOVE the cursor. 163 | 164 | 2. Type a to insert text AFTER the cursor. 165 | Type A to insert text after the end of the line. 166 | 167 | 3. The e command moves to the end of a word. 168 | 169 | 4. The y operator yanks (copies) text, p puts (pastes) it. 170 | 171 | 5. Typing a capital R enters Replace mode until is pressed. 172 | 173 | 6. Typing ":set xxx" sets the option "xxx". Some options are: 174 | 'ic' 'ignorecase' ignore upper/lower case when searching 175 | 'is' 'incsearch' show partial matches for a search phrase 176 | 'hls' 'hlsearch' highlight all matching phrases 177 | You can either use the long or the short option name. 178 | 179 | 7. Prepend "no" to switch an option off: :set noic 180 | 181 | ``` 182 | 183 | ### 1.2.7. Chapter 7 184 | 185 | 186 | ```text 187 | Lesson 7 SUMMARY 188 | 189 | 190 | 1. Type :help or press or to open a help window. 191 | 192 | 2. Type :help cmd to find help on cmd . 193 | 194 | 3. Type CTRL-W CTRL-W to jump to another window 195 | 196 | 4. Type :q to close the help window 197 | 198 | 5. Create a vimrc startup script to keep your preferred settings. 199 | 200 | 6. When typing a : command, press CTRL-D to see possible completions. 201 | Press to use one completion. 202 | 203 | ``` 204 | 205 | # 2. 配置Vim 206 | 207 | ## 2.1. 安装`spf13-vim` 208 | 209 | 由于国内[http://j.mp/spf13-vim3](http://j.mp/spf13-vim3)被封,spf13-vim官网告知的安装方法无法执行成功。国内用户请通过下面的命令执行安装: 210 | 211 | ```sh 212 | curl https://raw.githubusercontent.com/spf13/spf13-vim/3.0/bootstrap.sh -L -o - | sh 213 | ``` 214 | 215 | # 3. 参考 216 | 217 | - [vim](https://www.vim.org/) 218 | 219 | 学习内容: 220 | 221 | - [有哪些编程必备的 Vim 配置?](http://www.zhihu.com/question/19989337) 222 | - [笨方法学Vimscript](http://learnvimscriptthehardway.onefloweroneworld.com/): 面向那些想学会如何自定义Vim编辑器的用户 223 | - [vimgolf](http://www.vimgolf.com/): Real Vim ninjas count every keystroke 224 | - [Graphical vi-vim Cheat Sheet and Tutorial](http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html) 225 | - [Vim Cheat Sheet](http://michael.peopleofhonoronly.com/vim/) 226 | 227 | VIM配置: 228 | 229 | - [spf13-vim](http://vim.spf13.com/) 230 | - [SpaceVim](https://github.com/SpaceVim/SpaceVim) 231 | - [neovim](https://neovim.io/) 232 | - [amix/vimrc](https://github.com/amix/vimrc): The ultimate Vim configuration 233 | -------------------------------------------------------------------------------- /macos/assets/2022-05-15-00-19-40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EthanCai/linux-system-ops/0bcfd206908ff3293a17c782ddb8a3aac1f23752/macos/assets/2022-05-15-00-19-40.png -------------------------------------------------------------------------------- /macos/mac-os-study-guideline.md: -------------------------------------------------------------------------------- 1 | - [1. 知识体系](#1-知识体系) 2 | - [2. Further Reading](#2-further-reading) 3 | - [3. FAQ](#3-faq) 4 | - [3.1. Windows和Mac OS X的一些区别?](#31-windows和mac-os-x的一些区别) 5 | - [3.2. Macbook OS X Yosemite快捷键?](#32-macbook-os-x-yosemite快捷键) 6 | - [3.3. MacOS有哪些好用的SSH客户端?](#33-macos有哪些好用的ssh客户端) 7 | - [3.4. MacOS建议使用什么包管理工具?](#34-macos建议使用什么包管理工具) 8 | - [3.5. 如何配置Mac开发环境?](#35-如何配置mac开发环境) 9 | - [3.6. Macbook Terminal中有哪些快捷键?](#36-macbook-terminal中有哪些快捷键) 10 | - [3.7. 如何在Finder右键菜单中直接打开Shell?](#37-如何在finder右键菜单中直接打开shell) 11 | - [3.8. Mac OS X如何使用系统自带功能截屏?](#38-mac-os-x如何使用系统自带功能截屏) 12 | - [3.9. 如何通过Boot Camp Assistance在MacBook Pro上安装Windows?](#39-如何通过boot-camp-assistance在macbook-pro上安装windows) 13 | - [3.10. Bootcamp Windows中如何访问Mac OS X的分区?](#310-bootcamp-windows中如何访问mac-os-x的分区) 14 | - [3.11. 如何让Bootcamp Windows上的触摸板操作体验和Mac OS X一样?](#311-如何让bootcamp-windows上的触摸板操作体验和mac-os-x一样) 15 | - [3.12. MacOS下的Hosts文件在哪?](#312-macos下的hosts文件在哪) 16 | - [3.13. MacOS如何查看路由表?](#313-macos如何查看路由表) 17 | 18 | # 1. 知识体系 19 | 20 | - 文件、目录与权限 21 | - 系统自带的特殊目录及其作用 22 | - [苹果新手Mac OS X 使用笔记--系统目录结构](http://blog.csdn.net/smstong/article/details/15499661) 23 | 24 | 25 | # 2. Further Reading 26 | 27 | - [好文推荐,《Mac OS X 背后的故事》](https://www.v2ex.com/t/154959) 28 | 29 | # 3. FAQ 30 | 31 | ## 3.1. Windows和Mac OS X的一些区别? 32 | 33 | - [Mac的基础知识](http://www.apple.com/cn/support/macbasics/) 34 | - [切换 101:在 Windows 上,我常常……](https://support.apple.com/zh-cn/HT2514) 35 | - [Windows系统与Mac系统的简单区别](http://wiki.blueidea.com/index.php?title=Windows系统与Mac系统的简单区别) 36 | 37 | ## 3.2. Macbook OS X Yosemite快捷键? 38 | 39 | - [OS X键盘快捷键](https://support.apple.com/zh-cn/HT201236) 40 | - 打开System Preferences -> Keyboard -> Shortcuts查看 41 | 42 | ## 3.3. MacOS有哪些好用的SSH客户端? 43 | 44 | 参考:[Mac OS X 平台有哪些好用的 SSH 客户端?](http://www.zhihu.com/question/20541129), 最好掌握[iTerm2](https://www.iterm2.com/index.html)和[tmux](http://tmux.sourceforge.net/)。 45 | 46 | ## 3.4. MacOS建议使用什么包管理工具? 47 | 48 | [Homebrew](http://brew.sh/) 49 | [Homebrew的用户手册](https://github.com/Homebrew/homebrew/tree/master/share/doc/homebrew) 50 | 51 | ## 3.5. 如何配置Mac开发环境? 52 | 53 | 参考:[Mac开发配置手册](https://www.gitbook.com/book/aaaaaashu/mac-dev-setup/details) 54 | 55 | ## 3.6. Macbook Terminal中有哪些快捷键? 56 | 57 | * 清屏:Command + K 或者 Control + L 58 | * 新建标签: Command + T 59 | * 关闭当前标签页: Command +W 60 | * 保存终端输出:Command + S 61 | * 水平分隔当前标签页: Command + D (注意iTerm2中,Command+D是纵向分割) 62 | * 取消水平分隔: Command + Shift + D (注意iTerm2中,Command+D是水平分割) 63 | * 向左/向右切换标签: Command + shift + { 或 } 64 | * control + a / e 回到命令行头/尾 65 | * option + b / f 向前/后跳一个单词 66 | * control +u /k 删除光标前/后 所有单词 67 | * control + y 撤销上个操作 68 | 69 | ## 3.7. 如何在Finder右键菜单中直接打开Shell? 70 | 71 | - 通过Automator创建一个Service,参考[open-shell-at-selected-folder-via-automater-service](http://blog.xcodev.com/archives/open-shell-at-selected-folder-via-automater-service/) 72 | - 通过菜单Finder -> Services->Services Preferences,找到"Files and Folders"下的"New Terminal xxx"并勾选![](assets/2022-05-15-00-19-40.png) 73 | 74 | ## 3.8. Mac OS X如何使用系统自带功能截屏? 75 | 76 | 参考:[How To Capture a Screen Shot with Mac OS X](http://graphicssoft.about.com/od/screencapturemac/ht/macscreenshot.htm) 77 | 78 | * To capture the entire desktop, press `Command-Shift-3`. 79 | * To copy the entire desktop to clipboard, press `Command-Control-Shift-3`. 80 | * To capture a portion of the desktop, press `Command-Shift-4`. 81 | * To capture a specific application window, press `Command-Shift-4`, then press the Spacebar. The screen shot will be saved as a PNG file on your desktop. (The file is saved as PDF in Mac OS 10.3 and earlier.) 82 | * Add `Control` to the two shortcuts above to place the screen shot on the clipboard instead of saving it to the desktop. 83 | * Another method for capturing screen shots in Mac OS X is by using the bundled Apple utility, **Grab**, located in the *Applications > Utilities* folder. Grab is useful if you need to include a cursor or a menu in your screen shot, or if you want to save your screen shot to TIFF format. 84 | 85 | ## 3.9. 如何通过Boot Camp Assistance在MacBook Pro上安装Windows? 86 | 87 | 参考:[Apple Help - Bootcamp](http://www.apple.com/support/bootcamp/) 88 | 89 | 注意下面几点: 90 | 91 | * Windows分区一旦创建并且安装了Windows,以后再次调整Windows分区大小,需要重新安装Windows。所以安装windows前事先做好容量规划。 92 | * 安装好Windows分区后,需要安装bootcamp drivers,位置在制作好的usb启动盘的bootcamp目录下 93 | * 安装了bootcamp windows以后,macbook启动时按住option键,可以选择进入mac os还是windows 94 | * 安装了bootcamp windows以后,mac os x的桌面会多出一个bootcamp磁盘,打开可以访问(读写)windows分区的文件 95 | 96 | ## 3.10. Bootcamp Windows中如何访问Mac OS X的分区? 97 | 98 | 参考: 99 | 100 | * [Why I can not see mac partition under windows installed with bootcamp?](http://apple.stackexchange.com/questions/167874/why-i-can-not-see-mac-partition-under-windows-installed-with-bootcamp) 101 | * [How to access your OS X partition from Windows in Boot Camp](http://www.simplehelp.net/2008/07/21/how-to-access-your-os-x-partition-from-windows-in-boot-camp/) 102 | 103 | Mac OS X Yosemite的Bootcamp driver中是支持Windows访问Mac OS X分区的,但是如果在Mac OS X打开了FileVault,由于FileVault会对SSD上的所有文件进行加密,这样Windows就无法访问Mac OS X分区上的文件。只要把FileVault关掉,再进入bootcamp Windows,就可以看到Mac OS X分区,但是只能读,不能写。 104 | 105 | ## 3.11. 如何让Bootcamp Windows上的触摸板操作体验和Mac OS X一样? 106 | 107 | 参考: 108 | 109 | * [3 Tools to Make Your Mac’s Hardware Work Better in Windows with Boot Camp](http://www.howtogeek.com/197485/3-tools-to-make-your-macs-hardware-work-better-in-windows-with-boot-camp/) 110 | 111 | 我的Bootcamp Windows目前使用的是Trackpad++,注意Trackpad++依赖Power Plan Assistant,安装Trackpad++前必须安装Power Plan Assistant。 112 | 113 | ## 3.12. MacOS下的Hosts文件在哪? 114 | 115 | ```zsh 116 | zsh > cat /private/etc/hosts 117 | ## 118 | # Host Database 119 | # 120 | # localhost is used to configure the loopback interface 121 | # when the system is booting. Do not change this entry. 122 | ## 123 | 127.0.0.1 localhost 124 | 255.255.255.255 broadcasthost 125 | ::1 localhost 126 | ``` 127 | 128 | ## 3.13. MacOS如何查看路由表? 129 | 130 | 执行命令`netstat -nr`。注意macos和linux的`netstat`命令不一样,注意查看文档。 131 | 132 | 133 | -------------------------------------------------------------------------------- /sre/container-learning-notes.md: -------------------------------------------------------------------------------- 1 | # Container Technology 2 | 3 | ## Docker介绍 4 | 5 | [Docker Wikipedia](https://en.wiki2.org/wiki/Docker_(software)) 6 | 7 | Docker is an open-source project that automates the deployment of applications inside software containers, by providing an additional layer of abstraction and automation of operating-system-level virtualization on Linux. Docker uses resource isolation features of the Linux kernel such as cgroups and kernel namespaces to allow independent "containers" to run within a single Linux instance, avoiding the overhead of starting and maintaining virtual machines. 8 | 9 | The Linux kernel's support for namespaces mostly isolates an application's view of the operating environment, including process trees, network, user IDs and mounted file systems, while the kernel's cgroups provide resource isolation, including the CPU, memory, block I/O and network. Since version 0.9, Docker includes the libcontainer library as its own way to directly use virtualization facilities provided by the Linux kernel, in addition to using abstracted virtualization interfaces via libvirt, LXC (Linux Containers) and systemd-nspawn. 10 | 11 | According to industry analyst firm 451 Research, "Docker is a tool that can package an application and its dependencies in a virtual container that can run on any Linux server. This helps enable flexibility and portability on where the application can run, whether on premise [sic], public cloud, private cloud, bare metal, etc." 12 | 13 | ### How is this different from virtual machines? 14 | 15 | Each virtual machine includes the application, the necessary binaries and libraries and an entire guest operating system - all of which may be tens of GBs in size. 16 | 17 | Containers include the application and all of its dependencies, but share the kernel with other containers. They run as an isolated process in userspace on the host operating system. They’re also not tied to any specific infrastructure – Docker containers run on any computer, on any infrastructure and in any cloud. 18 | 19 | ![](./img/2015/07/container-vs-vm.jpg) 20 | 21 | ### Docker's Architecture 22 | 23 | 参考:[https://docs.docker.com/introduction/understanding-docker/](https://docs.docker.com/introduction/understanding-docker/) 24 | 25 | Docker uses a client-server architecture. The Docker client talks to the Docker daemon, which does the heavy lifting of building, running, and distributing your Docker containers. Both the Docker client and the daemon can run on the same system, or you can connect a Docker client to a remote Docker daemon. The Docker client and daemon communicate via sockets or through a RESTful API. 26 | 27 | ![](./img/2015/07/architecture.svg) 28 | 29 | ## LXC, LXD, LXCFS and CGManager 30 | 31 | [Linux Containers](https://linuxcontainers.org/) 32 | 33 | linuxcontainers.org is the umbrella project behind LXC, LXD, LXCFS and CGManager. 34 | 35 | The goal is to offer a distro and vendor neutral environment for the development of Linux container technologies. 36 | 37 | ## CoreOS rkt 38 | 39 | [rkt](https://coreos.com/rkt/) 40 | 41 | rkt is the next-generation container manager for Linux clusters. Designed for security, simplicity, and composability within modern cluster architectures, rkt discovers, verifies, fetches, and executes application containers with pluggable isolation. rkt can run the same container with varying degrees of protection, from lightweight, OS-level namespace and capabilities isolation to heavier, VM-level hardware virtualization. 42 | 43 | rkt’s primary interface comprises a single executable, rather than a background daemon, and rkt leverages this design to easily integrate with existing init systems, like systemd, and with advanced cluster orchestration environments, like Kubernetes. rkt implements a modern, open, standard container format, the App Container (appc), but can also execute other container images, like those created with Docker. 44 | 45 | # Docs & Books 46 | 47 | - [Get Started with Docker for Linux](http://docs.docker.com/linux/started/) 48 | - [Get Started with Docker for Mac OS X](http://docs.docker.com/mac/started/): 需要安装boot2docker,boot2docker会安装VirtualBox、Docker、Boot2Docker management tool 49 | - [Get Started with Docker for Windows](http://docs.docker.com/windows/started/): 需要安装boot2docker,boot2docker会安装VirtualBox、Docker、Boot2Docker management tool 50 | - [Docker Docs](https://docs.docker.com/) 51 | - [The Docker Book](http://book.douban.com/subject/26285268/) 52 | - [Docker Up and Running](http://www.amazon.com/Docker-Up-Running-Karl-Matthias/dp/1491917571/ref=sr_1_1?ie=UTF8&qid=1437978051&sr=8-1&keywords=docker) 53 | - [shipyard中文文档](http://dockerpool.com/static/books/shipyard_doc/index.html) 54 | - [Docker Cheat Sheet](https://github.com/wsargent/docker-cheat-sheet/) 55 | 56 | # Resources 57 | 58 | 网站: 59 | 60 | - [Docker Hub](https://hub.docker.com/) 61 | - [DaoCloud技术Blog](http://blog.daocloud.io/) 62 | - [灵雀云Blog](http://www.alauda.cn/blog/) 63 | - [UnitedStack技术分享](https://www.ustack.com/skill-share/) 64 | 65 | 社区: 66 | 67 | - [DockOne](http://dockone.io/) 68 | 69 | 容器类产品: 70 | 71 | - [灵雀云](http://www.alauda.cn/) 72 | - [DaoCloud](http://www.daocloud.io/) 73 | - [希云cSphere](https://csphere.cn/): 企业级Docker管理平台 74 | 75 | 公有云类产品: 76 | 77 | - [阿里云](http://www.aliyun.com/) 78 | - [Window Azure CN](http://www.windowsazure.cn/) 79 | - [UnitedStack](https://www.ustack.com/) 80 | - [青云](https://www.qingcloud.com/) 81 | - [时速云](https://www.tenxcloud.com/) 82 | 83 | # Projects 84 | 85 | ## Container 86 | 87 | - [Docker Engine](https://www.docker.com/): An open platform for distributed applications for developers and sysadmins 88 | - [docker kitematic](https://kitematic.com/): Kitematic is the fastest and easiest way to start using Docker on your laptop. A completely automated process installs and configures the Docker environment on your machine in just minutes. Build and run containers through a simple, yet powerful graphical user interface (GUI). 89 | - [docker registry](https://www.docker.com/docker-registry): [源代码](https://github.com/docker/distribution), Docker Registry is an open source application dedicated to the storage and distribution of your Docker images. Its seamless architecture allows both for fine grain integration with other systems and high-level scalability. Aggressively developed, its vibrant community includes industry leaders and users using it at the core of their images distribution solutions. 90 | - [docker machine](https://www.docker.com/docker-machine): To get started with Docker, first you need to setup a Docker Engine. Docker Machine automatically sets up Docker on your computer, on cloud providers, and inside your data center. Docker Machine provisions the hosts, installs Docker Engine on them, and then configures the Docker client to talk to the Docker Engines. 91 | - [docker compose](https://www.docker.com/docker-compose): Distributed applications consist of many small applications that work together. Docker transforms these applications into individual containers that are linked together. Instead of having to build, run and manage each individual container, Docker Compose allows you to define your multi-container application with all of its dependencies in a single file, then spin your application up in a single command. Your application’s structure and configuration are held in a single place, which makes spinning up applications simple and repeatable everywhere. 92 | - [docker swarm](https://www.docker.com/docker-swarm): The nature of distributed applications requires compute resources that are also distributed. Docker Swarm provides native clustering capabilities to turn a group of Docker engines into a single, virtual Docker Engine. With these pooled resources, you can scale out your application as if it were running on a single, huge computer. 93 | 94 | ## Docker Network 95 | 96 | - [flannel](https://github.com/coreos/flannel): flannel is a virtual network that gives a subnet to each host for use with container runtimes. Platforms like Google's Kubernetes assume that each container (pod) has a unique, routable IP inside the cluster. The advantage of this model is that it reduces the complexity of doing port mapping. 97 | - [Weave](https://github.com/weaveworks/weave): Weave creates a virtual network that connects Docker containers deployed across multiple hosts and enables their automatic discovery. 98 | - [Pipework](https://github.com/jpetazzo/pipework): Software-Defined Networking for Linux Containers. Pipework lets you connect together containers in arbitrarily complex scenarios. Pipework uses cgroups and namespace and works with "plain" LXC containers (created with lxc-start), and with the awesome Docker. 99 | 100 | ## Configuration Management 101 | 102 | - [Registrator](https://github.com/gliderlabs/registrator): Service registry bridge for Docker with pluggable adapters 103 | 104 | ## Docker Host OS 105 | 106 | - [CoreOS](https://coreos.com/): CoreOS produces, maintains and utilizes open source software for Linux containers and distributed systems. Projects are designed to be composable and complement each other in order to run container-ready infrastructure. 107 | - [boot2docker](http://boot2docker.io/): boot2docker is a lightweight Linux distribution based on Tiny Core Linux made specifically to run Docker containers. It runs completely from RAM, weighs ~27MB and boots in ~5s (YMMV). 108 | - [Atomic](http://www.projectatomic.io/): Atomic是Red Hat公司发起的以应用为中心的操作系统,它可以更方便地部署和管理你的Docker容器。Atomic基于成熟的底层操作系统,保证容器运行环境的安全,并且集成了Kubernetes、Systemd等管理工具,提供容器应用部署的全套解决方案。与传统操作系统不同,Atomic经过裁剪后体积更小更容易维护,并且集成了SELinux安全技术,让Docker容器有更好的安全隔离,还有Gockpit等工具让容器的部署和管理更加方便。 109 | - [Ubuntu Core](http://ubuntu.com.cn/cloud/tools/snappy): Ubuntu Core is a new rendition of Ubuntu for the cloud with transactional updates. Ubuntu Core is a minimal server image with the same libraries as today’s Ubuntu, but applications are provided through a simpler mechanism. The snappy approach is faster, more reliable, and lets us provide stronger security guarantees for apps and users — that’s why we call them “snappy” applications. 110 | 111 | ## Container Management 112 | 113 | - [kubernetes](http://kubernetes.io/): Manage a cluster of Linux containers as a single system to accelerate Dev and simplify Ops. 114 | - [kube-ui](https://github.com/kubernetes/kube-ui): Container Cluster Manager from Google Web UI. 介绍见[这里](http://kubernetes.io/v1.0/docs/user-guide/ui.html). 115 | - [Kubernetes API client libraries](http://kubernetes.io/v1.0/docs/devel/client-libraries.html): 文档见[这里](https://godoc.org/github.com/kubernetes/kubernetes/pkg/client) 116 | 117 | ## Monitor 118 | 119 | - [cAdvisor](https://github.com/google/cadvisor): Analyzes resource usage and performance characteristics of running containers. 120 | - [heapster](https://github.com/kubernetes/heapster): Compute Resource Usage Analysis and Monitoring of Container Clusters 121 | 122 | ## Data Volume Management 123 | 124 | - [ClusterHQ Flocker](https://github.com/ClusterHQ/flocker): Flocker is an open-source Container Data Volume Manager for your Dockerized applications. 125 | 126 | ## Image Build 127 | 128 | - [dockramp](https://github.com/jlhawn/dockramp): Docker 1.8.0 will introduce a new API endpoint for copying files and directories into a container. With this addition, anyone can now implement their own build system using the Docker Remote API. Dockramp is the first proof of concept for an alternative to docker build. 129 | - [packer](https://packer.io/): Packer is a tool for creating machine and container images for multiple platforms from a single source configuration. 130 | 131 | ## Continous Integration 132 | 133 | - [Drone](https://github.com/drone/drone): Drone是一个使用Go语言编写的基于Docker的持续集成系统。Drone可以快速提供隔离的虚拟环境编译测试,而且根据需要保留结果,比使用VM更加简洁有效。如何使用 Drone和Docker搭建全功能的CI服务器可以参考此文。使用Drone搭建CI服务器后,代码可以不离开公司网络即可测试,这非常适合大公司的保密原则,另外,由于Drone基于Docker使用,所以部署到生产环境也非常容易。 134 | 135 | ## Continuous Delivery 136 | 137 | - [wharf](https://github.com/containerops/wharf): ContainerOps is all about product workflow. Wharf builds and runs a container image you defined whenever new code is being pushed, along with corresponding dependence system. But it's not all, the image will also work with continuous integration, or continuous deployment with Rocket, LXC or Atomic, etc. Wharf is focusing on the continuous changes from version control system to production environment. 138 | 139 | ## Visualization 140 | 141 | - [dockviz](https://github.com/justone/dockviz): Visualizing docker data 142 | 143 | ## Developer Tools 144 | 145 | - [Vagrant](https://www.vagrantup.com/): Vagrant 是一个基于 Ruby 的工具,用于创建和部署虚拟化开发环境。它使用 Oracle 的开源 VirtualBox 虚拟化系统,使用 Chef 创建自动化虚拟环境。 146 | - [Panamax](http://panamax.io/): Panamax是一个CenturyLink开源的Docker管理工具,用户可以把多个Docker容器组合为模板并分享到GitHub。Panamax中的应用是由基于Docker镜像的独立服务组合而成,这些Docker镜像来自Docker Hub或者其它的Docker registry。Web的用户界面允许每个服务可以连接到其他服务,并可以配置环境变量、端口绑定、卷。另外也可以添加自定义的Docker运行命令。当这些服务组合在一起成为一个具备完整功能的应用后就可以作为一个模板保存到GitHub。Panamax的最初版本运行在由Vagrant管理的VirtualBox上,由于Vagrant的限制,目前Panamax仅可运行在Mac和Linux的VirtualBox上,并不支持其他虚拟化平台。CenturyLink的云平台也将会支持Panamax。 147 | 148 | ## PaaS 149 | 150 | - [Flynn](https://flynn.io/): Flynn是一个使用Go语言编写的开源PaaS平台,Flynn使用模块化的设计,任何一个模块都可以独立的进行修改、升级和替换。Flynn的目标是简化分布式环境中应用的部署和维护,通过使用git push命令,Flynn就可以将应用部署到Docker,从而省去了复杂的配置和操作。Flynn的架构大致分为两层,Layer 0是底层的资源层,提供分布式配置、任务调度、服务发现、主机隔离等基础功能;Layer 1基于Layer 0构建了一个用于集群中管理、部署、扩展服务的系统,主要包括管理API/客户端、Git接收器、数据存储、路由。Flynn目前仍在开发中,尚未发布稳定版,但已经获得了很多公司的资助,它被称为是下一代的开源PaaS平台。 151 | - [Deis](http://deis.io/): Deis也是一个支持共有云和私有云的开源PaaS系统,Deis基于Docker和CentOS构建了一个类Heroku的PaaS系统。Deis主要设计用来和不同的云提供商进行交互,目前支持 Rackspace、EC2、 DigitalOcean、Google Compute Engine、Bare-Metal。Deis使用out-of-the-box的方式支持Ruby、Python、Node.js、Java、Clojure、Scala、Play、PHP、Perl、Dart和Go语言,同样支持git push部署。Flynn和Deis都是两个基于Docker的云计算微PaaS技术,关于它们的区别,可以参考这篇文章,作者从架构、实现方式等多方面对二者进行了比较,Deis目前也尚未发布1.0版本,但在GitHub上已经有2000+的star量。 152 | - [Dokku](https://github.com/progrium/dokku): Dokku是一个迷你版的Heroku,基于Docker使用100行左右的Bash代码编写,简单的安装和配置后,即可使用Git命令将应用部署到本地的Dokku平台(当使用git push命令的时候,Dokku会使用buildpack检测应用,然后再部署)。Dokku实际上相当于一个单机版的Heroku,它包含4个组件,分别是Docker、Buildstep、pluginhook、sshcommand。Dokku目前支持Node.js、Ruby、Python。 153 | - [OpenShift Origin](http://www.openshift.org/): OpenShift 3 is built around a core of application containers powered by Docker, with orchestration and management provided by Kubernetes, on a foundation of Atomic and Enterprise Linux. OpenShift Origin is the upstream community project that brings it all together along with extensions, to accelerate application development and deployment. 154 | 155 | ## IaaS 156 | 157 | - [OpenStack](http://www.openstack.org/): Open source software for creating private and public clouds. 158 | - [Apache CloudStack](http://cloudstack.apache.org/): Apache CloudStack is open source software designed to deploy and manage large networks of virtual machines, as a highly available, highly scalable Infrastructure as a Service (IaaS) cloud computing platform. CloudStack is used by a number of service providers to offer public cloud services, and by many companies to provide an on-premises (private) cloud offering, or as part of a hybrid cloud solution. 159 | - [Zstack](http://zstack.org/cn/): ZStack是下一代开源的云计算IaaS(基础架构即服务)软件。它主要面向的是未来的智能数据中心, 通过提供全完善的APIs来管理包括计算、存储和网络在内的数据中心的各种资源。 用户可以基于ZStack构建自己的智能数据中心,也可以在稳定的ZStack之上搭建灵活的云应用场景, 例如VDI(虚拟桌面基础架构),PaaS(平台即服务),SaaS(软件即服务)等等。 160 | 161 | ## Virtual Machine OS 162 | 163 | - [Clear Linux](https://clearlinux.org/): The Clear Linux* Project for Intel® Architecture is a project that is building a Linux OS distribution for various cloud use cases. The goal of Clear Linux OS is to showcase the best of Intel Architecture technology, from low-level kernel features to more complex items that span across the entire operating system stack. 164 | 165 | ## Virtual Machine Host 166 | 167 | - [Xen](http://www.xenproject.org/): Xen 是一个开放源代码虚拟机监视器,由剑桥大学开发。它打算在单个计算机上运行多达100个满特征的操作系统。操作系统必须进行显式地修改(“移植”)以在Xen上运行(但是提供对用户应用的兼容性)。这使得Xen无需特殊硬件支持,就能达到高性能的虚拟化。 168 | - [XenServer](http://xenserver.org/): XenServer is the leading open source virtualization platform, powered by the Xen Project hypervisor and the XAPI toolstack. It is used in the world's largest clouds and enterprises. 169 | - [Kernel Virtual Machine](http://www.linux-kvm.org/page/Main_Page): KVM (for Kernel-based Virtual Machine) is a full virtualization solution for Linux on x86 hardware containing virtualization extensions (Intel VT or AMD-V). It consists of a loadable kernel module, kvm.ko, that provides the core virtualization infrastructure and a processor specific module, kvm-intel.ko or kvm-amd.ko. 170 | - [Hyper](https://hyper.sh/): Hyper 是一种 App-Centric 的虚拟化技术,我们完全摒弃了传统虚机上必须和物理机一样,运行一个完整 OS 这种看似显然的假设,我们让Docker Image 直接运行在 Hypervisor 上。我们让一组容器直接启动在 hypervisor 上的时间达到 350 毫秒,并且还在进一步优化。而且所有这些,都是“开箱即得的”。当然有人会问,有了容器为什么还要虚机。诚然,虚机并不是所有人都需要的,但是,虚机天然具备更好的隔离性;虚拟机也仍然存在于很多企业应用的协议栈中,这样一个依赖更少、开箱即得,而且还带有 Pod、persist mode 等附加丰富特性的应用,是不少场景中都需要的。而我们最期待的,就是去引爆新的容器服务 —— CaaS。.传统虚拟机的问题其实在于过于刻意模仿物理机,刻意要承载完整操作系统,启动一台虚拟机要若干秒,甚至几分钟,Image 有若干GB,加载传播都很慢,但其实根本没有这个必要,Hyper希望兼取两者的强项 171 | - [OpenVZ](http://openvz.org/Main_Page): OpenVZ is container-based virtualization for Linux. OpenVZ creates multiple secure, isolated Linux containers (otherwise known as VEs or VPSs) on a single physical server enabling better server utilization and ensuring that applications do not conflict. Each container performs and executes exactly like a stand-alone server; a container can be rebooted independently and have root access, users, IP addresses, memory, processes, files, applications, system libraries and configuration files. 172 | 173 | ## Network Virtualization 174 | 175 | - [Open vSwitch](http://openvswitch.org/): Open vSwitch is a production quality, multilayer virtual switch licensed under the open source Apache 2.0 license. It is designed to enable massive network automation through programmatic extension, while still supporting standard management interfaces and protocols (e.g. NetFlow, sFlow, IPFIX, RSPAN, CLI, LACP, 802.1ag). In addition, it is designed to support distribution across multiple physical servers similar to VMware's vNetwork distributed vswitch or Cisco's Nexus 1000V. 176 | - [Data Plane Development Kit](http://www.dpdk.org/): DPDK is a set of libraries and drivers for fast packet processing. It was designed to run on any processors. The first supported CPU was Intel x86 and it is now extended to IBM Power 8, EZchip TILE-Gx and ARM. It runs mostly in Linux userland. A FreeBSD port is available for a subset of DPDK features. 177 | - [Open Networking Foundation](https://www.opennetworking.org/index.php): Foundation about SDN and Open Flow 178 | 179 | ## Docker on OSX 180 | 181 | - [Dlite](https://github.com/nlf/dlite): The simplest way to use Docker on OSX. 182 | 183 | # FAQ 184 | 185 | ## How to install and uninstall Docker in Ubuntu 186 | 187 | ```sh 188 | # install docker 189 | $ curl -fsSL https://get.docker.com/ | sh 190 | 191 | # Uninstall docker and it's dependencies 192 | $ sudo apt-get remove --auto-remove docker 193 | 194 | # Purging docker, config/data and it's dependencies 195 | $ sudo apt-get purge --auto-remove docker-engine 196 | 197 | # restart to start docker server 198 | $ sudo shutdown -r 0 199 | ``` 200 | 201 | ## Use docker hub mirror to speed up download docker image 202 | 203 | ```sh 204 | $ echo "DOCKER_OPTS=\"\$DOCKER_OPTS --registry-mirror=http://6de9fa0c.m.daocloud.io\"" | sudo tee -a /etc/default/docker 205 | $ sudo service docker restart 206 | ``` 207 | 208 | Refer to: 209 | 210 | - [DaoCloud 加速器和 Toolbox](http://docs.daocloud.io/faq/what-is-daocloud-accelerator) 211 | 212 | 213 | ## How to make docker daemon accept connections incoming from any network interface 214 | 215 | 参考[Docker client communicating with docker host](http://stackoverflow.com/questions/26481258/docker-client-communicating-with-docker-host) 216 | 217 | Using the -H tcp://127.0.0.1:5555 docker daemon option on the UbuntuA machine will instruct docker to bind to the loopback network interface (127.0.0.1). As a result it will only accept connections originating from the UbuntuA machine. 218 | 219 | If you want to accept connections incoming from any network interface use -H tcp://0.0.0.0:5555. Be aware that anyone that would be able to connect to your UbuntuA machine on port 5555 will be able to control your docker host. You need to protect it with firewall rules to allow only UbuntuB to connect to UbuntuA on port 5555. 220 | 221 | ## 在Mac OS X中,启动VirutalBox VM中的mongodb容器,挂载Mac OS X本地数据卷,启动mongod报“fsync: Invalid argument”的错误 222 | 223 | 参考: 224 | 225 | - ["Fatal Assertion" with "fsync: Invalid Argument"](https://github.com/mvertes/docker-alpine-mongo/issues/1) 226 | - [can not use external volume](https://github.com/docker-library/mongo/issues/30) 227 | - [OFFICIAL REPOSITORY - mongo](https://hub.docker.com/_/mongo/) 228 | - [How to set docker mongo data volume](http://stackoverflow.com/questions/35400740/how-to-set-docker-mongo-data-volume) 229 | 230 | WARNING: because MongoDB uses memory mapped files it is not possible to use it through vboxsf to your host (vbox bug). VirtualBox shared folders are not supported by MongoDB (see docs.mongodb.org and related jira.mongodb.org bug). This means that it is not possible with the default setup using Docker Toolbox to run a MongoDB container with the data directory mapped to the host. 231 | -------------------------------------------------------------------------------- /windows/img/powershell_dsc_pull_push_mode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EthanCai/linux-system-ops/0bcfd206908ff3293a17c782ddb8a3aac1f23752/windows/img/powershell_dsc_pull_push_mode.png -------------------------------------------------------------------------------- /windows/img/powershellgetArchitecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EthanCai/linux-system-ops/0bcfd206908ff3293a17c782ddb8a3aac1f23752/windows/img/powershellgetArchitecture.png -------------------------------------------------------------------------------- /windows/powershell-learning-notes.md: -------------------------------------------------------------------------------- 1 | - [1. 说明](#1-说明) 2 | - [2. PowerShell Introduction](#2-powershell-introduction) 3 | - [3. Advantages](#3-advantages) 4 | - [4. Learning Videos](#4-learning-videos) 5 | - [4.1. Getting Started with PowerShell 3.0 Jump Start](#41-getting-started-with-powershell-30-jump-start) 6 | - [4.1.1. URL](#411-url) 7 | - [4.1.2. 课程目录](#412-课程目录) 8 | - [4.1.3. 内容概要](#413-内容概要) 9 | - [4.2. Advanced Tools & Scripting with PowerShell 3.0 Jump Start](#42-advanced-tools--scripting-with-powershell-30-jump-start) 10 | - [4.2.1. URL](#421-url) 11 | - [4.2.2. 课程目录](#422-课程目录) 12 | - [4.2.3. 内容概要](#423-内容概要) 13 | - [4.3. Getting Started with PowerShell Desired State Configuration (DSC)](#43-getting-started-with-powershell-desired-state-configuration-dsc) 14 | - [4.3.1. URL](#431-url) 15 | - [4.3.2. 课程目录](#432-课程目录) 16 | - [4.3.3. 内容概要](#433-内容概要) 17 | - [4.3.3.1. 01 | Get Getting ready for DSC](#4331-01--get-getting-ready-for-dsc) 18 | - [4.3.3.2. 02 | Performing a Push deployment](#4332-02--performing-a-push-deployment) 19 | - [4.3.3.3. 03 | Configuring Pull Servers for Deployment​](#4333-03--configuring-pull-servers-for-deployment) 20 | - [4.3.3.4. 04 | Deploying Configurations Using a Pull Server](#4334-04--deploying-configurations-using-a-pull-server) 21 | - [4.3.3.5. 05 | Resource roundup](#4335-05--resource-roundup) 22 | - [4.3.3.6. 06 | Writing better configurations](#4336-06--writing-better-configurations) 23 | - [4.3.3.7. 07 | DSC and Linux](#4337-07--dsc-and-linux) 24 | - [4.4. Advanced PowerShell Desired State Configuration (DSC) and Custom Resources](#44-advanced-powershell-desired-state-configuration-dsc-and-custom-resources) 25 | - [4.4.1. URL](#441-url) 26 | - [4.4.2. 课程目录](#442-课程目录) 27 | - [4.4.3. 内容概要](#443-内容概要) 28 | - [4.4.3.1. 01 | Getting Ready for DSC Custom Resources](#4431-01--getting-ready-for-dsc-custom-resources) 29 | - [4.4.3.2. 02 | Implementing and Testing Custom Resources](#4432-02--implementing-and-testing-custom-resources) 30 | - [4.4.3.3. 03 | Packaging and Deploying Custom Resources](#4433-03--packaging-and-deploying-custom-resources) 31 | - [4.4.3.4. 04 | Using Classes to Build a Custom Resource](#4434-04--using-classes-to-build-a-custom-resource) 32 | - [4.4.3.5. 05 | Enhancing Your Custom Resources](#4435-05--enhancing-your-custom-resources) 33 | - [4.5. Windows Server 2012 R2 : 服务器管理和自动化](#45-windows-server-2012-r2--服务器管理和自动化) 34 | - [4.5.1. URL](#451-url) 35 | - [4.5.2. 课程目录](#452-课程目录) 36 | - [4.5.3. 内容概要](#453-内容概要) 37 | - [5. Blog Articles](#5-blog-articles) 38 | - [6. Third-Party Utilities](#6-third-party-utilities) 39 | - [6.1. PowerShell Modules](#61-powershell-modules) 40 | - [6.2. Utilities](#62-utilities) 41 | - [7. Websites about PowerShell](#7-websites-about-powershell) 42 | - [7.1. In China](#71-in-china) 43 | - [7.2. Out of China](#72-out-of-china) 44 | - [8. Books](#8-books) 45 | - [9. FAQ](#9-faq) 46 | - [9.1. Windows PowerShell Profiles文件保存在什么位置?](#91-windows-powershell-profiles文件保存在什么位置) 47 | - [9.2. PowerShell Remote Trouble Shooting](#92-powershell-remote-trouble-shooting) 48 | - [9.3. PowerShell展示本地及远程电脑的driver](#93-powershell展示本地及远程电脑的driver) 49 | - [9.4. Windows 10的Microsoft Edge浏览器默认不能访问localhost website,如果解决?](#94-windows-10的microsoft-edge浏览器默认不能访问localhost-website如果解决) 50 | - [9.5. Write-Host和Write-Output有什么区别?](#95-write-host和write-output有什么区别) 51 | - [9.6. 如何查看所有的WMI Classes?](#96-如何查看所有的wmi-classes) 52 | - [9.7. 如何连接局域网中不在域的PC?](#97-如何连接局域网中不在域的pc) 53 | - [9.8. PowerShell中Cmdlet和Function有什么区别?](#98-powershell中cmdlet和function有什么区别) 54 | - [9.9. ConEmu中PowerShell Shell输入中文字符时字符重叠在一起,如何解决?](#99-conemu中powershell-shell输入中文字符时字符重叠在一起如何解决) 55 | - [9.10. Windows和Linux的dynamic port range动态端口范围是多少?](#910-windows和linux的dynamic-port-range动态端口范围是多少) 56 | 57 | 58 | # 1. 说明 59 | 60 | 这个repository中的内容包括我学习PowerShell过程中,浏览过的文章、书籍、学习视频、学习过程中写的一些练习脚本。通过系统化的记录学习的内容,希望能够加深对各种知识理解。 61 | 62 | 网络上的已经有很多关于PowerShell的文章和教程,但是过于分散,而且PowerShell发展比较快,也使很多文章和教程不能涵盖PowerShell最新的发展。所以决定把学习的内容记录下来。 63 | 64 | 建议把这个文章当作一个学习笔记或者手册,而不要当作一个教程。写教程需要花费更多的时间和精力,我比较懒,只希望花最少的时间掌握PowerShell,所以不想花太多时间在书写教程这件工作上。 65 | 66 | 希望能对你学习PowerShell有所帮助。 67 | 68 | 备注:[windows-command-line-utilities.md](./windows-command-line-utilities.md)是一些常用的windows命令行命令和工具的用法。 69 | 70 | # 2. PowerShell Introduction 71 | 72 | Please read [PowerShell-Wikipedia](https://en.wiki2.org/wiki/Windows_PowerShell) first. Following is the contents: 73 | 74 | 1. Background 75 | 1. Design: cmdlet,pipeline,scripting,hosting 76 | 1. Versions:1.0,2.0,3.0,4.0,5.0 77 | 1. Comparison of cmdlet with similar commands 78 | 1. File extensions 79 | 1. Application Support 80 | 1. Alternative implementation 81 | 82 | # 3. Advantages 83 | 84 | - 语言本身: 85 | - 丰富的命令(或者功能),以及扩展性 86 | - 管道机制,功能倍增器 87 | - 语法是否简单,完备:比如是否支持变量、函数、分支、循环、异常处理、闭包等等 88 | - 方便易用的帮助,比如man,get-help 89 | - 其它方面: 90 | - 和Shell集成:反面的例子比如cscript.exe上执行的VBScript和Jscript 91 | - 包管理机制(类似Chocolatey,OneGet,APT-GET,homebrew),这方面期待powershell 5.0推出的OneGet 92 | - 互操作性(interoperable):比如.NET程序中执行PowerShell脚本 93 | - 广泛的支持(SQL Server,Exchange Server等) 94 | 95 | # 4. Learning Videos 96 | 97 | ## 4.1. Getting Started with PowerShell 3.0 Jump Start 98 | 99 | ### 4.1.1. URL 100 | - [Getting Started with PowerShell 3.0 Jump Start](https://www.microsoftvirtualacademy.com/en-US/training-courses/getting-started-with-powershell-3-0-jump-start-8276) 101 | - [快速入门 : PowerShell 3.0](http://www.microsoftvirtualacademy.com/training-courses/getting-started-with-powershell-3-0-jump-start-cn) 102 | - [youku上的观看地址](http://www.youku.com/playlist_show/id_20773431.html?sf=10201) 103 | 104 | ### 4.1.2. 课程目录 105 | - Don't fear the Shell 106 | - The help System 107 | - The pipeline: getting connected & extending the shell 108 | - Objects for the Admin 109 | - The pipeline: deeper 110 | - The PowerShell in the shell: remoting 111 | - Getting prepared for automation 112 | - Automation in scale: remoting 113 | - Introducing scripting and toolmaking 114 | - Recommended Resources & Next Steps for PowerShell 3.0 115 | 116 | ### 4.1.3. 内容概要 117 | 118 | **The Help System** 119 | 120 | ```PowerShell 121 | # 下载帮助文档或者更新本地的帮助文档 122 | PS > update-help 123 | 124 | # 查找名称中包含service的cmdlet(case-insensitive) 125 | PS > Get-Help *service* 126 | 127 | # 查找名称以g开头,包含service的cmdlet(case-insensitive) 128 | PS > Get-Help g*service* 129 | 130 | # 查看某个cmdlet的帮助,阅读并理解帮助内容 131 | PS > Get-Help Get-Service 132 | 133 | PS > Get-Help Get-Service -Full 134 | PS > Get-Help Get-Service -Online 135 | PS > Get-Help Get-Service -Examples 136 | PS > Get-Help Get-Service -ShowWindow 137 | 138 | # 查看所有的HelpFile列表 139 | PS > Get-Help about* 140 | PS > Get-Help * -Category HelpFile 141 | ``` 142 | 143 | **Pipleline** 144 | 145 | ```PowerShell 146 | # 停止名称叫bits的service 147 | PS > Get-Service -name bits | Stop-Service 148 | 149 | # 启动名称叫bits的service,并显示结果 150 | PS > Get-Service -name bits | Start-Service -PassThru 151 | 152 | # 把所有的系统服务输出到csv文件 153 | PS > Get-Service | export-csv -Path c:\service.csv 154 | 155 | # 把所有的进程输出到XML文件 156 | PS > Get-Process | Export-Clixml -Path c:\process.xml 157 | 158 | # 运行notepad,然后执行下面的命令比较两个对象的差别 159 | PS > Compare-Object -ReferenceObject (Import-Clixml C:\process.xml) -DifferenceObject (Get-Process) -Property Name 160 | 161 | Name SideIndicator 162 | ---- ------------- 163 | notepad => 164 | 165 | # 把所有的service的name、status输出到html文件 166 | PS > Get-Service | ConvertTo-Html -Property Name,Status | Out-File c:\service.html 167 | 168 | # 通过-whatif查看命令执行效果,实际不执行操作 169 | PS > Get-Service | Stop-Service -WhatIf 170 | 171 | # 通过-confirm要求用户确认操作 172 | PS > Get-Service -name bits | Stop-Service -Confirm 173 | 174 | # 获得加载的Module 175 | PS > Get-Module 176 | 177 | # 获得所有的Module,无论加载与否 178 | PS > Get-Module -ListAvailable 179 | 180 | # 获得某个module的所有cmdlet 181 | PS > Get-Command -Module Microsoft.PowerShell.Core 182 | 183 | # 当某个module未加载,如果你执行这个module的cmdlet,PowerShell会自动加载这个module 184 | ``` 185 | 186 | **Objects for the admin** 187 | 188 | ```PowerShell 189 | # 获得handles大于900的进程,并排序展示出来 190 | PS > Get-Process | where Handles -gt 900 | sort handles -Descending 191 | 192 | # 获得某个service的成员 193 | PS > Get-Service -Name BITS | Get-Member 194 | 195 | # 获得service的name、status 196 | PS > get-service | Select-Object -Property Name, Status 197 | 198 | # 自定义property的格式 199 | PS > Get-WmiObject -Class win32_logicalDisk | ` 200 | >>> Select-Object -Property __Server, Name, 201 | >>> @{n='FreeGB';e={$_.Freespace /1Gb -as [int]}} | 202 | >>> Format-Table -AutoSize 203 | 204 | __SERVER Name FreeGB 205 | -------- ---- ------ 206 | WIN-LRSDTAVTAR1 A: 0 207 | WIN-LRSDTAVTAR1 C: 55 208 | WIN-LRSDTAVTAR1 D: 97 209 | WIN-LRSDTAVTAR1 E: 0 210 | 211 | # 把最近的5条System日志输出到html文件中 212 | PS > Get-EventLog -LogName System -Newest 5 | Select-Object -Property EventID, TimeWritten, Message | Sort -Property TimeWritten | ConvertTo-Html | Out-File c:\elog.html 213 | 214 | # xml操作 215 | PS > $x = [xml](cat c:\test.xml) 216 | PS > $x.PLAY 217 | PS > $x.PLAY.ACT 218 | PS > $x.PLAY.ACT[0] 219 | PS > $x.PLAY.ACT.SCENE.SPEECH | group speeker | sort count 220 | 221 | # $_用法 222 | PS > Get-Service | Where-Object -FilterScript { $_.Status -eq "Running" -and $_.Name -like "b*" } 223 | PS > Get-Service | Where { $_.Status -eq "Running" -and $_.Name -like "b*" } 224 | PS > Get-Service | ?{ $_.Status -eq "Running" -and $_.Name -like "b*" } 225 | ``` 226 | 227 | **Pipleline: deeper** 228 | 229 | ```PowerShell 230 | # 理解下面的命令为什么都能执行成功 231 | PS > Get-Service *bits* | Start-Service -PassThru 232 | 233 | PS > "BITS" | Start-Service -PassThru 234 | 235 | PS > $h = @{ Name = "BITS"} 236 | PS > $h | Start-Service -PassThru 237 | 238 | PS > $h = @{ Name = "BITS"} 239 | PS > $ho = New-Object -TypeName psobject -Property $h 240 | PS > $ho | Start-Service -PassThru 241 | 242 | # 理解-ExpandProperty的作用 243 | # 下面命令返回的是ServiceController 244 | PS > get-service | Select-Object -Property Name 245 | 246 | # 下面命令返回的是String 247 | PS > get-service | Select-Object -ExpandProperty Name 248 | 249 | ``` 250 | 251 | **PowerShell Remoting** 252 | 253 | 注意: 254 | 255 | - Windows Server 2012 R2 ServerCore自动启用了PowerShell Remoting 256 | 257 | 258 | ```PowerShell 259 | # Enable PowerShell Remoting 260 | PS > Enable-PSRemoting 261 | 262 | # WinRM Service的组策略路径在"Computer Configuration/Policies/Administrative Templates/Windows Components/Windows Remote Management(WinRM)/WinRM Service" 263 | 264 | # One-to-one, interactive 265 | PS > Enter-PSSession -ComputerName dc 266 | 267 | # One-to-many, interactive 268 | PS > Invoke-Command -ComputerName 192.168.1.105 -ScriptBlock { ls c:\ } -Credential administrator 269 | 270 | # PowerShell Web Access 271 | PS > Get-WindowsFeatures *powershell* #View all features about powershell 272 | PS > Install-WindowsFeature WindowsPowerShellWebAccess 273 | PS > Get-Help *pswa* 274 | 275 | Name Category Module Synopsis 276 | ---- -------- ------ -------- 277 | Get-PswaAuthorizationRule Cmdlet PowerShellWebAccess Get-PswaAuthorizationRule... 278 | Add-PswaAuthorizationRule Cmdlet PowerShellWebAccess Add-PswaAuthorizationRule... 279 | Remove-PswaAuthorizationRule Cmdlet PowerShellWebAccess Remove-PswaAuthorizationRule... 280 | Test-PswaAuthorizationRule Cmdlet PowerShellWebAccess Test-PswaAuthorizationRule... 281 | Install-PswaWebApplication Function PowerShellWebAccess ... 282 | Uninstall-PswaWebApplication Function PowerShellWebAccess ... 283 | 284 | PS > Install-PswaWebApplication -UseTestCertificate 285 | PS > Add-PswaAuthorizationRule * * * #Don't use this in product environment 286 | ``` 287 | 288 | **Getting Prepared for automation** 289 | 290 | ```PowerShell 291 | # 执行策略包括: 292 | # Restricted 293 | # Unrestricted 294 | # AllSigned 295 | # RemoteSigned 296 | # Bypass 297 | # Undefined 298 | 299 | PS > Get-ExecutionPolicy 300 | 301 | # 可以通过注册表修改PowerShell的执行策略,路径"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" 302 | # 也可以通过组策略来修改PowerShell执行策略,路径"Computer Configuration | Administrative Templates | Windows Components | Windows PowerShell" 303 | 304 | # 查看PSDrive 305 | PS > Get-PSDrive 306 | 307 | Name Used (GB) Free (GB) Provider Root CurrentLocation 308 | ---- --------- --------- -------- ---- --------------- 309 | A FileSystem A:\ 310 | Alias Alias 311 | C 44.68 55.32 FileSystem C:\ Windows\system32 312 | Cert Certificate \ 313 | D 2.62 97.25 FileSystem D:\ 314 | E FileSystem E:\ 315 | Env Environment 316 | Function Function 317 | HKCU Registry HKEY_CURRENT_USER 318 | HKLM Registry HKEY_LOCAL_MACHINE 319 | Variable Variable 320 | WSMan WSMan 321 | 322 | # 下面是一个测试签名的例子 323 | 324 | PS > Set-ExecutionPolicy Allsigned #修改执行策略 325 | PS > D:\test.ps1 #执行测试脚本,应该提示没有签名 326 | PS > #从https://gallery.technet.microsoft.com/scriptcenter/Self-signed-certificate-5920a7c6下载创建证书的PS function,保存到D:\ 327 | PS > . D:\New-SelfSignedCertificateEx.ps1 #执行脚本并在当前session保留脚本中的function 328 | PS > New-SelfsignedCertificateEx -Subject "CN=Test Code Signing" -EKU "Code Signing" -KeySpec "Signature" -KeyUsage "DigitalSignature" -FriendlyName "Test code signing" -NotAfter ([DateTime]::Now.AddYears(5)) #创建证书 329 | PS > $certs = (dir Cert:\CurrentUser\my) #获得创建的证书 330 | PS > Set-AuthenticodeSignature -FilePath D:\test.ps1 -Certificate $certs[0] #对脚本进行签名 331 | PS > D:\test.ps1 #正常执行 332 | PS > Set-ExecutionPolicy Unrestricted #改回执行策略 333 | 334 | 335 | # 打印消息 336 | PS > Write-Output "hello" | Get-Member 337 | PS > Write-Host "hello" #Write-Host不会输出到pipeline 338 | PS > Write-Warning "Warning Message" 339 | PS > Write-Error "Error Message" 340 | 341 | # Write-Debug,Write-Verbose一般用于 342 | ``` 343 | 344 | **Automation in scale: remoting** 345 | 346 | ```PowerShell 347 | # 创建PSSession 348 | PS > $session = New-PSSession -ComputerName dc 349 | PS > Invoke-Command -Session $session { $var=2 } 350 | PS > Invoke-Command -Session $session { $var } 351 | 352 | # 通过Connect-PSSession和Disconnect-PSSession连接和断开PSSession,用法见Technet文档 353 | 354 | # 度量执行时间 355 | PS > Measure-Command { Invoke-Command -Session $session { dir c:\ } } 356 | 357 | # 通过Import-PSSession加载远程OS的module 358 | PS > Import-PSSession -module ActiveDirectory -prefix remote -session $session 359 | 360 | # 关闭PSSession 361 | PS > Remove-PSSession $session 362 | ``` 363 | 364 | **Introducing scripting and toolmaking** 365 | 366 | ```PowerShell 367 | # 编写function 368 | function Do-Something { 369 | <# 370 | .SYNOPSIS 371 | Describe the function here 372 | .DESCRIPTION 373 | Describe the function in more detail 374 | .EXAMPLE 375 | Give an example of how to use it 376 | .EXAMPLE 377 | Give another example of how to use it 378 | .PARAMETER computername 379 | The computer name to query. Just one. 380 | .PARAMETER logname 381 | The name of a file to write failed computer names to. Defaults to errors.txt. 382 | #> 383 | [CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact='Low')] 384 | param 385 | ( 386 | [Parameter(Mandatory=$True, 387 | ValueFromPipeline=$True, 388 | ValueFromPipelineByPropertyName=$True, 389 | HelpMessage='What computer name would you like to target?')] 390 | [Alias('host')] 391 | [ValidateLength(3,30)] 392 | [string[]]$computername, 393 | 394 | [string]$logname = 'errors.txt' 395 | ) 396 | 397 | begin { 398 | write-verbose "Deleting $logname" 399 | del $logname -ErrorActionSilentlyContinue 400 | } 401 | 402 | process { 403 | 404 | write-verbose "Beginning process loop" 405 | 406 | foreach ($computer in $computername) { 407 | Write-Verbose "Processing $computer" 408 | if ($pscmdlet.ShouldProcess($computer)) { 409 | # use $computer here 410 | } 411 | } 412 | } 413 | } 414 | 415 | # 查看PSModulePath,此变量配置在windows系统环境变量中 416 | PS > $env:PSModulePath 417 | 418 | # 创建自己的Module,注意事项: 419 | # 1. Module必须包含一个psm1文件,且文件名称必须和文件夹名称一致 420 | # 2. Module文件夹必须放在$env:PSModulePath的任何一个目录中 421 | ``` 422 | 423 | ## 4.2. Advanced Tools & Scripting with PowerShell 3.0 Jump Start 424 | 425 | ### 4.2.1. URL 426 | 427 | - [Advanced Tools & Scripting with PowerShell 3.0 Jump Start](http://www.microsoftvirtualacademy.com/training-courses/advanced-tools-scripting-with-powershell-3-0-jump-start) 428 | - [PowerShell 3.0 高级工具和脚本](http://www.microsoftvirtualacademy.com/training-courses/821) 429 | 430 | ### 4.2.2. 课程目录 431 | - Get Started Scripting 432 | - PowerShell’s Scripting Language 433 | - Simple Scripts and Functions 434 | - Advanced Functions 435 | - More on Parameters 436 | - Writing Help 437 | - Error Handling 438 | - Tools That Make Changes 439 | - Script and Manifest Modules 440 | - Recommended Resources & Next Steps for Advanced PowerShell 3.0 441 | 442 | ### 4.2.3. 内容概要 443 | 444 | **PowerShell's Scripting Language** 445 | 446 | 参考:[幻灯片展示](https://sg1b-powerpoint.officeapps.live.com/p/PowerPointFrame.aspx?PowerPointView=SlideShowView&ui=en-US&rs=en-US&WOPISrc=http%3A%2F%2Fsg1b-15-view-wopi%2Ewopi%2Elive%2Enet%3A808%2Foh%2Fwopi%2Ffiles%2F%40%2FwFileId%3FwFileId%3Dhttps%253A%252F%252Fcp%252Dmlxprod%252Dstatic%252Emicrosoft%252Ecom%253A443%252F05373%252D1000%252Fen%252Dus%252Fcontent%252Fcontent%255Flnzipuwy%255F8404984382%252F04242015062214%252Epptx&access_token_ttl=0&wdSlideId=389&wdModeSwitchTime=1435884253645) 447 | 448 | **Simple Scripts and Functions** 449 | 450 | 参考:[幻灯片展示](https://sg1b-powerpoint.officeapps.live.com/p/PowerPointFrame.aspx?PowerPointView=SlideShowView&ui=en-US&rs=en-US&WOPISrc=http%3A%2F%2Fsg1b-15-view-wopi%2Ewopi%2Elive%2Enet%3A808%2Foh%2Fwopi%2Ffiles%2F%40%2FwFileId%3FwFileId%3Dhttps%253A%252F%252Fcp%252Dmlxprod%252Dstatic%252Emicrosoft%252Ecom%253A443%252F05373%252D1000%252Fen%252Dus%252Fcontent%252Fcontent%255Flle3bvwy%255F9304984382%252F04242015062245%252Epptx&access_token_ttl=0&wdSlideId=316&wdModeSwitchTime=1435884447831) 451 | 452 | **Advanced Functions** 453 | 454 | 参考:[幻灯片展示](https://sg1b-powerpoint.officeapps.live.com/p/PowerPointFrame.aspx?PowerPointView=SlideShowView&ui=en-US&rs=en-US&WOPISrc=http%3A%2F%2Fsg1b-15-view-wopi%2Ewopi%2Elive%2Enet%3A808%2Foh%2Fwopi%2Ffiles%2F%40%2FwFileId%3FwFileId%3Dhttps%253A%252F%252Fcp%252Dmlxprod%252Dstatic%252Emicrosoft%252Ecom%253A443%252F05373%252D1000%252Fen%252Dus%252Fcontent%252Fcontent%255F1kwqavwy%255F504984382%252F04242015062323%252Epptx&access_token_ttl=0&wdSlideId=285&wdModeSwitchTime=1435884651034) 455 | 456 | **More on Parameters** 457 | 458 | 参考:[幻灯片展示](https://sg1b-powerpoint.officeapps.live.com/p/PowerPointFrame.aspx?PowerPointView=SlideShowView&ui=en-US&rs=en-US&WOPISrc=http%3A%2F%2Fsg1b-15-view-wopi%2Ewopi%2Elive%2Enet%3A808%2Foh%2Fwopi%2Ffiles%2F%40%2FwFileId%3FwFileId%3Dhttps%253A%252F%252Fcp%252Dmlxprod%252Dstatic%252Emicrosoft%252Ecom%253A443%252F05373%252D1000%252Fen%252Dus%252Fcontent%252Fcontent%255Fyozmwvwy%255F4304984382%252F04242015062355%252Epptx&access_token_ttl=0&wdSlideId=287&wdModeSwitchTime=1435884790291) 459 | 460 | **Writing Help** 461 | 462 | 参考:[幻灯片展示](https://sg1b-powerpoint.officeapps.live.com/p/PowerPointFrame.aspx?PowerPointView=SlideShowView&ui=en-US&rs=en-US&WOPISrc=http%3A%2F%2Fsg1b-15-view-wopi%2Ewopi%2Elive%2Enet%3A808%2Foh%2Fwopi%2Ffiles%2F%40%2FwFileId%3FwFileId%3Dhttps%253A%252F%252Fcp%252Dmlxprod%252Dstatic%252Emicrosoft%252Ecom%253A443%252F05373%252D1000%252Fen%252Dus%252Fcontent%252Fcontent%255Fg3xhiwwy%255F6504984382%252F04242015062428%252Epptx&access_token_ttl=0&wdSlideId=289&wdModeSwitchTime=1435884854344) 463 | 464 | **Error Handling** 465 | 466 | 参考:[幻灯片展示](https://sg1b-powerpoint.officeapps.live.com/p/PowerPointFrame.aspx?PowerPointView=SlideShowView&ui=en-US&rs=en-US&WOPISrc=http%3A%2F%2Fsg1b-15-view-wopi%2Ewopi%2Elive%2Enet%3A808%2Foh%2Fwopi%2Ffiles%2F%40%2FwFileId%3FwFileId%3Dhttps%253A%252F%252Fcp%252Dmlxprod%252Dstatic%252Emicrosoft%252Ecom%253A443%252F05373%252D1000%252Fen%252Dus%252Fcontent%252Fcontent%255Fbx9qgwwy%255F1804984382%252F04242015062503%252Epptx&access_token_ttl=0&wdSlideId=291&wdModeSwitchTime=1435884945180) 467 | 468 | **Tools That Make Changes** 469 | 470 | 参考:[幻灯片展示](https://sg1b-powerpoint.officeapps.live.com/p/PowerPointFrame.aspx?PowerPointView=SlideShowView&ui=en-US&rs=en-US&WOPISrc=http%3A%2F%2Fsg1b-15-view-wopi%2Ewopi%2Elive%2Enet%3A808%2Foh%2Fwopi%2Ffiles%2F%40%2FwFileId%3FwFileId%3Dhttps%253A%252F%252Fcp%252Dmlxprod%252Dstatic%252Emicrosoft%252Ecom%253A443%252F05373%252D1000%252Fen%252Dus%252Fcontent%252Fcontent%255Fythu3wwy%255F504984382%252F04242015062536%252Epptx&access_token_ttl=0&wdSlideId=293&wdModeSwitchTime=1435885420387) 471 | 472 | **Script and Manifest Modules** 473 | 474 | 参考:[幻灯片展示](https://sg1b-powerpoint.officeapps.live.com/p/PowerPointFrame.aspx?PowerPointView=SlideShowView&ui=en-US&rs=en-US&WOPISrc=http%3A%2F%2Fsg1b-15-view-wopi%2Ewopi%2Elive%2Enet%3A808%2Foh%2Fwopi%2Ffiles%2F%40%2FwFileId%3FwFileId%3Dhttps%253A%252F%252Fcp%252Dmlxprod%252Dstatic%252Emicrosoft%252Ecom%253A443%252F05373%252D1000%252Fen%252Dus%252Fcontent%252Fcontent%255Fdd9xmxwy%255F7604984382%252F04242015062605%252Epptx&access_token_ttl=0&wdSlideId=295&wdModeSwitchTime=1435885678020) 475 | 476 | ## 4.3. Getting Started with PowerShell Desired State Configuration (DSC) 477 | 478 | ### 4.3.1. URL 479 | 480 | - [Getting Started with PowerShell Desired State Configuration (DSC)](http://www.microsoftvirtualacademy.com/training-courses/getting-started-with-powershell-desired-state-configuration-dsc-) 481 | 482 | ### 4.3.2. 课程目录 483 | - 01 | Get Getting ready for DSC 484 | - 02 | Performing a Push deployment 485 | - 03 | Configuring Pull Servers for Deployment​ 486 | - 04 | Deploying Configurations Using a Pull Server 487 | - 05 | Resource roundup 488 | - 06 | Writing better configurations 489 | - 07 | DSC and Linux 490 | - Recommended Resources & Next Steps 491 | 492 | ### 4.3.3. 内容概要 493 | 494 | #### 4.3.3.1. 01 | Get Getting ready for DSC 495 | 496 | 通过Dsc可以实现: 497 | 498 | * Install or remove server roles and features 499 | * Manage registry settings 500 | * Manage files and directories 501 | * Start, stop, and manage processes and services 502 | * Manage local groups and user accounts 503 | * Install and manage packages such as .msi and .exe 504 | * Manage environment variables 505 | * Run Windows PowerShell scripts 506 | * Fix a configuration that has drifted away from the desired state 507 | * Discover the actual configuration state on a given node 508 | 509 | PowerShell的Pull/Push模式 510 | ![](./img/powershell_dsc_pull_push_mode.png) 511 | 512 | [这篇文章](http://blogs.msdn.com/b/powershell/archive/2013/11/26/push-and-pull-configuration-modes.aspx)清楚描述了Push/Pull模式的工作原理。 513 | 514 | 如果Windows没有安装WMF 5.0 Preview,先下载安装。 515 | 516 | 安装之后,你可以: 517 | 518 | * Search through modules in the Gallery with `Find-Module` 519 | * Save modules to your system from the Gallery with `Save-Module` 520 | * Install modules from the Gallery with `Install-Module` 521 | * Update your modules to the latest version with `Update-Module` 522 | * Add your own custom repository with `Register-PSRepository` 523 | 524 | 下面的命令列出了Repository的地址: 525 | 526 | ```PowerShell 527 | PS > Get-PSRepository 528 | 529 | Name OneGetProvider InstallationPolicy SourceLocation 530 | ---- -------------- ------------------ -------------- 531 | PSGallery NuGet Untrusted https://www.powershellgallery.com/api/v2/ 532 | ``` 533 | 534 | `Find-Module`, `Install-Module`这些命令都属于PowerShellGet module,PowerShellGet module如何利用PackageManage(也叫OneGet)来安装module? 535 | 536 | > **How does PackageManagement relate to PowerShellGet? (High Level Answer)** 537 | > 538 | > PackageManagement is a common interface for working with any package manager. Eventually, whether you're dealing with Windows PowerShell modules, MSIs, Ruby gems, NuGet packages, or Perl modules, you should be able to use PackageManagement's commands (Find-Package and Install-Package) to find and install them. PackageManagement does this by having a package provider for each package manager that plugs into PackageManagement. Providers do all of the actual work; they fetch content from repositories, and install the content locally. Often, package providers simply wrap around the existing package manager tools for a given package type. 539 | > 540 | > PowerShellGet is the package manager for Windows PowerShell modules. There is a PSModule package provider that exposes PowerShellGet functionality through PackageManagement. Because of this, you can either run Install-Module or Install-Package -Provider PSModule to install a module from the PowerShell Gallery. Certain PowerShellGet functionality, including Update-Module and Publish-Module, cannot be accessed through PackageManagement commands. 541 | > 542 | > In summary, PowerShellGet is solely focused on having a premium package management experience for Windows PowerShell content. PackageManagement is focused on exposing all package management experiences through one general set of tools. If you find this answer unsatisfying, there is a long answer at the bottom of this document, in the How does PackageManagement actually relate to PowerShellGet? section. 543 | > 544 | > For more information, please visit the [PackageManagement project page](http://oneget.org/). 545 | > 546 | > **How does PackageManagement actually relate to PowerShellGet? (Technical Details)** 547 | > 548 | > Under the hood, PowerShellGet heavily leverages PackageManagement infrastructure. 549 | > 550 | > At the Windows PowerShell cmdlet layer, Install-Module is actually a thin wrapper around Install-Package -Provider PSModule. 551 | > 552 | > At the PackageManagement package provider layer, the PSModule package provider actually calls into other PackageManagement package providers. For example, when you are working with NuGet-based galleries (such as the PowerShell Gallery), the PSModule package provider uses the NuGet Package Provider to work with the repository. 553 | > 554 | > ![](./img/powershellgetArchitecture.png) 555 | 556 | 557 | 下面的命令列出了安装在本地的DSC Resource(我理解这个resource就是module) 558 | 559 | ```PowerShell 560 | PS > Get-DscResource 561 | ``` 562 | 563 | 查看`Get-DscResource`命令所在PSDesiredStateConfiguration Module的其它命令,可以发现很多跟Dsc相关的command: 564 | 565 | ```PowerShell 566 | PS > Get-Command -Module PSDesiredStateConfiguration 567 | 568 | CommandType Name Version Source 569 | ----------- ---- ------- ------ 570 | Function Configuration 1.0 PSDesiredStateConfiguration 571 | Function Find-DscResource 1.0 PSDesiredStateConfiguration 572 | Function Get-DscConfiguration 1.0 PSDesiredStateConfiguration 573 | Function Get-DscConfigurationStatus 1.0 PSDesiredStateConfiguration 574 | Function Get-DscLocalConfigurationManager 1.0 PSDesiredStateConfiguration 575 | Function Get-DscResource 1.0 PSDesiredStateConfiguration 576 | Function New-DSCCheckSum 1.0 PSDesiredStateConfiguration 577 | Function Remove-DscConfigurationDocument 1.0 PSDesiredStateConfiguration 578 | Function Restore-DscConfiguration 1.0 PSDesiredStateConfiguration 579 | Function Stop-DscConfiguration 1.0 PSDesiredStateConfiguration 580 | Function Test-DscConfiguration 1.0 PSDesiredStateConfiguration 581 | Cmdlet Compare-DscConfiguration 1.0 PSDesiredStateConfiguration 582 | Cmdlet Connect-DscConfiguration 1.0 PSDesiredStateConfiguration 583 | Cmdlet Invoke-DscResource 1.0 PSDesiredStateConfiguration 584 | Cmdlet Publish-DscConfiguration 1.0 PSDesiredStateConfiguration 585 | Cmdlet Set-DscLocalConfigurationManager 1.0 PSDesiredStateConfiguration 586 | Cmdlet Start-DscConfiguration 1.0 PSDesiredStateConfiguration 587 | Cmdlet Update-DscConfiguration 1.0 PSDesiredStateConfiguration 588 | ``` 589 | 590 | #### 4.3.3.2. 02 | Performing a Push deployment 591 | 592 | ```PowerShell 593 | # 第1步,我在自己电脑上搭建了两个VM,一个Windows Server 2012 R2,另外一个是Windows Server 2012 ServerCore。下面我称前者是VMa,后者是VMb。 594 | 595 | # 第2步,在VMa上执行下面的命令,查看VMb的LCM配置 596 | PS > $s1 = New-CimSession -ComputerName 192.168.1.102 -Credential Administrator 597 | 598 | PS > Get-DscLocalConfigurationManager -CimSession $s1 599 | 600 | # 第3步,编写DSC Configuration文件,执行文件生成MOF 601 | PS > C:\Scripts\DSC1\Mod2\1.LCM_Push_NewWay.ps1 602 | 603 | # 第4步,把MOF推送到远程服务器 604 | PS > Set-DscLocalConfigurationManager -ComputerName 192.168.1.102 -Path C:\DSC\LCM -Verbose -Credential Administrator 605 | 606 | # 第5步,查看DSC Resource的用法 607 | PS > Get-DscResource 608 | PS > Get-DscResource -Name windowsFeature | Select-Object -ExpandProperty Properties 609 | PS > Get-DscResource -Name windowsFeature -Syntax 610 | 611 | # 第6步,编写一个安装IIS的Dsc Configuration文件,并执行文件生成MOF 612 | configuration ConfigName { 613 | Node $ComputerName { 614 | 615 | WindowsFeature IIS{ 616 | Name = 'web-server' 617 | Ensure = 'Present' 618 | } 619 | } 620 | } 621 | $computername = '192.168.1.102' 622 | ConfigName -OutputPath c:\DSC\Config 623 | 624 | # 第7步,应用Dsc Configuration文件 625 | PS > Start-DscConfiguration -Path C:\dsc\Config -ComputerName 192.168.1.106 -Credential Administrator 626 | 627 | 628 | ``` 629 | 630 | #### 4.3.3.3. 03 | Configuring Pull Servers for Deployment​ 631 | 632 | ```PowerShell 633 | 634 | ``` 635 | 636 | #### 4.3.3.4. 04 | Deploying Configurations Using a Pull Server 637 | 638 | ```PowerShell 639 | 640 | ``` 641 | 642 | #### 4.3.3.5. 05 | Resource roundup 643 | 644 | ```PowerShell 645 | 646 | ``` 647 | 648 | #### 4.3.3.6. 06 | Writing better configurations 649 | 650 | ```PowerShell 651 | 652 | ``` 653 | 654 | #### 4.3.3.7. 07 | DSC and Linux 655 | 656 | ```PowerShell 657 | 658 | ``` 659 | 660 | ## 4.4. Advanced PowerShell Desired State Configuration (DSC) and Custom Resources 661 | 662 | ### 4.4.1. URL 663 | 664 | - [Advanced PowerShell Desired State Configuration (DSC) and Custom Resources](http://www.microsoftvirtualacademy.com/training-courses/advanced-powershell-desired-state-configuration-dsc-and-custom-resources) 665 | 666 | ### 4.4.2. 课程目录 667 | - 01 | Getting Ready for DSC Custom Resources 668 | - 02 | Implementing and Testing Custom Resources 669 | - 03 | Packaging and Deploying Custom Resources 670 | - 04 | Using Classes to Build a Custom Resource 671 | - 05 | Enhancing Your Custom Resources 672 | - 06 | Building Composite Resources 673 | - 07 | Advanced Configurations 674 | - Recommended Resources & Next Steps 675 | 676 | ### 4.4.3. 内容概要 677 | 678 | #### 4.4.3.1. 01 | Getting Ready for DSC Custom Resources 679 | 680 | ```PowerShell 681 | 682 | ``` 683 | 684 | #### 4.4.3.2. 02 | Implementing and Testing Custom Resources 685 | 686 | ```PowerShell 687 | ``` 688 | 689 | #### 4.4.3.3. 03 | Packaging and Deploying Custom Resources 690 | 691 | ```PowerShell 692 | ``` 693 | 694 | #### 4.4.3.4. 04 | Using Classes to Build a Custom Resource 695 | 696 | ```PowerShell 697 | ``` 698 | 699 | #### 4.4.3.5. 05 | Enhancing Your Custom Resources 700 | 701 | ```PowerShell 702 | ``` 703 | 704 | ## 4.5. Windows Server 2012 R2 : 服务器管理和自动化 705 | 706 | ### 4.5.1. URL 707 | 708 | - [Windows Server 2012 R2 : 服务器管理和自动化](http://www.microsoftvirtualacademy.com/training-courses/803) 709 | 710 | ### 4.5.2. 课程目录 711 | 712 | - Module 1 : 基于标准的管理 713 | - Module 2 : 简化常规任务 714 | - Module 3 : 部署 715 | - Module 4 : 多服务器管理 716 | 717 | ### 4.5.3. 内容概要 718 | 719 | 720 | 721 | # 5. Blog Articles 722 | 723 | - 2007-11-23: [An Introduction to Windows PowerShell and IIS 7.0](http://www.iis.net/learn/manage/powershell/an-introduction-to-windows-powershell-and-iis) 724 | - 2008-08-29: [How to run PowerShell scripts from C#](http://www.codeproject.com/Articles/18229/How-to-run-PowerShell-scripts-from-C) 725 | - 2008-08-29: [Asynchronously Execute PowerShell Scripts from C#](http://www.codeproject.com/Articles/18409/Asynchronously-Execute-PowerShell-Scripts-from-C) 726 | - 2009-03-03: [Hey, Scripting Guy! How Do I Find the Names of WMI Classes?](http://blogs.technet.com/b/heyscriptingguy/archive/2009/03/03/how-do-i-find-the-names-of-wmi-classes.aspx) 727 | - 2009-11-25: [Changing Computer Name and Workgroup with PowerShell](http://www.gangleri.net/2009/11/25/ChangingComputerNameAndWorkgroupWithPowerShell.aspx) 728 | - 2010-02-22: [不一样的命令行 – Windows PowerShell简介](http://www.cnblogs.com/grapeot/archive/2010/02/22/1670822.html) 729 | - 2010-02-25: [用PowerShell打造时间管理小秘书](http://www.cnblogs.com/grapeot/archive/2010/02/25/1673473.html) 730 | - 2010-02-26: [一个相对实用的PowerShell时间记录脚本](http://www.cnblogs.com/grapeot/archive/2010/02/26/1674246.html) 731 | - 2010-03-08: [How to Create a Powershell 2.0 Module and Cmdlet with Visual Studio 2010 (Screencast included)](http://blogs.msdn.com/b/saveenr/archive/2010/03/08/how-to-create-a-powershell-2-0-module-and-cmdlet-with-visual-studio-2010-screencast-included.aspx) 732 | - 2010-11-01: [Windows PowerShell:通过命令而不是脚本完成操作](https://technet.microsoft.com/zh-cn/magazine/gg293110.aspx) 733 | - 2010-11-09: [Powershell 远程管理 (一)](http://www.cnblogs.com/bhtfg538/archive/2010/11/09/1872508.html) 734 | - 2010-11-12: [Powershell远程管理 二](http://www.cnblogs.com/bhtfg538/archive/2010/11/12/1875707.html) 735 | - 2011-01-01: [Windows PowerShell:将命令变为可重用工具](https://technet.microsoft.com/zh-cn/magazine/gg537351.aspx) 736 | - 2011-08-01: [Windows PowerShell: Build a Better Function](https://technet.microsoft.com/zh-cn/magazine/hh360993.aspx) 737 | - 2011-09-17: [Powershell实现Hyper-V虚拟机管理](http://www.cnblogs.com/Peter-Zhang/archive/2011/09/17/2179731.html) 738 | - 2011-10-25: [PowerShell应用之-批量执行SQL脚本](http://www.cnblogs.com/wghao/archive/2011/10/25/2224626.html) 739 | - 2011-11-01: [Windows PowerShell: Scripting Crash Course](https://technet.microsoft.com/en-us/magazine/hh551144.aspx) 740 | - 2011-12-29: [How to sign a Powershell Script](http://www.cnblogs.com/luoyiShi/archive/2011/12/29/2305865.html) 741 | - 2012-01-01: [Windows PowerShell: The Many Ways to a Custom Object](https://technet.microsoft.com/en-us/magazine/hh750381.aspx) 742 | - 2012-02-13: [Integrating Microsoft Word with PowerShell: Generate a Document](https://www.petri.com/generate-microsoft-word-document-powershell) 743 | - 2012-03-15: [Integrating Microsoft Excel with PowerShell: Build a Basic Report](https://www.petri.com/export-to-excel-with-powershell) 744 | - 2012-08-24: [Introduction to CIM Cmdlets](http://blogs.msdn.com/b/powershell/archive/2012/08/24/introduction-to-cim-cmdlets.aspx) 745 | - 2012-10-30: [PowerShell尝试ssh登录](http://www.cnblogs.com/fuhj02/archive/2012/10/30/2745701.html) 746 | - 2012-12-26: [PowerShell Workflows: The Basics](http://blogs.technet.com/b/heyscriptingguy/archive/2012/12/26/powershell-workflows-the-basics.aspx) 747 | - 2013-03-17: [Powershell针对Excel的一些简单操作](http://www.cnblogs.com/zhoujie/archive/2013/03/17/powershell1.html) 748 | - 2013-03-28: [Run your PowerShell Scripts as Windows Services!](http://the.powershell.zone/run-your-powershell-scripts-as-windows-services/) 749 | - 2013-05-06: [10 Tips for the SQL Server PowerShell Scripter](http://blogs.technet.com/b/heyscriptingguy/archive/2013/05/06/10-tips-for-the-sql-server-powershell-scripter.aspx) 750 | - 2013-05-31: [change computer name and add computer to domain using powershell script](https://social.technet.microsoft.com/Forums/scriptcenter/en-US/61b7a384-f1c6-4e1b-8759-d03ad91ae852/change-computer-name-and-add-computer-to-domain-using-powershell-script?forum=ITCG) 751 | - 2013-06-09: [An Introduction to Error Handling in PowerShell](http://blogs.msdn.com/b/kebab/archive/2013/06/09/an-introduction-to-error-handling-in-powershell.aspx) 752 | - 2013-06-11: [Understanding PowerShell's Type Conversion Magic](http://blogs.msdn.com/b/powershell/archive/2013/06/11/understanding-powershell-s-type-conversion-magic.aspx) 753 | - 2013-06-24: [Getting Started with Windows PowerShell Workflow](https://technet.microsoft.com/en-us/library/jj134242.aspx) 754 | - 2013-08-14: [Automation–Service Management Automation–Getting Started with SMA Runbooks](http://blogs.technet.com/b/privatecloud/archive/2013/08/14/automation-service-management-automation-getting-started-with-sma-runbooks.aspx) 755 | - 2013-08-30: [Introducing PowerShell Desired State Configuration (DSC)](http://blogs.technet.com/b/privatecloud/archive/2013/08/30/introducing-powershell-desired-state-configuration-dsc.aspx) 756 | - 2013-10-04: [PowerShell读取Windows产品密钥](http://www.cnblogs.com/fuhj02/p/3351172.html) 757 | - 2013-11-26: [Windows PowerShell Desired State Configuration: Push and Pull Configuration Modes](http://blogs.msdn.com/b/powershell/archive/2013/11/26/push-and-pull-configuration-modes.aspx) 758 | - 2013-12-16: [PowerShell Security Best Practices](http://blogs.msdn.com/b/powershell/archive/2013/12/16/powershell-security-best-practices.aspx) 759 | - 2014-01-31: [Comparing PowerShell PSSessions and CIM Sessions](http://blogs.technet.com/b/heyscriptingguy/archive/2014/01/31/comparing-powershell-pssessions-and-cim-sessions.aspx) 760 | - 2014-03-18: [Writing a PowerShell module in C#, Part 1: The basics](http://www.powershellmagazine.com/2014/03/18/writing-a-powershell-module-in-c-part-1-the-basics/) 761 | - 2014-04-01: [PowerShell Desired State Configuration (DSC) Survival Guide](http://social.technet.microsoft.com/wiki/contents/articles/23222.powershell-desired-state-configuration-dsc-survival-guide.aspx) 762 | - 2014-04-08: [Basics of Writing a PowerShell Module with C#, Part 2: Debugging](http://www.powershellmagazine.com/2014/04/08/basics-of-writing-a-powershell-module-with-c-part-2-debugging/) 763 | - 2014-04-16: [A World of Scripts at your Fingertips – Introducing Script Browser](http://blogs.msdn.com/b/powershell/archive/2014/04/16/a-world-of-scripts-at-your-fingertips-introducing-script-browser.aspx) 764 | - 2014-05-23: [PowerShell提速和多线程](http://www.pstips.net/speeding-up-powershell-multithreading.html) 765 | - 2014-06-01: [Prevent Write-Debug From Bugging You](http://learn-powershell.net/2014/06/01/prevent-write-debug-from-bugging-you/) 766 | - 2014-06-06: [PowerShell DSC Blog Series, Part 5- Point in Time List of DSC Resources](http://blogs.technet.com/b/privatecloud/archive/2014/06/06/powershell-dsc-blog-series-part-5-point-in-time-list-of-dsc-resources.aspx) 767 | - 2014-07-03: [Posh-SSH: Open Source SSH PowerShell Module](http://www.powershellmagazine.com/2014/07/03/posh-ssh-open-source-ssh-powershell-module/) 768 | - 2014-07-29: [Chef with PowerShell DSC Now Public!](http://blogs.msdn.com/b/powershell/archive/2014/07/29/chef-with-powershell-dsc-now-public.aspx) 769 | - 2014-07-30: [Use PowerShell to Write Verbose Output](http://blogs.technet.com/b/heyscriptingguy/archive/2014/07/30/use-powershell-to-write-verbose-output.aspx) 770 | - 2014-08-08: [Executing PowerShell scripts from C#](http://blogs.msdn.com/b/kebab/archive/2014/04/28/executing-powershell-scripts-from-c.aspx) 771 | - 2014-09-09: [15 Ways to Bypass the PowerShell Execution Policy](https://blog.netspi.com/15-ways-to-bypass-the-powershell-execution-policy/) 772 | - 2014-09-14: [Weekend Scripter: Manipulating Word and Excel with PowerShell](http://blogs.technet.com/b/heyscriptingguy/archive/2014/09/14/weekend-scripter-manipulating-word-and-excel-with-powershell.aspx) 773 | - 2014-10-08: [通过PowerShell获取Windows系统密码Hash](http://www.cnblogs.com/fuhj02/p/4011705.html) 774 | - 2015-01-14: [利用Powershell在IIS上自动化部署网站](http://www.cnblogs.com/jiangjun0817/p/4214660.html) 775 | - 2015-02-27: [Invoking PowerShell DSC Resources directly](http://blogs.msdn.com/b/powershell/archive/2015/02/27/invoking-dsc-resource-methods-directly-from-powershell-cim-apis.aspx) 776 | - 2015-04-29: [ScriptAnalyzer in GitHub and availability on PowerShell Gallery](http://blogs.msdn.com/b/powershell/archive/2015/04/29/scriptanalyzer-in-github-and-availability-on-powershell-gallery.aspx) 777 | - 2015-05-05: [PowerShell DSC for Linux is now available!](http://blogs.msdn.com/b/powershell/archive/2015/05/06/powershell-dsc-for-linux-is-now-available.aspx) 778 | - 2015-05-05: [Desired State Configuration Resources for PackageManagement Providers](http://blogs.msdn.com/b/powershell/archive/2015/05/05/desired-state-configuration-resources-for-packagemanagement-providers.aspx) 779 | - 2015-05-29: [How to register a node with a DSC pull server](http://blogs.msdn.com/b/powershell/archive/2015/05/29/how-to-register-a-node-with-a-dsc-pull-server.aspx) 780 | - 2015-06-01: [PowerShell控制台输出绿色的对号](http://www.pstips.net/using-green-checkmarks-in-console-output.html) 781 | - 2015-06-03: [Looking Forward: Microsoft Support for Secure Shell (SSH)](http://blogs.msdn.com/b/powershell/archive/2015/06/03/looking-forward-microsoft-support-for-secure-shell-ssh.aspx) 782 | - 2015-06-09: [PowerShell ♥ the Blue Team](http://blogs.msdn.com/b/powershell/archive/2015/06/09/powershell-the-blue-team.aspx) 783 | - 2015-06-17: [Azure DSC Extension v2.0 released](http://blogs.msdn.com/b/powershell/archive/2015/06/17/azure-dsc-extension-v2-0-released.aspx) 784 | - 2015-06-23: [DSC Resource Kit flourishes as open source](http://blogs.msdn.com/b/powershell/archive/2015/06/23/dsc-resource-kit-flourishes-as-open-source.aspx) 785 | 786 | # 6. Third-Party Utilities 787 | 788 | ## 6.1. PowerShell Modules 789 | 790 | - [DSC Resource Kit (All Modules)](https://gallery.technet.microsoft.com/scriptcenter/DSC-Resource-Kit-All-c449312d) 791 | - [PSReadLine](https://github.com/lzybkr/PSReadLine) - A bash inspired readline implementation for PowerShell 792 | - [Towards a better console - PSReadLine for PowerShell command line editing](http://www.hanselman.com/blog/TowardsABetterConsolePSReadLineForPowerShellCommandLineEditing.aspx) By Scott Hanselman 793 | - [SSH.NET Library](http://sshnet.codeplex.com/) 794 | - [Posh-SSH: PowerShell Module for automating tasks on remote systems using SSH](https://github.com/darkoperator/Posh-SSH) 795 | - [Posh-SecMod: PowerShell Module with Security cmdlets for security work](https://github.com/darkoperator/Posh-SecMod) 796 | - [PsGet](http://psget.net/) - Search and install PowerShell modules easy. 797 | - 注意:PowerShell 5中已经自带了PowerShellGet Module的,这个module和PsGet的功能重复。如果系统的PowerShell版本是5.0,不要安装PsGet 798 | - [Posh-hg](https://github.com/JeremySkinner/posh-hg): Mercurial integration for PowerShell 799 | - [PowerSploit](https://github.com/mattifestation/PowerSploit) is a collection of Microsoft PowerShell modules that can be used to aid penetration testers during all phases of an assessment. 800 | - [PowerShellArsenal](https://github.com/mattifestation/PowerShellArsenal) is a PowerShell module used to aid a reverse engineer. The module can be used to disassemble managed and unmanaged code, perform .NET malware analysis, analyze/scrape memory, parse file formats and memory structures, obtain internal system information, etc. 801 | - [Nishang](https://github.com/samratashok/nishang) is a framework and collection of scripts and payloads which enables usage of PowerShell for offensive security and penetration testing. Nishang is useful during various phases of a penetration test and is most powerful for post exploitation usage. 802 | 803 | ## 6.2. Utilities 804 | 805 | - [PowerShell Tools for Visual Studio 2013](https://visualstudiogallery.msdn.microsoft.com/c9eb3ba8-0c59-4944-9a62-6eee37294597) 806 | - [Script Browser & Script Analyzer](http://www.microsoft.com/zh-cn/download/details.aspx?id=42525): Script Browser for Windows PowerShell ISE允许用户从Windows PowerShell ISE内直接搜索、下载和使用9000多个微软TechNet脚本中心的脚本示例。 807 | - [Boxstarter](http://boxstarter.org/): Boxstarter 2.x的50%以上的代码由PowerShell编写,可以作为学习PowerShell很好的项目 808 | - [Psake](https://github.com/psake/psake): a build automation tool… now with less XML… 809 | - [Prester](https://github.com/pester/Pester): Powershell BDD style testing framework 810 | - [winbootstrap](https://github.com/aroben/winbootstrap): 使用PowerShell自动安装并配置Cygwin 811 | - [clymb3r/PowerShell](https://github.com/clymb3r/PowerShell): Useful PowerShell scripts 812 | 813 | # 7. Websites about PowerShell 814 | 815 | ## 7.1. In China 816 | 817 | - [pstips.net](http://www.pstips.net/): 收集和分享 Windows PowerShell 相关教程,技术和最新动态 818 | 819 | ## 7.2. Out of China 820 | 821 | - [PowerShell Gallery](https://www.powershellgallery.com/) 822 | - [Microsoft Script Center - Technet](https://technet.microsoft.com/en-us/scriptcenter/bb410849.aspx) 823 | - [Windows PowerShell Team Blog](http://blogs.msdn.com/b/powershell/) 824 | - [Windows PowerShell Tutorial By Guy Thomas](http://www.computerperformance.co.uk/powershell/index.htm) 825 | - [PowerShell Magazine](http://www.powershellmagazine.com/) 826 | - [powershell.org](http://powershell.org/wp/) 827 | - [Windows PowerShell Desired State Configuration Overview](https://technet.microsoft.com/en-us/library/dn249912.aspx) 828 | 829 | # 8. Books 830 | 831 | - "Learn PowerShell 3 in a month of Lunches (2nd)" by Don Jones 832 | - "PowerShell in Depth (2nd)" by Don Jonnes 833 | - "Windows PowerShell in Action (2nd)" by Bruce Payette 834 | - "Windows PowerShell Cookbook (3nd)" by Lee Holmes 835 | - "Learn PowerShell ToolMaking in a Month of Lunches" by Don Jones 836 | - [powershell.org free ebooks](http://powershell.org/wp/ebooks/) 837 | 838 | # 9. FAQ 839 | 840 | ## 9.1. Windows PowerShell Profiles文件保存在什么位置? 841 | 842 | - [Windows PowerShell Profiles - Technet](https://technet.microsoft.com/en-us/library/bb613488(v=vs.85).aspx) 843 | - [Understanding and Using PowerShell Profiles - PowerShell Team Blog](http://blogs.technet.com/b/heyscriptingguy/archive/2013/01/04/understanding-and-using-powershell-profiles.aspx) 844 | 845 | ## 9.2. PowerShell Remote Trouble Shooting 846 | 847 | 下面的文章中包含了很多关于PowerShell远程连接的一些问题和解决办法 848 | - [about_Remote_Troubleshooting - TechNet](https://technet.microsoft.com/en-us/library/dd347642.aspx) 849 | 850 | ## 9.3. PowerShell展示本地及远程电脑的driver 851 | 852 | `GET-WMIOBJECT –query "SELECT * from win32_logicaldisk where DriveType='3'"` 853 | 854 | 检查远程电脑的drivers,需要加上-ComputerName参数 855 | 856 | `GET-WMIOBJECT –query "SELECT * from win32_logicaldisk where DriveType = '3'" –computername "ContosoWS1"` 857 | 858 | ## 9.4. Windows 10的Microsoft Edge浏览器默认不能访问localhost website,如果解决? 859 | 860 | 参考[Can't open localhost in Project Spartan in Windows 10 preview](http://stackoverflow.com/questions/30334289/cant-open-localhost-in-project-spartan-in-windows-10-preview) 861 | 862 | 原因是:So the issue is Edge doesn't have access to the loopback addresses, which is something that most Windows Store are blocked from accessing. 863 | 864 | ## 9.5. Write-Host和Write-Output有什么区别? 865 | 866 | 参考:[Which should I use: “write-host”, “write-output”, or “[console]::WriteLine”?](http://stackoverflow.com/questions/8755497/which-should-i-use-write-host-write-output-or-consolewriteline) 867 | 868 | Write-Output should be used when you want to send data on in the pipe line, but not necessarily want to display it on screen. The pipeline will eventually write it to out-default if nothing else uses it first. Write-Host should be used when you want to do the opposite. 869 | 870 | ## 9.6. 如何查看所有的WMI Classes? 871 | 872 | 参考: 873 | - [How do I find the names fo WMI classes](http://blogs.technet.com/b/heyscriptingguy/archive/2009/03/03/how-do-i-find-the-names-of-wmi-classes.aspx) 874 | - [Windows Management Instrumentation - MSDN](https://msdn.microsoft.com/en-us/library/aa394582(v=vs.85).aspx) 875 | - [Windows Management Instrumentation - Wikipedia](https://en.wiki2.org/wiki/Windows_Management_Instrumentation) 876 | 877 | ## 9.7. 如何连接局域网中不在域的PC? 878 | 879 | 参考:[Using Enter-PSSession on LAN without domain?](https://social.technet.microsoft.com/Forums/windowsserver/en-US/f4b79641-92cb-4aa7-8cd3-921853b9e0d5/using-enterpssession-on-lan-without-domain) 880 | 881 | ## 9.8. PowerShell中Cmdlet和Function有什么区别? 882 | 883 | 参考:[cmdlets vs functions](http://powershell.org/wp/forums/topic/cmdlets-vs-functions/) 884 | 885 | Basically a true Powershell cmdlet is written in a .NET programming language, typically C#, and compiled – so in a way it's a real application. An advanced function is written in Powershell (although you could include some custom C# code) and is not compiled. There are probably performance benefits to implementing a compiled cmdlet rather than an advanced function but the functions exist for us average joe admins who aren't real programmers to be able to develop and share our own tools. 886 | 887 | This is probably not the most eloquent description so I'll leave the nitty-gritty details to those who know more about the developer side of Powershell and .NET. 888 | 889 | ## 9.9. ConEmu中PowerShell Shell输入中文字符时字符重叠在一起,如何解决? 890 | 891 | 打开Settings -> Main -> Main console font,取消Monospace(等宽字体)上的勾。 892 | 893 | ## 9.10. Windows和Linux的dynamic port range动态端口范围是多少? 894 | 895 | 参考: 896 | 897 | - [The default dynamic port range for TCP/IP has changed in Windows Vista and in Windows Server 2008](https://support.microsoft.com/en-us/kb/929851) 898 | - [Windows2003 动态端口,端口重用,动态端口取值范围](http://blog.chinaunix.net/uid-116213-id-3150158.html) 899 | - [Why doesn't Linux use the IANA Ephemeral port range?](http://unix.stackexchange.com/questions/39699/why-doesnt-linux-use-the-iana-ephemeral-port-range) 900 | - [Linux Increase Local Port Range with net.ipv4.ip_local_port_range Kernel Parameter](http://www.cyberciti.biz/tips/linux-increase-outgoing-network-sockets-range.html) 901 | - [List of TCP and UDP port numbers - wikipedia](https://en.wiki2.org/wiki/List_of_TCP_and_UDP_port_numbers): 常见端口用途 902 | 903 | Dynamic Port Range is used by the client computers (or a server acting as a client) to connect to Well Known Port Services or Root Services. 904 | 905 | - Default dynamic port range of Windows XP, Windows 2000 Professional, and Windows Server 2003: 1024-65535 906 | - Default dynamic port range of Windows Vista, Windows 7 and Windows Server 2008: 49152-65535 907 | - Default dynamic port range of Ubuntu Linux 14.04: 32768-61000 908 | -------------------------------------------------------------------------------- /windows/windows-command-line-utilities.md: -------------------------------------------------------------------------------- 1 | # 文件操作命令 2 | 3 | - `dir`: [说明](http://ss64.com/nt/copy.html), Display a list of files and subfolders. 4 | - `copy`: [说明](http://ss64.com/nt/copy.html), Copy one or more files to another location. 5 | - `xcopy`: [说明](http://ss64.com/nt/xcopy.html), Copy files and folders. 6 | - `robocopy`: [说明](http://ss64.com/nt/robocopy.html), Robust File and Folder Copy, By default Robocopy will only copy a file if the source and destination have different time stamps or different file sizes. 7 | - 一般命令执行成功`%ERRORLEVEL%`为0,而`robocopy`命令执行返回的值只要小于8,都算成功,具体见[robocopy返回值](http://blog.csdn.net/kapuliyuehan/article/details/6738025) 8 | - `ren`: [说明](http://ss64.com/nt/ren.html), Rename a file or files. Read the introduction to know about the differences between `rem` and `move`. 9 | - `move`: [说明](http://ss64.com/nt/move.html), Move a file from one folder to another. 10 | 11 | # 网络命令 12 | 13 | - `ipconfig`: [说明](http://ss64.com/nt/ipconfig.html),Configure IP (Internet Protocol configuration). 14 | - `netstat`: [说明](http://ss64.com/nt/netstat.html), Display current TCP/IP network connections and protocol statistics. 15 | - `netsh`: 16 | - [说明](http://ss64.com/nt/netsh.html), Configure Network Interfaces, Windows Firewall, Routing & remote access. 17 | - [The Netsh Command-Line Utility - Technet](https://technet.microsoft.com/en-us/library/cc785383%28v=ws.10%29.aspx) 18 | - [Netsh命令详解](http://www.hackbase.com/tech/2011-02-15/62612.html) 19 | 20 | # Nmap 21 | 22 | 23 | # Sysinternals Tools 24 | 25 | 26 | # FAQ 27 | 28 | # 参考 29 | 30 | - [SS64 Windows CMD](http://ss64.com/nt/) 31 | - [Windows Command-Line Reference](https://technet.microsoft.com/en-us/library/cc754340.aspx) 32 | --------------------------------------------------------------------------------