├── LICENSE-CC-BY-SA-4.0.md ├── README.md ├── part1-basics.md ├── part2-prepare.md └── part3-customize.md /LICENSE-CC-BY-SA-4.0.md: -------------------------------------------------------------------------------- 1 | # LICENSE-CC-BY-SA-4.0.md 2 | 3 | UNLESS OTHERWISE NOTED, THE CONTENTS OF THIS REPOSITORY ARE LICENSED UNDER THE CREATIVE COMMONS ATTRIBUTION - SHARE ALIKE 4.0 INTERNATIONAL LICENSE 4 | 5 | ![https://creativecommons.org/licenses/by-sa/4.0/](https://i.creativecommons.org/l/by-sa/4.0/88x31.png) 6 | 7 | ## License Summary of CC-BY-SA 4.0 International 8 | 9 | *This section is a human-readable summary of (and not a substitute for) the full license included below.* 10 | 11 | ### You are free to: 12 | 13 | * **Share** — copy and redistribute the material in any medium or format 14 | * **Adapt** — remix, transform, and build upon the material for any purpose, even commercially. 15 | 16 | The licensor cannot revoke these freedoms as long as you follow the license terms. 17 | 18 | ### Under the following terms: 19 | 20 | * ![CC-BY](https://creativecommons.org/images/deed/by.png) **Attribution** — You must give **appropriate credit**, provide **a link to the license**, and **indicate if changes were made**. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. 21 | * ![CC-BY](https://creativecommons.org/images/deed/sa.png) **ShareAlike** — If you remix, transform, or build upon the material, you must distribute your contributions under the **same license** as the original. 22 | 23 | **No additional restrictions** — You may not apply legal terms or **technological measures** that legally restrict others from doing anything the license permits. 24 | 25 | ### Notices: 26 | 27 | You do not have to comply with the license for elements of the material in the public domain or where your use is permitted by an applicable **exception or limitation**. 28 | 29 | No warranties are given. The license may not give you all of the permissions necessary for your intended use. For example, other rights such as **publicity, privacy, or moral rights** may limit how you use the material. 30 | 31 | # Creative Commons Attribution-ShareAlike 4.0 International License 32 | 33 | FROM: https://creativecommons.org/licenses/by-sa/4.0/legalcode 34 | 35 | Creative Commons Corporation (“Creative Commons”) is not a law firm and does not provide legal services or legal advice. Distribution of Creative Commons public licenses does not create a lawyer-client or other relationship. Creative Commons makes its licenses and related information available on an “as-is” basis. Creative Commons gives no warranties regarding its licenses, any material licensed under their terms and conditions, or any related information. Creative Commons disclaims all liability for damages resulting from their use to the fullest extent possible. 36 | 37 | ### Using Creative Commons Public Licenses 38 | 39 | Creative Commons public licenses provide a standard set of terms and conditions that creators and other rights holders may use to share original works of authorship and other material subject to copyright and certain other rights specified in the public license below. The following considerations are for informational purposes only, are not exhaustive, and do not form part of our licenses. 40 | 41 | * __Considerations for licensors:__ Our public licenses are intended for use by those authorized to give the public permission to use material in ways otherwise restricted by copyright and certain other rights. Our licenses are irrevocable. Licensors should read and understand the terms and conditions of the license they choose before applying it. Licensors should also secure all rights necessary before applying our licenses so that the public can reuse the material as expected. Licensors should clearly mark any material not subject to the license. This includes other CC-licensed material, or material used under an exception or limitation to copyright. [More considerations for licensors](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensors). 42 | 43 | * __Considerations for the public:__ By using one of our public licenses, a licensor grants the public permission to use the licensed material under specified terms and conditions. If the licensor’s permission is not necessary for any reason–for example, because of any applicable exception or limitation to copyright–then that use is not regulated by the license. Our licenses grant only permissions under copyright and certain other rights that a licensor has authority to grant. Use of the licensed material may still be restricted for other reasons, including because others have copyright or other rights in the material. A licensor may make special requests, such as asking that all changes be marked or described. Although not required by our licenses, you are encouraged to respect those requests where reasonable. [More considerations for the public](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensees). 44 | 45 | ### Creative Commons Attribution-ShareAlike 4.0 International Public License 46 | 47 | By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. 48 | 49 | **Section 1 – Definitions.** 50 | 51 | 1. **Adapted Material** means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image. 52 | 2. **Adapter's License** means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License. 53 | 3. **BY-SA Compatible License** means a license listed at [ creativecommons.org/compatiblelicenses][4], approved by Creative Commons as essentially the equivalent of this Public License. 54 | 4. **Copyright and Similar Rights** means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. 55 | 5. **Effective Technological Measures** means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements. 56 | 6. **Exceptions and Limitations** means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material. 57 | 7. **License Elements** means the license attributes listed in the name of a Creative Commons Public License. The License Elements of this Public License are Attribution and ShareAlike. 58 | 8. **Licensed Material** means the artistic or literary work, database, or other material to which the Licensor applied this Public License. 59 | 9. **Licensed Rights** means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license. 60 | 10. **Licensor** means the individual(s) or entity(ies) granting rights under this Public License. 61 | 11. **Share** means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them. 62 | 12. **Sui Generis Database Rights** means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world. 63 | 13. **You** means the individual or entity exercising the Licensed Rights under this Public License. **Your** has a corresponding meaning. 64 | 65 | **Section 2 – Scope.** 66 | 67 | 1. **License grant**. 68 | 1. Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to: 69 | 1. reproduce and Share the Licensed Material, in whole or in part; and 70 | 2. produce, reproduce, and Share Adapted Material. 71 | 2. Exceptions and Limitations. For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions. 72 | 3. Term. The term of this Public License is specified in Section 6(a). 73 | 4. Media and formats; technical modifications allowed. The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material. 74 | 5. Downstream recipients. 75 | 76 | 1. Offer from the Licensor – Licensed Material. Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License. 77 | 2. Additional offer from the Licensor – Adapted Material. Every recipient of Adapted Material from You automatically receives an offer from the Licensor to exercise the Licensed Rights in the Adapted Material under the conditions of the Adapter's License You apply. 78 | 3. No downstream restrictions. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material. 79 | 80 | 6. No endorsement. Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i). 81 | 2. **Other rights**. 82 | 83 | 1. Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise. 84 | 2. Patent and trademark rights are not licensed under this Public License. 85 | 3. To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties. 86 | 87 | **Section 3 – License Conditions.** 88 | 89 | Your exercise of the Licensed Rights is expressly made subject to the following conditions. 90 | 91 | 1. **Attribution**. 92 | 93 | 1. If You Share the Licensed Material (including in modified form), You must: 94 | 95 | 1. retain the following if it is supplied by the Licensor with the Licensed Material: 96 | 1. identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated); 97 | 2. a copyright notice; 98 | 3. a notice that refers to this Public License; 99 | 4. a notice that refers to the disclaimer of warranties; 100 | 5. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; 101 | 2. indicate if You modified the Licensed Material and retain an indication of any previous modifications; and 102 | 3. indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License. 103 | 2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information. 104 | 3. If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable. 105 | 2. **ShareAlike**. 106 | 107 | In addition to the conditions in Section 3(a), if You Share Adapted Material You produce, the following conditions also apply. 108 | 109 | 1. The Adapter's License You apply must be a Creative Commons license with the same License Elements, this version or later, or a BY-SA Compatible License. 110 | 2. You must include the text of, or the URI or hyperlink to, the Adapter's License You apply. You may satisfy this condition in any reasonable manner based on the medium, means, and context in which You Share Adapted Material. 111 | 3. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, Adapted Material that restrict exercise of the rights granted under the Adapter's License You apply. 112 | 113 | **Section 4 – Sui Generis Database Rights.** 114 | 115 | Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material: 116 | 117 | 1. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database; 118 | 2. if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material, including for purposes of Section 3(b); and 119 | 3. You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database. 120 | For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights. 121 | 122 | **Section 5 – Disclaimer of Warranties and Limitation of Liability.** 123 | 124 | 1. **Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You.** 125 | 2. **To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You.** 126 | 3. The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability. 127 | 128 | **Section 6 – Term and Termination.** 129 | 130 | 1. This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically. 131 | 2. Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates: 132 | 133 | 1. automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or 134 | 2. upon express reinstatement by the Licensor. 135 | For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License. 136 | 3. For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License. 137 | 4. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. 138 | 139 | **Section 7 – Other Terms and Conditions.** 140 | 141 | 1. The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed. 142 | 2. Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License. 143 | 144 | **Section 8 – Interpretation.** 145 | 146 | 1. For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License. 147 | 2. To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions. 148 | 3. No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor. 149 | 4. Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority. 150 | 151 | --- 152 | 153 | *Creative Commons is not a party to its public licenses. Notwithstanding, Creative Commons may elect to apply one of its public licenses to material it publishes and in those instances will be considered the "Licensor." The text of the Creative Commons public licenses is dedicated to the public domain under the [CC0 Public Domain Dedication](http://creativecommons.org/publicdomain/zero/1.0/legalcode). Except for the limited purpose of indicating that material is shared under a Creative Commons public license or as otherwise permitted by the Creative Commons policies published at [creativecommons.org/policies](http://creativecommons.org/policies), Creative Commons does not authorize the use of the trademark "Creative Commons" or any other trademark or logo of Creative Commons without its prior written consent including, without limitation, in connection with any unauthorized modifications to any of its public licenses or any other arrangements, understandings, or agreements concerning use of licensed material. For the avoidance of doubt, this paragraph does not form part of the public licenses.* 154 | 155 | *Creative Commons may be contacted at [creativecommons.org](http://creativecommons.org/).* 156 | 157 | *Additional languages available: [Bahasa Indonesia](http://creativecommons.org/licenses/by/4.0/legalcode.id), [Nederlands](http://creativecommons.org/licenses/by/4.0/legalcode.nl), [norsk]//creativecommons.org/licenses/by/4.0/legalcode.no, [suomeksi](//creativecommons.org/licenses/by/4.0/legalcode.fi), [te reo Māori](//creativecommons.org/licenses/by/4.0/legalcode.mi), [українська](//creativecommons.org/licenses/by/4.0/legalcode.uk), [日本語](//creativecommons.org/licenses/by/4.0/legalcode.ja). Please read the [FAQ](//wiki.creativecommons.org/FAQ#officialtranslations) for more information about official translations.* 158 | 159 | --- 160 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Introduction to the Mac Command Line 2 | ==================================== 3 | 4 | This git repository contains a tutorial and associated files to introduce people to the Mac command line, with a focus on creating a base of skills that will make it easier for a novice programmer to learn web server and client programming skills, in particular JavaScript and Node.js. 5 | 6 | * [Part 1 - Command Line Basics](https://github.com/ChristopherA/intro-mac-command-line/blob/master/part1-basics.md) 7 | * [Part 2 - Preparation and Installation](https://github.com/ChristopherA/intro-mac-command-line/blob/master/part2-prepare.md) 8 | * [Part 3 - Customize Your Environment](https://github.com/ChristopherA/intro-mac-command-line/blob/master/part3-customize.md) 9 | 10 | This tutorial was created by [Christopher Allen](mailto:ChristopherA@LifeWithAlacrity.com) and is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License, based on the original work at [https://github.com/ChristopherA/intro-mac-commandline](https://github.com/ChristopherA/intro-mac-commandline). 11 | 12 | All of the installation and customization features suggested by this tutorial are also automated as part of a prepare-osx.sh script in [https://github.com/ChristopherA/prepare-osx-for-webdev](https://github.com/ChristopherA/prepare-osx-for-webdev), however, I recommend that you do the tutorial first to understand what this script does. 13 | -------------------------------------------------------------------------------- /part1-basics.md: -------------------------------------------------------------------------------- 1 | Command Line Basics 2 | =================== 3 | 4 | What is the Command Line Interface? 5 | ----------------------------------- 6 | Underneath the wonderful Mac Graphical User Interface ("GUI") is a powerful and flexible method of working directly with files and the web. This is known as the "command line interface", or sometimes "CLI". 7 | 8 | It may seem geeky at first, and its depth may seem intimidating, but you don't need to learn it all of it for it for the command line to become quite useful to you. In particular, in order to learn how to program web applications or clients effectively on the Mac, you will need to have some comfort with the basics of the Mac command line. 9 | 10 | The Terminal, the Console, the Shell, and the Command Line 11 | ---------------------------------------------------------- 12 | First, you should learn how to start the built-in application that runs the Mac CLI, called the _Terminal_. To launch it, rather than the usual GUI method of opening the Applications/Utilities directory and double-clicking the Terminal app, instead you should learn to launch the Terminal solely by using your keyboard. 13 | 14 | Type `command + spacebar` and then type `terminal` and press return. In fact, you don't even need to typically type the whole word -- just the first few letters `ter` or `term` is usually enough. 15 | 16 | When Terminal first opens, you should see a small window with this text in it: 17 | 18 | ``` 19 | Last login: {some date} on console 20 | COMPUTERNAME:~ USERNAME$ 🁢 21 | ``` 22 | The window you see is created by the _Terminal_ application, which more properly a form of _terminal emulator_ and its contents (any commands and the text output from previous commands) are known as the _console_. These words come from the days when you had a green CRT screen and keyboard –- the machine as a whole was the the _terminal_, and the contents of the screen was the _console_. Our _terminal emulator_ provides us the experience of typing into an old school terminal from the convenience of our modern graphical operating system. 23 | 24 | The text before and including the $ is known as the _prompt_. The _command line_ is everything after the current prompt, and is the portion of the console where you can type. 25 | 26 | The 🁢 symbol is the location of your _text cursor_ on the command line. Anything you type will appear under the text cursor and the text cursor will move to the next spot. 27 | 28 | All the text you see in the console was created by what is known as the _shell_ application (the Mac defaults to the shell application known as _bash_). 29 | 30 | Often the words terminal, console, command line, shell, or bash are used interchangeably, but these each are are all slightly different. 31 | 32 | Someday you may want to switch to a more sophisticated Terminal applications (_iTerm_ is popular), or switch to a more sophisted text shell (_tsch_ is popular), or both. For the purpose of this _Intro to the Command Line_ tutorial we will only be using the default Mac _Terminal_ app, and the _bash_ command line text shell. 33 | 34 | Running a Command 35 | ----------------- 36 | 37 | If you now type the text `ls -l ~` you will see the text appear to the right of the $. This is your _command_. Type return to _execute_ your command. 38 | 39 | ``` 40 | COMPUTERNAME:~ USERNAME$ ls -l ~ 41 | total 0 42 | drwx------+ 3 USERNAME staff 102 Oct 21 18:44 Desktop 43 | drwx------+ 3 USERNAME staff 102 Oct 21 18:44 Documents 44 | drwx------+ 3 USERNAME staff 102 Oct 21 18:44 Downloads 45 | drwx------@ 43 USERNAME staff 1462 Apr 12 00:15 Library 46 | drwx------+ 3 USERNAME staff 102 Oct 21 18:44 Movies 47 | drwx------+ 3 USERNAME staff 102 Oct 21 18:44 Music 48 | drwx------+ 3 USERNAME staff 102 Oct 21 18:44 Pictures 49 | drwxr-xr-x+ 5 USERNAME staff 170 Oct 21 18:44 Public 50 | COMPUTERNAME:~ USERNAME$ 🁢 51 | ``` 52 | 53 | Nearly all commands follow a common pattern with 3 main parts. The program, the options, and the arguments, each separated by spaces. 54 | 55 | The program is the verb, in this case the first part `ls`, which is short for _list_, which will show us a list of files. 56 | 57 | The options are like the adverb, and modify how the program is run. Options almost always begin with a hyphen. In this example `-l` means _long_, so the `ls` command will now show us more detailed information rather than just the names of the files. 58 | 59 | The arguments are what is left, and are the objects of our command. They describe what we want our program to act on. In this case we are using a special shorthand name for our home directory `~`. 60 | 61 | Combined, these three parts tell the computer to list, in long form, the contents of your home directory. 62 | 63 | The Current Directory 64 | --------------------- 65 | 66 | When you enter many commands without any arguments, they will act by default on on the current directory (aka folder) . What is the current directory? Type `pwd`. 67 | 68 | ``` 69 | COMPUTERNAME:~ USERNAME$ pwd 70 | /Users/USERNAME 71 | COMPUTERNAME:~ USERNAME$ 🁢 72 | ``` 73 | 74 | The command `pwd` is short for 'present working directory' which basically means "Where am I now?". The result of `pwd` is the _path_ to where any commands without arguments will default to. 75 | 76 | ``` 77 | COMPUTERNAME:~ USERNAME$ ls 78 | Desktop Downloads Movies Pictures 79 | Documents Library Music Public 80 | COMPUTERNAME:~ USERNAME$ 🁢 81 | ``` 82 | 83 | Notice that the `ls` command showed us one additional directory that you can't see from your Mac's Finder GUI: the Library directory. There can be other invisible files. We can see these by adding to the `ls` command an option, in this case `-a`. Together the command and option `ls -a` means 'list all'. 84 | 85 | ``` 86 | COMPUTERNAME:~ USERNAME$ ls 87 | . Desktop Movies 88 | .. Documents Music 89 | .CFUserTextEncoding Downloads Pictures 90 | .Trash Library Public 91 | COMPUTERNAME:~ USERNAME$ 🁢 92 | ``` 93 | 94 | The 'ls -a' command reveals a number of directory and files that are marked as invisible to the Finder and the Mac GUI. Any file or directory that begins with a period will also be invisible to the Finder. We will learn more about these files later. 95 | 96 | To look at the contents of another directory, you can add a _path_ option to the `ls` command. Type `ls Public` to see the contents of your Public directory (the name of the directory `Public` is case sensitive — `public` will not work). 97 | 98 | ``` 99 | COMPUTERNAME:~ USERNAME$ ls Public 100 | Drop Box 101 | COMPUTERNAME:~ USERNAME$ 🁢 102 | ``` 103 | 104 | The `ls -l` (i.e. `list long`) command lists additional information about each item in the current directory: 105 | 106 | ``` 107 | COMPUTERNAME:~ USERNAME$ ls -l 108 | total 0 109 | drwx------+ 3 USERNAME staff 102 Oct 21 18:44 Desktop 110 | drwx------+ 3 USERNAME staff 102 Oct 21 18:44 Documents 111 | drwx------+ 3 USERNAME staff 102 Oct 21 18:44 Downloads 112 | drwx------@ 43 USERNAME staff 1462 Apr 12 00:15 Library 113 | drwx------+ 3 USERNAME staff 102 Oct 21 18:44 Movies 114 | drwx------+ 3 USERNAME staff 102 Oct 21 18:44 Music 115 | drwx------+ 3 USERNAME staff 102 Oct 21 18:44 Pictures 116 | drwxr-xr-x+ 5 USERNAME staff 170 Oct 21 18:44 Public 117 | COMPUTERNAME:~ USERNAME$ 🁢 118 | ``` 119 | 120 | With the `-l` option the `d` on the left tells you that the item in the directory contains another directory. A hyphen `-` tells you that the item is a file. 121 | 122 | You can combine options, so `ls -la` will list all the information about all the contents of the current directory, including hidden dot `.` files and invisible directories like the `Library`. 123 | 124 | ``` 125 | COMPUTERNAME:~ USERNAME$ ls -l 126 | total 8 127 | drwxr-xr-x+ 14 USERNAME staff 476 Apr 12 12:39 . 128 | drwxr-xr-x 6 root admin 204 Oct 21 18:44 .. 129 | -r-------- 1 USERNAME staff 7 Oct 21 18:46 .CFUserTextEncoding 130 | drwx------ 2 USERNAME staff 68 Apr 11 23:27 .Trash 131 | drwx------+ 3 USERNAME staff 102 Oct 21 18:44 Desktop 132 | drwx------+ 3 USERNAME staff 102 Oct 21 18:44 Documents 133 | drwx------+ 3 USERNAME staff 102 Oct 21 18:44 Downloads 134 | drwx------@ 43 USERNAME staff 1462 Apr 12 00:15 Library 135 | drwx------+ 3 USERNAME staff 102 Oct 21 18:44 Movies 136 | drwx------+ 3 USERNAME staff 102 Oct 21 18:44 Music 137 | drwx------+ 3 USERNAME staff 102 Oct 21 18:44 Pictures 138 | drwxr-xr-x+ 5 USERNAME staff 170 Oct 21 18:44 Public 139 | COMPUTERNAME:~ USERNAME$ 🁢 140 | ``` 141 | 142 | You can also add the name of a directory as an argument to see the contents of that directory, for example `ls -la Public` 143 | 144 | ``` 145 | COMPUTERNAME:~ USERNAME$ ls -la Public 146 | total 0 147 | drwxr-xr-x+ 5 ChristopherA staff 170 Oct 21 18:44 . 148 | drwxr-xr-x+ 13 ChristopherA staff 442 Apr 12 12:41 .. 149 | -rw-r--r-- 1 ChristopherA staff 0 Oct 21 18:44 .com.apple.timemachine.supported 150 | -rw-r--r-- 1 ChristopherA staff 0 Oct 21 18:44 .localized 151 | drwx-wx-wx+ 3 ChristopherA staff 102 Oct 21 18:44 Drop Box 152 | COMPUTERNAME:~ USERNAME$ 🁢 153 | ``` 154 | 155 | Tab Completion 156 | -------------- 157 | 158 | A useful feature that the command line offers is called "command line completion" or "tab completion". What this means if you enter insufficient information about an argument, you can press the `tab` key to see what the choices are, or if there is only one choice, select that one. 159 | 160 | Try this out by typing `ls M` then press the `tab` key instead of return. 161 | 162 | ``` 163 | COMPUTERNAME:~ USERNAME$ ls M→ 164 | Movies/ Music/ 165 | COMPUTERNAME:~ USERNAME$ ls M🁢 166 | ``` 167 | 168 | In this case there are two items that begin with M, so the command line lists them both, and retains the text that you started. Now add one more letter, `o` and press the `tab` key: 169 | 170 | ``` 171 | COMPUTERNAME:~ USERNAME$ ls Movies/🁢 172 | ``` 173 | 174 | There was only one item that began with `Mo`, the Movies directory. If you press `return` you will see the contents of that folder. 175 | 176 | Tab completion is very useful for file names that have spaces in them. For instance: 177 | 178 | ``` 179 | COMPUTERNAME:~ USERNAME$ls -la Public/Drop Box 180 | ls: Box: No such file or directory 181 | ls: Public/Drop: No such file or directory 182 | COMPUTERNAME:~ USERNAME$ 🁢 183 | ``` 184 | 185 | Basically the `ls` program is confused by the space in name of the directory `Drop Box`, and it thinks you want to list the contents of `Drop` and `Box` as separate arguments. 186 | 187 | You can fix this by putting quotes around the path and file name: 188 | 189 | ``` 190 | COMPUTERNAME:~ USERNAME$ls -la "Public/Drop Box" 191 | total 0 192 | drwx-wx-wx+ 3 ChristopherA staff 102 Oct 21 18:44 . 193 | drwxr-xr-x+ 5 ChristopherA staff 170 Oct 21 18:44 .. 194 | -rw-r--r-- 1 ChristopherA staff 0 Oct 21 18:44 .localized 195 | COMPUTERNAME:~ USERNAME$ 🁢 196 | ``` 197 | 198 | Alternatively can fix this by "escaping" the space by putting a backslash in front it, for example: 199 | 200 | ``` 201 | COMPUTERNAME:~ USERNAME$ls -la Public/Drop\ Box 202 | total 0 203 | drwx-wx-wx+ 3 ChristopherA staff 102 Oct 21 18:44 . 204 | drwxr-xr-x+ 5 ChristopherA staff 170 Oct 21 18:44 .. 205 | -rw-r--r-- 1 ChristopherA staff 0 Oct 21 18:44 .localized 206 | COMPUTERNAME:~ USERNAME$ 🁢 207 | ``` 208 | 209 | Finally, you just type `ls -la Pu` then press tab, then type `D` and press tab again. The path will be auto-completed with all the spaces properly escaped. 210 | 211 | Finder Path Trick 212 | ----------------- 213 | 214 | One trick for very long paths with spaces and other special characters in them is that you can drag the file or folder from a Finder window (or the folder icon in the title bar of a Finder window) to the prompt, and the full path and file name will be appended to your command line. 215 | 216 | Try `ls ` followed by dragging a random folder open in the Finder's GUI, then press `return`. 217 | 218 | Absolute Paths and Home Directory 219 | --------------------------------- 220 | 221 | So far, we have listed the contents of directories that exist inside our current directory. Every directory on your computer has a name and a path that takes you to it. 222 | 223 | What if we want to see other directories? One way is by what is known as the "absolute path". These paths begin with the the `/` character. 224 | 225 | Try it: 226 | 227 | ``` 228 | COMPUTERNAME:~ USERNAME$ls / 229 | Applications home 230 | Library installer.failurerequests 231 | System net 232 | Users private 233 | Volumes sbin 234 | bin tmp 235 | dev usr 236 | etc var 237 | COMPUTERNAME:~ USERNAME$ 🁢 238 | ``` 239 | 240 | This reveals items in the "root" folder of your computer. Some you will recognize from the Finder GUI, others are invisible to the Finder. From the command-line, the root directory `/` is the starting point all the contents of your computer. It contains all the directories on your boot drive, directories for other drives, as well as a number of special system directories. 241 | 242 | Now lets look at the absolute path for the Users Directory: 243 | 244 | ``` 245 | COMPUTERNAME:~ USERNAME$ls /Users 246 | USERNAME Shared 247 | COMPUTERNAME:~ USERNAME$ 🁢 248 | ``` 249 | 250 | Now lets add your user name (if it has a space in it try tab completion!): 251 | 252 | ``` 253 | COMPUTERNAME:~ USERNAME$ls /Users/USERNAME 254 | Desktop Downloads Movies Pictures 255 | Documents Library Music Public 256 | COMPUTERNAME:~ USERNAME$ 🁢 257 | ``` 258 | 259 | This is is your current working directory, which is also the default "home" directory that the shell application defaults to, so it gives same exact result as `ls` by itself. 260 | 261 | Your home directory `/Users/USERNAME/` or `~` for short, contains your personal files and directories. For example Pictures, Music, Documents, etc. Each of these directories is referenced as /home/USERNAME/{directory name}. For example Documents is located at /home/USERNAME/Documents. 262 | 263 | This home path will be different for each user of the machine, so there is a shortcut for it that is different for each user, taking them to their home directory. This is the tilde character `~`. Thus `ls`, `ls /Users/USERNAME/` and 'ls ~` all give the same result. 264 | 265 | Like with directories, files are referenced in the same way, for example a file named temp.txt located at the home directory of the user christophera can be referenced using the full path `/Users/christophera/temp.txt` or `~/temp.txt` by that user. 266 | 267 | Both files and directories can be referenced using their absolute paths from everywhere in the system. Additionally one can access them using only their name if it is in the same directory. For example, if your current working directory is `~` when using the terminal, you can access `/Users/USERNAME/temp.txt` file by entering just `temp.txt`. 268 | 269 | Changing Working Directory 270 | -------------------------- 271 | 272 | In all of the examples above our current working directory path was the home directory. To change the current working directory, type `cd` followed by the {directory path}, for example: 273 | 274 | ``` 275 | COMPUTERNAME:~ USERNAME$cd Desktop 276 | COMPUTERNAME:Desktop USERNAME$ 🁢 277 | ``` 278 | 279 | Note that your prompt now displays your working directory. To see the "absolute" path of that directory, type `pwd` again. 280 | 281 | ``` 282 | COMPUTERNAME:Desktop USERNAME$ pwd 283 | /Users/USERNAME/Desktop 284 | COMPUTERNAME:Desktop USERNAME$ 🁢 285 | ``` 286 | 287 | To return to your home directory, you can type `cd` with no options or arguments, but I prefer to type `cd ~` to remind me that I'm returning to home. 288 | 289 | Creating a Temp Directory 290 | ----------------------------- 291 | 292 | In most of the remaining examples I'm no longer going to demonstrate the full prompt. Instead, when you see the first `$` it shows where you are to type to the right of that prompt. A final `$` with no text shows that the the output from your command has completed. 293 | 294 | As we don't want to clutter our home directory with lots of files, let's create a `temp` directory to hold our future work. We will use the `mkdir` (_make directory_) command, then enter the folder with the `cd` command, and confirm that we are there with the `pwd' command. 295 | 296 | ``` 297 | $ cd ~ 298 | $ mkdir temp 299 | $ cd temp 300 | $ pwd 301 | /Users/USERNAME/temp 302 | $ 303 | ``` 304 | 305 | Manipulating Files 306 | ------------------ 307 | 308 | To create your first empty file, use the `touch` command followed by the filename: 309 | 310 | ``` 311 | $ touch temp.txt 312 | $ 313 | ``` 314 | 315 | You can see that this file exists with the `ls` command: 316 | 317 | ``` 318 | $ ls 319 | temp.txt 320 | $ 321 | ``` 322 | 323 | You can edit this text file with your Mac GUI text editor (by default the _Text Edit_ app in your _Applications_ folder) by using the `open` command. 324 | 325 | ``` 326 | $ open temp.txt 327 | $ 328 | ```` 329 | 330 | Enter some text in that file, save it (use `command + S`) and close it (use `command + W`). Then go back to terminal using either `command + tab` to cycle through your apps, or `command + space + term`. When using the Mac command-line it is important to learn these command keys — your hands should rarely need to leave the keyboard. 331 | 332 | Now we can display that text using the `cat` command (whose name is short for _concatenate_). 333 | 334 | ``` 335 | $ cat temp.txt 336 | The quick brown fox jumped over the lazy dog. 337 | $ 338 | ```` 339 | 340 | If there were many pages of text, you can also use the `more` command, which if there is more than window of text will display one window full at a time. Just type `space` to see the next window, or `q` to quit, or `h` to see a list of other choices. 341 | 342 | Now we can copy that file using the `cp` (_copy_) command. 343 | 344 | ``` 345 | $ cp temp.txt temporary.txt 346 | $ cat temporary.txt 347 | The quick brown fox jumped over the lazy dog. 348 | $ ls 349 | temp.txt temporary.txt 350 | $ 351 | ```` 352 | 353 | We can copy that file to another directory as well, by adding the path. In this case we will copy a temp file to the home directory. 354 | 355 | ``` 356 | $ cp temp.txt ~/temp.txt 357 | $ ls ~/*.txt 358 | temp.txt 359 | $ 360 | ```` 361 | 362 | We can rename a file using the `mv` (_move_) command. 363 | 364 | ``` 365 | $ mv temp.txt temp.bak 366 | $ ls 367 | temp.bak temporary.txt 368 | $ 369 | ``` 370 | 371 | We can also move a file with the same command. 372 | 373 | ``` 374 | $ ls 375 | temp.bak temporary.txt 376 | $ ls ~/*.txt 377 | temp.txt 378 | $ mv ~/temp.txt ./temp.txt 379 | $ ls 380 | temp.bak temp.txt temporary.txt 381 | $ ls ~/*.txt 382 | $ 383 | ``` 384 | 385 | 386 | We can delete all these file using the `rm` command (short for _remove_). Since `rm` can be dangerous, I always recommend you use it with the option `-i` which makes it interactive. 387 | 388 | ``` 389 | $ rm -i temp.txt 390 | remove temp.txt? y 391 | $ rm -i temporary.txt 392 | remove temporary.txt? y 393 | $ rm -i temp.bak 394 | remove temp.bak? y 395 | $ 396 | ```` 397 | 398 | 399 | The .. and . Relative Paths 400 | --------------------------- 401 | 402 | There are two special paths, the `.` and '..` - these are are used for what are _relative_ paths. 403 | 404 | The `..` directory is the directory _above_ the current working directory. So while still in the `~/temp` directory you type 'ls ..` and you will see the contents of the home directory: 405 | 406 | ``` 407 | $ ls .. 408 | Desktop Downloads Movies Pictures 409 | Documents Library Music Public 410 | $ 411 | ``` 412 | 413 | While in the ~/temp you can also enter `ls ..\{directory name}` to see sibling directories under the home directory. 414 | 415 | If you were deep inside a complex set of directories, you can get out of them by entering `cd ..` - note how the prompt changes after each command: 416 | 417 | ``` 418 | COMPUTERNAME:~ temp USERNAME$ pwd 419 | /Users/ChristopherA/temp 420 | COMPUTERNAME:~ temp USERNAME$ cd .. 421 | COMPUTERNAME:~ USERNAME$ cd .. 422 | COMPUTERNAME:Users USERNAME$ cd .. 423 | COMPUTERNAME:/ USERNAME$ cd ~/temp 424 | COMPUTERNAME:temp USERNAME$ pwd 425 | /Users/USERNAME/temp 426 | COMPUTERNAME:~ USERNAME$ 427 | ``` 428 | 429 | A path beginning with `.` means relative to the current working directory. In effect `ls .` is the same as `ls`. There are times when you absolutely want a path to be relative to where you are currently, use the `.` form. 430 | 431 | The * and ? Wildcards 432 | --------------------- 433 | 434 | Sometimes you want copy, rename or delete multiple files all at once. We can do this by using the `*` (sometimes called _star_) wildcard character to replace zero or more characters in a filename or directory. 435 | 436 | The command `rm *` will delete every thing in the current working directory except for those files that are special and begin with a `.`, thus until you are very experienced, I recommend that you always use the `-i` (for _interactive_) option when using `rm`. 437 | 438 | Try this experiment: 439 | 440 | ``` 441 | $ cd ~/temp 442 | $ ls 443 | $ ls -a 444 | . .. 445 | $ mkdir there 446 | $ touch .where here that then 447 | $ ls 448 | here that then there 449 | $ ls -a 450 | . .. .where here that then there 451 | $ rm -i t* 452 | remove that? y 453 | remove then? y 454 | rm: there: is a directory 455 | $ ls 456 | here there 457 | $ ls -a 458 | . .. .where here there 459 | $ rm -i * 460 | remove here? y 461 | rm: there: is a directory 462 | $ ls 463 | there 464 | $ ls -a 465 | . .. .where there 466 | $ rm -i .w* 467 | remove .where? y 468 | $ rm -i .* 469 | rm: "." and ".." may not be removed 470 | $ 471 | ``` 472 | As you can see, trying to remove directories, including the `.` (the current directory) and `..` (the parent directory) is not allowed with the `rm -i` command. So how do you delete directories? With the `rmdir` command. 473 | 474 | ``` 475 | $ ls 476 | there 477 | $ rmdir there 478 | $ ls 479 | $ 480 | ``` 481 | 482 | This command may seem dangerous, but the `rmdir` command has a failsafe that doesn't allow you to delete folders that have contents. First you must delete any contents. 483 | 484 | ``` 485 | $ mkdir there 486 | $ touch there/that 487 | $ ls there 488 | that 489 | A$ rmdir there 490 | rmdir: there: Directory not empty 491 | $ rm -i there/* 492 | remove there/that? y 493 | $ rmdir there 494 | $ ls 495 | $ 496 | ``` 497 | 498 | A particularly common use of the `*` wildcard is to view or delete only files with certain extensions. For instance: 499 | 500 | ``` 501 | $ touch a.txt b.txt a.jpg b.jpg 502 | $ ls a* 503 | a.jpg a.txt 504 | $ ls a.* 505 | a.jpg a.txt 506 | $ ls *.txt 507 | a.txt b.txt 508 | $ rm -i a.* 509 | remove a.jpg? y 510 | remove a.txt? y 511 | $ ls 512 | b.jpg b.txt 513 | $ rm -i *.txt 514 | remove b.txt? y 515 | $ ls 516 | b.jpg 517 | $ rm -i *.* 518 | remove b.jpg? y 519 | $ ls 520 | $ 521 | ``` 522 | 523 | Suppose you have some files ending in `.jpg` and some ending in `.jpeg` -- the asterisk wildcard makes clean-up easy: 524 | 525 | ``` 526 | $ touch a.jpg b.jpeg c.java d.js 527 | $ rm -i *.jp*g 528 | remove a.jpg? y 529 | remove b.jpeg? y 530 | $ rm -i *.j* 531 | remove c.java? y 532 | remove d.js? y 533 | $ ls 534 | $ 535 | ``` 536 | 537 | The `*` wildcard match zero or more characters, but sometimes you may want to match only one character. In this case we use the `?` wildcard: 538 | 539 | ``` 540 | $ touch task taskA taskB taskXY 541 | $ ls task* 542 | task taskA taskB taskXY 543 | $ ls task? 544 | taskA taskB 545 | $ ls task?? 546 | taskXY 547 | $ rm -i ?ask* 548 | remove task? y 549 | remove taskA? y 550 | remove taskB? y 551 | remove taskXY? y 552 | $ ls 553 | $ 554 | ``` 555 | 556 | So now that we are done with our temp directory, we can delete the entire directory and all of its contents at once with the `rm -ir` command and option: 557 | 558 | ``` 559 | $ cd .. 560 | $ pwd 561 | /Users/USERNAME 562 | $ ls temp 563 | task taskA taskB taskXY 564 | $ rm -ir temp 565 | examine files in directory temp? y 566 | remove temp/task? y 567 | remove temp/taskA? y 568 | remove temp/taskB? y 569 | remove temp/taskXY? y 570 | remove temp? y 571 | $ 572 | ``` 573 | 574 | Getting Help 575 | ------------ 576 | 577 | If you don't remember what a command does, there is a command `whatis` that returns basic one line of information about it. You can also use it to search for complete words in a commands description: 578 | 579 | ``` 580 | $ whatis cat 581 | cat(1) - concatenate and print files 582 | $ whatis rm 583 | rm(1), unlink(1) - remove directory entries 584 | $ whatis delete 585 | at(1), batch(1), atq(1), atrm(1) - queue, examine, or delete jobs for later execution 586 | delete(n) - delete things in the interpreter 587 | ldapdelete(1) - LDAP delete entry tool 588 | rename(ntcl) - Rename or delete a command 589 | unset(ntcl) - Delete variables 590 | $ 591 | ``` 592 | 593 | Related is `apropos` which allows you to search keywords. It will typically return many more items than `whatis`. 594 | 595 | ``` 596 | $ whatis unzip 597 | unzip(1) - list, test and extract compressed files in a ZIP archive 598 | $ apropos unzip 599 | bzip2(1), bunzip2(1) - a block-sorting file compressor, v1.0.6 bzcat - decompresses files to stdout bzip2recover - recovers data from damaged bzip2 files 600 | funzip(1) - filter for extracting from a ZIP archive in a pipe 601 | unzip(1) - list, test and extract compressed files in a ZIP archive 602 | unzipsfx(1) - self-extracting stub for prepending to ZIP archives 603 | $ 604 | ``` 605 | 606 | Every one of these commands have help files associated with them, which can be viewed with the `man` (short for _manual_) command. 607 | 608 | Like the `more` command, typing `space` moves down a window full of text, and typing `q` will quit. You can even see the man page for man with `man man`. 609 | 610 | Many, but not all commands will give you a brief summary of what they do if you type them without any options, or with the option `-h` or `--help`. Many options may be cryptic, but the man page for the commands should explain them in more detail. 611 | 612 | MacOSX Bash Shell Keys 613 | ---------------------- 614 | 615 | ### The following work everywhere 616 | 617 | ``` 618 | Command-Shift-3 Capture the screen to a file 619 | Command-Shift-Control-3 Capture the screen to the Clipboard 620 | Command-Shift-4 Capture a selection of the screen to a file, or press the spacebar to capture just a window 621 | Command-Shift-Control-4 Capture a selection of the screen to the Clipboard, , or press the spacebar to capture just a window 622 | ``` 623 | 624 | ### The following keys work in most Mac apps where text entry is supported: 625 | 626 | ``` 627 | Cmd + A Select all text in text area 628 | Ctrl + A Move cursor to the beginning of the line or paragraph you are currently typing on 629 | Ctrl + B Move the cursor one character backward (same as Left-Arrow) 630 | Ctrl + D Delete one character in front of cursor (same as fn-Delete) 631 | Ctrl + E Move cursor to the end of the line you are currently typing on 632 | Ctrl + F Move the text cursor one character forward (same as Right-Arrow) 633 | Ctrl + H Delete the character behind the curor 634 | Ctrl + K Delete "Kills" all characters after cursor to the end of the line. 635 | Ctrl + N Move the cursor down one line (same as Down-Arrow) 636 | Ctrl + P Move the cursor up one line (same as Up-Arrow) 637 | Ctrl + T Swap the last two characters before the cursor 638 | Ctrl + Y Pastes "Yanks" text that was Killed (Ctrl+K) 639 | ``` 640 | 641 | ### The following only work in the Mac OSX Terminal using the default Bash shell: 642 | 643 | ``` 644 | Ctrl + C Kill whatever you are running 645 | Ctrl + D Exit the current shell 646 | Ctrl + G Aborts the current incremental search, restoring the original command at the prompt 647 | Ctrl + J Stops incremental search (Ctrl-R or Ctrl-S) and puts the found command at the prompt 648 | Ctrl + L Clears the the terminal window, leaving the current command at the prompt, similar to the clear command 649 | Ctrl + R Incrementally searches back through previously used commands (with history or !) 650 | Ctrl + S Incrementally searches forward through previously used commands (with history or !) 651 | Ctrl + U Clears the line before the cursor position. If you are at the end of the line, clears the entire line. 652 | Ctrl + W Delete the word before the cursor 653 | Ctrl + Z Puts whatever you are running into a suspended background process. fg restores it. 654 | Ctrl + _ Undo the last editing command; you can undo all the way back to an empty line 655 | Esc + B Move cursor backward one word on the current line 656 | Esc + D Delete one word in front of cursor 657 | Esc + F Move cursor forward one word on the current line 658 | Esc + R Undo all changes made to this line 659 | Esc + T Swap the last two words before the cursor 660 | Esc + Y Pastes "Yanks" text that was previous Killed (Ctrl+K) before the last Kill 661 | Tab Auto-complete files and folder names 662 | Tab Tab Display all possible auto-complete values 663 | ``` 664 | 665 | ### Mouse in Terminal 666 | ``` 667 | Opt + Click Moves cursor to where the mouse was clicked in many shell editors. 668 | ``` 669 | 670 | ## Meta commands 671 | `` 672 | ! - starts a history substitution 673 | !n - the n-th command in bash's history list, for some integer n (works for negatives too) 674 | !! - the preceding command; equivalent to !-1 675 | !string - the most recent command starting with string 676 | 677 | Word designators select certain parts from an event. Use : to separate the event from the word designator. Words are numbered from 0 starting at the beginning of the line, and inserted into the current line separated by single spaces. 678 | 679 | $ - designates the last argument (eg !!:$ is the last arg of last command; can be shortened to !$) 680 | n - designates the n-th word (eg !str:2 is the 2nd arg of the most recent command starting with str; !!:0 is the command of the last command) 681 | ``` 682 | -------------------------------------------------------------------------------- /part2-prepare.md: -------------------------------------------------------------------------------- 1 | Part 2 - Preparation and Installation 2 | ===================================== 3 | 4 | Every Mac supports a large numer of command line tools, however, not every program that you need for web development is included by default. This tutorial instructs you on how to prepare and configure your Mac to make it a powerful web development system. 5 | 6 | You do not need to deeply understand all the commands that are used here — they are explained briefly, but you do not lean to learn them yet. I am explaining only because it is YOUR computer and you should know what and why these tools have been added. 7 | 8 | System Updates 9 | -------------- 10 | 11 | The first thing you need to do is to make sure that you have the most recent version of the OS, which as of the writing of this intro is Mac OS X Yosemite 10.10.3. Everything in these introduction files should work on previous version of the the OS, however, when you are doing web development it is important to have the most recent updates for security reasons. 12 | 13 | You can get all your system updates by going the the _App Store…_ item under the Apple Menu, clicking on the _Updates_ tab and pressing the _Update All_ button. However, you can also do it from the command line. 14 | 15 | The `sudo` command is used to run programs that need additional privileges to change your computer, and thus your Mac's administrative password. `/usr/sbin/softwareupdate -l` is the program that checks with Apple's update servers for the most recent version. You may need to execute this command multiple times, or even reboot your system if your Mac is not current. 16 | 17 | ``` 18 | $ cd ~ 19 | $ sudo /usr/sbin/softwareupdate -l 20 | 21 | WARNING: Improper use of the sudo command could lead to data loss 22 | or the deletion of important system files. Please double-check your 23 | typing when using sudo. Type "man sudo" for more information. 24 | 25 | To proceed, enter your password, or type Ctrl-C to abort. 26 | 27 | Password: 28 | Software Update Tool 29 | Copyright 2002-2012 Apple Inc. 30 | 31 | Finding available software 32 | No new software available. 33 | $ 34 | ``` 35 | 36 | Install Apple's Command Line Tools 37 | ---------------------------------- 38 | 39 | Next we are going to install Apple's Command Line Tools, which will install a number of development tools that will be available from the command line. There is a "trick" of touching a file that makes this happen from the command line without loading Apple's XCODE development environment for creating Mac and iOS apps. 40 | 41 | Because you've recently entered an administrative password for the `sudo` command, the shell may not ask you for your admin password again. 42 | 43 | ``` 44 | $ touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress 45 | sudo /usr/sbin/softwareupdate -ia 46 | Software Update Tool 47 | Copyright 2002-2012 Apple Inc. 48 | 49 | Finding available software 50 | 51 | Downloading Command Line Tools (OS X 10.10) 52 | Downloaded Command Line Tools (OS X 10.10) 53 | Installing Command Line Tools (OS X 10.10) 54 | Done with Command Line Tools (OS X 10.10) 55 | Done. 56 | $/bin/rm /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress 57 | ``` 58 | 59 | With this installation you have just installed 92 development tools into your /Library/Developer/CommandLineTools/bin/ 60 | 61 | ``` 62 | BuildStrings CpMac DeRez GetFileInfo MergePef MvMac ResMerger Rez RezDet RezWack SetFile SplitForks UnRezWack ar as asa bison c++ c89 c99 cc clang clang++ cmpdylib codesign_allocate cpp ctags ctf_insert dsymutil dwarfdump dyldinfo flex flex++ g++ gatherheaderdoc gcc gcov git git-cvsserver git-receive-pack git-shell git-upload-archive git-upload-pack gm4 gnumake gperf hdxml2manxml headerdoc2html indent install_name_tool ld lex libtool lipo lldb llvm-cov llvm-profdata lorder m4 make mig mkdep nasm ndisasm nm nmedit otool pagestuff projectInfo ranlib rebase redo_prebinding resolveLinks rpcgen segedit size strings strip svn svnadmin svndumpfilter svnlook svnrdump svnserve svnsync svnversion unifdef unifdefall unwinddump what xml2man yacc 63 | ``` 64 | 65 | From now on, the Mac App Store's regular System Update will keep these tools current. 66 | 67 | Create Some Additional Folders in Home 68 | -------------------------------------- 69 | 70 | I find it useful to prepare in advance some additional folder in my home "~" directory. The convention I use is that if the folder starts with a Capital, the folder contains items for Finder's GUI. If the folder begins with a lower-case letter (making it faster to type) then it is to used by the CLI. 71 | 72 | All of these folders are optional — many you will not use until much later in this tutorial: 73 | 74 | * ~/.dotfiles # This is where I backup my dotfiles (explained later) and store some other useful tools. 75 | * ~/.dotfiles/bin # This is where I keep small command line scripts that I use regularly. 76 | * ~/Applications # This is where I keep any GUI apps that are installed for development purposes seperate from those root /Applications folder. 77 | * ~/code # This is where store the source code from open source repositories from github 78 | * ~/Pool # This is where I store large files that I exclude from backing up on Time Machine. Great for movies, large installer files, etc. that I have backuped up elsewhere or are easily downloaded again from the net. 79 | * ~/projects # This is where I keep repositories of my own source code or others work-in-progress. 80 | * ~/temp # This is where I keep code and projects that are just temporary and can be deleted at any time. I practice here. 81 | 82 | ``` 83 | $ mkdir ~/.dotfiles ~/.dotfiles/bin ~/Applications ~/code ~/Pool ~/projects ~/temp 84 | $ ls -a 85 | . Desktop Pictures 86 | .. Documents Pool 87 | .CFUserTextEncoding Downloads Public 88 | .Trash Library code 89 | .dotfiles Movies projects 90 | Applications Music temp 91 | 92 | $ 93 | ``` 94 | 95 | Installing Brew 96 | --------------- 97 | 98 | Next we are going to install [Homebrew](http://brew.sh) (known as `brew` for short), a software package manager. 99 | 100 | You can consider `brew` to be an app store for open source web apps and developer tools. There are thousands of different open source code bases, all with various dependences on each other, and each requiring different configurations for what kind of computer OS it is running on (Linux, Unix, Mac, Windows, etc.). Brew manages those complexities. If request to install a particular tool it that needs other packages, tools or libraries to run, Brew will first install them in the correct order. Brew also stores its files in some specific ways that are best practices so that different tools don't interfere with each other. 101 | 102 | Brew is not installed on your Mac by default, so you'll need to run a script to install it. They provide a script to install it on their github site, which is run by `ruby` which is installed on your Mac by default. WARNING: Be cautious whenever someone asks you to run a script that has `curl` command in it, because if the author is malicious they can corrupt your system or make it vulnerable. In this case the script is run from a trusted website (github), and is from a trusted account there (Homebrew). I suggest you go to the [Homebrew](http://brew.sh) website and confirm that this is the correct script to use. 103 | 104 | This script may ask you for your administrator password. 105 | 106 | ``` 107 | $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 108 | ==> This script will install: 109 | /usr/local/bin/brew 110 | /usr/local/share/doc/homebrew 111 | /usr/local/share/man/man1/brew.1 112 | /usr/local/share/zsh/site-functions/_brew 113 | /usr/local/etc/bash_completion.d/brew 114 | /usr/local/Homebrew 115 | ==> The following new directories will be created: 116 | /usr/local/Cellar 117 | /usr/local/Homebrew 118 | /usr/local/Frameworks 119 | /usr/local/bin 120 | /usr/local/etc 121 | /usr/local/include 122 | /usr/local/lib 123 | /usr/local/opt 124 | /usr/local/sbin 125 | /usr/local/share 126 | /usr/local/share/zsh 127 | /usr/local/share/zsh/site-functions 128 | /usr/local/var 129 | 130 | Press RETURN to continue or any other key to abort 131 | ==> /usr/bin/sudo /bin/mkdir -p /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var 132 | ==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var 133 | ==> /usr/bin/sudo /bin/chmod u+rwx share/zsh share/zsh/site-functions 134 | ==> /usr/bin/sudo /usr/sbin/chown admin /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var 135 | ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var 136 | ==> /usr/bin/sudo /bin/mkdir -p /Users/admin/Library/Caches/Homebrew 137 | ==> /usr/bin/sudo /bin/chmod g+rwx /Users/admin/Library/Caches/Homebrew 138 | ==> /usr/bin/sudo /usr/sbin/chown admin /Users/admin/Library/Caches/Homebrew 139 | ==> Downloading and installing Homebrew... 140 | remote: Counting objects: 1033, done. 141 | remote: Compressing objects: 100% (929/929), done. 142 | remote: Total 1033 (delta 95), reused 592 (delta 68), pack-reused 0 143 | Receiving objects: 100% (1033/1033), 1.05 MiB | 508.00 KiB/s, done. 144 | Resolving deltas: 100% (95/95), done. 145 | From https://github.com/Homebrew/brew 146 | * [new branch] master -> origin/master 147 | HEAD is now at 23efbc5 Merge pull request #1051 from woodruffw/cctools-macho-remove 148 | ==> Homebrew has enabled anonymous aggregate user behaviour analytics 149 | Read the analytics documentation (and how to opt-out) here: 150 | https://git.io/brew-analytics 151 | ==> Tapping homebrew/core 152 | Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'... 153 | remote: Counting objects: 3725, done. 154 | remote: Compressing objects: 100% (3617/3617), done. 155 | remote: Total 3725 (delta 15), reused 1247 (delta 0), pack-reused 0 156 | Receiving objects: 100% (3725/3725), 2.91 MiB | 1.13 MiB/s, done. 157 | Resolving deltas: 100% (15/15), done. 158 | Checking connectivity... done. 159 | Tapped 3604 formulae (3,752 files, 9M) 160 | Checking out v1.0.1 in /usr/local/Homebrew... 161 | To checkout master in /usr/local/Homebrew run: 162 | 'cd /usr/local/Homebrew && git checkout master 163 | Already up-to-date. 164 | ==> Installation successful! 165 | ==> Next steps 166 | Run `brew help` to get started 167 | Further documentation: https://git.io/brew-docs 168 | ==> Homebrew has enabled anonymous aggregate user behaviour analytics 169 | Read the analytics documentation (and how to opt-out) here: 170 | https://git.io/brew-analytics 171 | $ 172 | ``` 173 | 174 | After installing Homebrew, the first thing we want to do is confirm that it has been installed correctly, or if there has been something else installed on your Mac previously that will cause problems. 175 | 176 | ``` 177 | $ brew doctor 178 | Your system is ready to brew. 179 | $ 180 | ``` 181 | 182 | If there were any errors, `brew doctor` will tell you how to fix them. If what it suggests to fix the problem doesn't work, I find that almost every problem that has come up is a question on the website [StackOverflow](http://stackoverflow.com) so search for your solution there. 183 | 184 | Install Git 185 | ----------- 186 | 187 | The first command line application we will install is [Git](http://git-scm.com), which is the most popular source code version control system. A source code control system helps you manage the production of your code, backup and restore different versions of your code, and work cooperatively with others. `git` is popular because it is open source, it is distributed (i.e. there isn't one master repository the files have to come from), works with projects as large as the Linux operating system with thousands of contributors, small team projects, and yet is useful for even for a single programmer. 188 | 189 | We will use `brew` to install git, so always before we brew anything we want to make sure that `brew` is current. We just installed it so we don't really need to do this now, but I will demonstrate best practices (everything after a # is a comment): 190 | 191 | ``` 192 | $ brew doctor # run self test to see if brew is running properly 193 | Your system is ready to brew. 194 | $ brew update # update brew itself to the latest version, and get latest list of apps 195 | Already up-to-date. 196 | $ brew upgrade # upgrade any apps managed by brew to the most recent version 197 | $ 198 | ``` 199 | 200 | Next we wil confirm information about git, then we install it. 201 | 202 | ``` 203 | $ brew info git 204 | git: stable 2.3.5 (bottled), HEAD 205 | http://git-scm.com 206 | /usr/local/Cellar/git/2.3.5 (1363 files, 31M) * 207 | Not installed 208 | From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/git.rb 209 | $ brew install git 210 | ==> Downloading https://homebrew.bintray.com/bottles/git-2.3.5.yosemite.bottle.t 211 | ######################################################################## 100.0% 212 | ==> Pouring git-2.3.5.yosemite.bottle.tar.gz 213 | ==> Caveats 214 | The OS X keychain credential helper has been installed to: 215 | /usr/local/bin/git-credential-osxkeychain 216 | 217 | The "contrib" directory has been installed to: 218 | /usr/local/share/git-core/contrib 219 | 220 | Bash completion has been installed to: 221 | /usr/local/etc/bash_completion.d 222 | 223 | zsh completion has been installed to: 224 | /usr/local/share/zsh/site-functions 225 | ==> Summary 226 | 🍺 /usr/local/Cellar/git/2.3.5: 1363 files, 31M 227 | $ git --version 228 | git version 2.3.5 229 | $ 230 | ``` 231 | 232 | Install Cask 233 | ------------ 234 | 235 | [Cask](http://caskroom.io) is a special brew application that installs a number of Mac GUI apps. I find it particularly useful for installing those developer apps require an installer or a .dmg file. One other useful thing that it does is that it puts the app into your ~/Applications folder, keeping them seperate from your other apps. 236 | 237 | ``` 238 | $ brew tap caskroom/cask 239 | Checking out v1.0.1 in /usr/local/Homebrew... 240 | To checkout v1.0.1 in /usr/local/Homebrew run: 241 | 'cd /usr/local/Homebrew && git checkout v1.0.1 242 | ==> Tapping caskroom/cask 243 | Cloning into '/usr/local/Homebrew/Library/Taps/caskroom/homebrew-cask'... 244 | remote: Counting objects: 3431, done. 245 | remote: Compressing objects: 100% (3412/3412), done. 246 | remote: Total 3431 (delta 37), reused 452 (delta 13), pack-reused 0 247 | Receiving objects: 100% (3431/3431), 1.16 MiB | 0 bytes/s, done. 248 | Resolving deltas: 100% (37/37), done. 249 | Checking connectivity... done. 250 | Tapped 0 formulae (3,438 files, 3.6M) 251 | $ 252 | ``` 253 | 254 | Installing the Atom Text Editor 255 | ------------------------------- 256 | 257 | Next we are going to use `brew cask` to install the Atom text editor. There are many powerful command line text editors out there (and a constant battle between fans of emacs vs those for vim), but learning them is outside the scope of this tutorial. In the meantime there is a very powerful, free and open source GUI text editor optimized for command line and web developers called Atom. One of its best features is its integration with Git. 258 | 259 | We will install it with `brew cask` 260 | 261 | ``` 262 | $ brew cask install atom 263 | ==> We need to make Caskroom for the first time at /opt/homebrew-cask/Caskroom 264 | ==> We'll set permissions properly so we won't need sudo in the future 265 | Password: 266 | chmod: /opt: No such file or directory 267 | ==> Downloading https://atom.io/download/mac 268 | ######################################################################## 100.0% 269 | ==> Symlinking App 'Atom.app' to '/Users/ChristopherA/Applications/Atom.app' 270 | ==> Symlinking Binary 'apm' to '/usr/local/bin/apm' 271 | ==> Symlinking Binary 'atom.sh' to '/usr/local/bin/atom' 272 | 🍺 atom staged at '/opt/homebrew-cask/Caskroom/atom/latest' (11288 files, 239M) 273 | $ 274 | ``` 275 | 276 | From now own instead of using the `open` command to edit a text file, we will use `atom`, for example: 277 | 278 | ``` 279 | $ touch ~/temp/temp.txt 280 | $ atom ~/temp/temp.txt 281 | ``` 282 | You can now edit this file using the familar Mac GUI experience. 283 | 284 | Install Node 285 | ------------ 286 | 287 | [Node](https://nodejs.org) is a popular web server tool that runs Javascript. Installed on the Mac, it also provides an interactive environment for learning how to Javascript code and use various frameworks. We are installing it because a number of tutorials later use it. 288 | 289 | ``` 290 | $ brew install node 291 | ==> Downloading https://homebrew.bintray.com/bottles/node-0.12.2_1.yosemite.bott 292 | ######################################################################## 100.0% 293 | ==> Pouring node-0.12.2_1.yosemite.bottle.tar.gz 294 | ==> Caveats 295 | If you update npm itself, do NOT use the npm update command. 296 | The upstream-recommended way to update npm is: 297 | npm install -g npm@latest 298 | 299 | Bash completion has been installed to: 300 | /usr/local/etc/bash_completion.d 301 | ==> Summary 302 | 🍺 /usr/local/Cellar/node/0.12.2_1: 2603 files, 28M 303 | $ 304 | ``` 305 | 306 | Web Get 307 | ------- 308 | 309 | I find the `wget` tool to be very useful. Point it to a URL and it downloads the contents to a file. You can also do this with the built-in `curl` tool, but I find `wget` very useful at time. 310 | 311 | ``` 312 | $ brew install wget 313 | ==> Installing wget dependency: openssl 314 | ==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2a-1.yosemite.bottle.tar.gz 315 | ######################################################################## 100.0% 316 | ==> Pouring openssl-1.0.2a-1.yosemite.bottle.tar.gz 317 | ==> Caveats 318 | A CA file has been bootstrapped using certificates from the system 319 | keychain. To add additional certificates, place .pem files in 320 | /usr/local/etc/openssl/certs 321 | 322 | and run 323 | /usr/local/opt/openssl/bin/c_rehash 324 | 325 | This formula is keg-only, which means it was not symlinked into /usr/local. 326 | 327 | Mac OS X already provides this software and installing another version in 328 | parallel can cause all kinds of trouble. 329 | 330 | Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries 331 | 332 | Generally there are no consequences of this for you. If you build your 333 | own software and it requires this formula, you'll need to add to your 334 | build variables: 335 | 336 | LDFLAGS: -L/usr/local/opt/openssl/lib 337 | CPPFLAGS: -I/usr/local/opt/openssl/include 338 | 339 | ==> Downloading https://www.geotrust.com/resources/root_certificates/certificates/Equifax_Secure_ 340 | ######################################################################## 100.0% 341 | ==> /usr/local/Cellar/openssl/1.0.2a-1/bin/c_rehash 342 | ==> Summary 343 | 🍺 /usr/local/Cellar/openssl/1.0.2a-1: 463 files, 18M 344 | ==> Installing wget 345 | ==> Downloading https://homebrew.bintray.com/bottles/wget-1.16.3.yosemite.bottle.tar.gz 346 | ######################################################################## 100.0% 347 | ==> Pouring wget-1.16.3.yosemite.bottle.tar.gz 348 | 🍺 /usr/local/Cellar/wget/1.16.3: 9 files, 1.5M 349 | Aeguss-MacBook-Pro:intro-mac-command-line ChristopherA$ 350 | ``` 351 | 352 | Brew & Cask Cleanup 353 | ------------------- 354 | 355 | Ater we `brew` or `brew cask` anything it is best practices to tell brew to cleanup. You don't have to do this after each item brew, you can brew a number of items at once and only cleanup after. 356 | 357 | ``` 358 | $ brew linkapps --local 359 | Finished linking. Find the links under /Users/ChristopherA/Applications. 360 | $ brew cleanup 361 | $ brew prune 362 | Pruned 0 dead formulae 363 | $ brew cask cleanup 364 | brew cask cleanup 365 | ==> Removing dead symlinks 366 | Nothing to do 367 | ==> Removing cached downloads 368 | /Library/Caches/Homebrew/atom-latest 369 | /Library/Caches/Homebrew/Casks/atom-latest 370 | $ 371 | ``` 372 | 373 | Final Cleanup 374 | ------------- 375 | 376 | The locate and whathis databases, used by the command line utilities `locate`, `whatis` and `apropos`, are only generated weekly, so run this after adding any commands to update the database. This will happen in the background and can take some time to generate the first time. 377 | 378 | ``` 379 | $ sudo periodic daily weekly monthly 380 | ``` 381 | -------------------------------------------------------------------------------- /part3-customize.md: -------------------------------------------------------------------------------- 1 | Part 3 - Customize Your Environment 2 | =================================== 3 | 4 | This part is entirely optional. In it I have a number of recommendations as to how to customize your command line "environment" so that it will be a little easier to use. There is nothing here that is required for later on. 5 | 6 | 7 | Solarized Terminal Profiles 8 | --------------------------- 9 | 10 | The _Terminal_ app allows you to choose from a number of options for how the terminal window is displayed. Open it's _Terminal_ menu _Preferences_ submenu and a number of options can be defined. Click on the _Profiles_ tab and see the choices. Of the default options, the _Homebrew_ profile is a useful choice — it is bright text on dark, which I personally find easier for coding. 11 | 12 | I personally use a dark background, but with a more subtly colored text based on the [Solarized](http://ethanschoonover.com/solarized). You can download and open my preferences using the `wget` command. 13 | 14 | ``` 15 | $ cd ~/temp 16 | $ wget https://github.com/ChristopherA/dotfiles/blob/master/install/osxterminal/christophera-dark.terminal 17 | $ open christophera-dark.terminal 18 | $ rm christophera-dark.terminal 19 | ``` 20 | 21 | In the _Terminal_'s _Preferences_, in the _General_ pane, set the "On startup open: New window with profile" and then select 'christophera-dark' 22 | 23 | You can set Atom's theme to use the a similar set of dark solarized colors. The theme is called _Solarized Dark_ and it comes installed by default with Atom and can be activated by going to the Themes section in the Settings view `command + -`) and selecting it from the Syntax Themes dropdown menu. 24 | 25 | CLI Colors 26 | ========== 27 | 28 | You can enable syntax colors for how various commands output text the command line. To see this, try this: 29 | 30 | ``` 31 | $ export CLICOLOR=1 32 | ``` 33 | 34 | Now type `ls -la` and you will see that directories and files are listed with different colors. 35 | 36 | For compatibility with the solarized terminal theme, I also set some specific colors that I find blend well: 37 | 38 | ``` 39 | $ export LSCOLORS=gxfxbEaEBxxEhEhBaDaCaD 40 | $ export LS_COLORS="di=36;40:ln=35;40:so=31;:pi=0;:ex=1;;40:bd=0;:cd=37;:su=37;:sg=0;:tw=0;:ow=0;:" 41 | ``` 42 | 43 | Now if you want these colors to be displayed ever time you open _Terminal_, you'll need to add them to a special file so that they will be always loaded. This file is called is `~/.bash_profile`. 44 | 45 | ``` 46 | $ atom ~/.bash_profile 47 | ``` 48 | 49 | Add all three lines (with out the $), save, quit _Terminal_ and launch it again, and you'll see all your color settings as you prefer. 50 | 51 | There is a `brew` app called `grc` (for [Generic Colourizer](http://kassiopeia.juls.savba.sk/~garabik/software/grc.html)) that adds colorization to a lot more commands than the above does. 52 | 53 | ``` 54 | $ brew install grc 55 | ==> Downloading http://korpus.juls.savba.sk/~garabik/software/grc/grc_1.9.orig.tar.gz 56 | ######################################################################## 100.0% 57 | ==> Caveats 58 | New shell sessions will start using GRC after you add this to your profile: 59 | source "`brew --prefix`/etc/grc.bashrc" 60 | ==> Summary 61 | 🍺 /usr/local/Cellar/grc/1.9: 32 files, 148K, built in 3 seconds 62 | $ 63 | ``` 64 | 65 | Like with CLI colors, you'll need to add a line to your to your `~/.bash_profile`. I recommend a slightly different syntax than what `brew` suggests: 66 | 67 | ``` 68 | if [ -f $(brew --prefix)/etc/grc.bashrc ]; then 69 | . $(brew --prefix)/etc/grc.bashrc 70 | fi 71 | ``` 72 | 73 | Bash Completion 74 | --------------- 75 | 76 | There are a number of apps that don't allow tab completion of partial text the way others do. the `brew` app called `bash-completion` (from http://bash-completion.alioth.debian.org) will make many more commands support tab completion. 77 | 78 | ``` 79 | $ brew install bash-completion 80 | ==> Downloading http://bash-completion.alioth.debian.org/files/bash-completion-1.3.tar.bz2 81 | ######################################################################## 100.0% 82 | ==> Patching 83 | patching file bash_completion 84 | ==> ./configure --prefix=/usr/local/Cellar/bash-completion/1.3 85 | ==> make install 86 | ==> Caveats 87 | Add the following lines to your ~/.bash_profile: 88 | if [ -f $(brew --prefix)/etc/bash_completion ]; then 89 | . $(brew --prefix)/etc/bash_completion 90 | fi 91 | 92 | Homebrew's own bash completion script has been installed to 93 | /usr/local/etc/bash_completion.d 94 | 95 | Bash completion has been installed to: 96 | /usr/local/etc/bash_completion.d 97 | ==> Summary 98 | 🍺 /usr/local/Cellar/bash-completion/1.3: 188 files, 1.1M, built in 20 seconds 99 | $ 100 | ``` 101 | 102 | To install bash-completeion one time type `. $(brew --prefix)/etc/bash_completion`. You can see all the apps that this `brew` recipe adds by typing 'complete -p' 103 | 104 | Once again, if you want this permanently, is are some more lines to add to your ~/.bash_profile 105 | 106 | ``` 107 | if [ -f $(brew --prefix)/etc/bash_completion ]; then 108 | . $(brew --prefix)/etc/bash_completion 109 | fi 110 | ``` 111 | 112 | Better Prompt 113 | ------------- 114 | 115 | You can customize the shell prompt (the part before $) in quite a few ways, but I find the `brew` recipe called `bash-git-prompt` to be quite powerful, especially once you start using `git`. 116 | 117 | ``` 118 | $ brew install bash-git-prompt 119 | ==> Downloading https://github.com/magicmonty/bash-git-prompt/archive/2.3.5.tar.gz 120 | ######################################################################## 100.0% 121 | ==> Caveats 122 | You should add the following to your .bashrc (or equivalent): 123 | if [ -f "$(brew --prefix bash-git-prompt)/share/gitprompt.sh" ]; then 124 | GIT_PROMPT_THEME=Default 125 | source "$(brew --prefix bash-git-prompt)/share/gitprompt.sh" 126 | fi 127 | ==> Summary 128 | 🍺 /usr/local/Cellar/bash-git-prompt/2.3.5: 21 files, 120K, built in 2 seconds 129 | $ 130 | ``` 131 | 132 | To run it one time, type: 133 | 134 | ``` 135 | GIT_PROMPT_THEME=Default 136 | source "$(brew --prefix bash-git-prompt)/share/gitprompt.sh" 137 | ``` 138 | 139 | If you like it, add this to your ~/.bash_profile: 140 | 141 | ``` 142 | if [ -f "$(brew --prefix bash-git-prompt)/share/gitprompt.sh" ]; then 143 | GIT_PROMPT_THEME=Solarized 144 | source "$(brew --prefix bash-git-prompt)/share/gitprompt.sh" 145 | fi 146 | ``` 147 | 148 | More Git & Github Tools 149 | ----------------- 150 | 151 | You will be using `git` and the _GitHub_ serve regularly, so these tools add additional functionality. 152 | 153 | The first is called `hub`, and it provides all the functionality of `git`, but adds some _GitHub_ specific features. 154 | 155 | ``` 156 | $ brew install hub 157 | 158 | 159 | ``` 160 | 161 | Since `hub` is compatible with `git`, I `alias` it in my `~/bash_profile` 162 | 163 | ``` 164 | alias git=hub 165 | ``` 166 | 167 | The `brew` recipe [git-extras]( https://github.com/visionmedia/git-extras) adds a number of additional useful `git` commands, and they are compatible with `hub`: 168 | 169 | ``` 170 | $ brew install git-extras 171 | ==> Downloading https://homebrew.bintray.com/bottles/git-extras-2.2.0.yosemite.bottle.tar.gz 172 | ######################################################################## 100.0% 173 | ==> Pouring git-extras-2.2.0.yosemite.bottle.tar.gz 174 | ==> Caveats 175 | Bash completion has been installed to: 176 | /usr/local/etc/bash_completion.d 177 | ==> Summary 178 | 🍺 /usr/local/Cellar/git-extras/2.2.0: 91 files, 388K 179 | $ 180 | ``` 181 | 182 | Finally, GitHub offers a useful Mac GUI app called [GitHub](https://mac.github.com) for browsing git repositories. 183 | 184 | ``` 185 | $ brew cask install github-desktop 186 | ``` 187 | 188 | Prepare OSX Script 189 | ------------------ 190 | 191 | All of the the installation and customization features suggested by this tutorial are also automated as part of a prepare-osx.sh script in [https://github.com/ChristopherA/prepare-osx-for-webdev](https://github.com/ChristopherA/prepare-osx-for-webdev), however, I recommend that you do the tutorial by hand first to understand what this script does. 192 | --------------------------------------------------------------------------------