CS18 TAs Spring 2021
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- tags: labs-summer21 --- # Just for Fun: Terminal Commands One of the most useful tools you should get familiar with through your study of computer science is the **terminal**. Familiarizing youself with how to maneuver through the terminal and use some basic tools, like git and text editing, will be very helpful throughout CS18 and beyond. ## 1. Accessing the terminal * To open the terminal using macOS: Go to *Applications* -> *Utilities* -> Open *Terminal* * If you are using a a Windows machine: Search for *Command Prompt* ## 2. Basic Terminal Commands **Task: Skim Terminal Commands** This is just a list of basic useful commands; feel free to skim through then refer back to it as you do the tasks below. First, we have the `man` (manual) command and `--help` tag to help us learn about any command we might want to use. ``` man <command> ``` `man` prints the manual of a given command. For all of these commands and any new commands, use `man` to find out more about them, e.g. `man pwd` ``` <command> --help ``` Adding the `--help` tag after any command allows you to access the help menu for a specific command if available, e.g. `pwd --help` ``` pwd ``` `pwd` or "print working directory" will print the full (absolute) path to the folder the user/terminal is currently at. ``` cd <directory> ``` `cd` or "change directory" moves the user to the indicated directory if it exists inside the current directory. ``` cd </absolute-filepath> ``` putting a `/` before a filepath indicates that it's absolute, i.e. that it start from the root directory instead of from the current working directory (meaning it doesn't matter where you are now) ``` cd .. ``` `..` is a link within every directory to the previous directory that contains the current directory, `cd ..` lets you move back one folder ``` cd ~ OR cd ``` These commands will move you to your home directory (noted with a ~), which is usually your user name (e.g doing `cd` then `pwd` I get `/c/Users/mthain`) ``` ls ``` `ls` prints the contents of the current directory. ``` mkdir <directory> ``` `mkdir` creates a new empty directory named `<directory>` in the current directory. ``` rmdir <directory> ``` This command removes an **empty** directory. It must be called in the directory that contains what a user wants to remove. ``` rm -r <directory> ``` This command removes any directory and all of its contents. ``` cat <file> ``` `cat` prints the contents of `file` to your terminal ``` vim/nano <file> ``` `vim` or `nano` are basic text editors that work within the terminal; we'll talk more about them later ``` mv <filepath1> <filepath2> ``` `mv` moves what file is at filepath1 to filepath2. for example, you could put a file into a folder with `mv file folder`. `mv` will also rename the file if you include a non-folder name at the end, e.g. `mv file folder/newname` ___ **Task:** Within your own terminal, we will make a cs18 directory and resetup your file system to be based in your home directory and easily accessible. Feel free to change steps (e.g. disclude the browncs folder) or not user this, but at least go through the motions so you know how. First, cd home and make a new "browncs" folder to put everything in (I would also definitely just make a shortcut to this folder to put on your desktop and/or pin it in your Finder/File Explorer). ``` cd ~ mkdir browncs ``` Next, we'll hop inside and make a cs18 folder. ``` cd browncs mkdir cs18 ``` Now we'll make directories for different assignments. ``` cd cs18 mkdir hws mkdir labs mkdir projs ``` Finally, let's reclone the lab01 repo to our new labs folder. Let's also use a key trick! Whenever you're dealing with files or folders that exist, you can use tab to autofill what you've typed so far. Try typing `cd l` then pressing tab to complete the command. ``` cd labs ``` Then, click this url: https://classroom.github.com/a/hUL5du-F and clone the repo there. Now, let's also make a `lab99` directory to show off how the tab autocomplete works. If we press tab and there are multiple options to select from with the same prefix we've given, like if we only type l but there are multiple labs, pressing tab again will show us all of them. Then, once we see our options, we can type the necessary amount (lab) then press tab to make it work. ``` cd l cd lab cd lab01 ``` Now, if you use `ls` to list what's contained in lab01, you'll see that there is a "just-for-fun" folder. Get in there yourself and play around with your new pet using the commands we've learned above. Feel free to also mess around with other files included or skip them until we actually get to the vim editor section. **Task:** Create a home for the cat by making a new directory and moving the cat inside to protect it from the scary eagle. Then rename it also using! I've secretly included a few typos in the last parts so you'll have to type the interesting `mv` commands yourself (remember to use tab!) ``` cat cat-this-sample-text.txt cat scary-predator-eagle.txt mkdir new-cat-home mv cat-this-sample-typo.txt new-cat-home mv new-cat-home/cat-typo-sample-text.txt new-cat-home/Kryptonite ``` ## Basic Git There are three steps to updating your repository: staging, committing, and pushing. Before you perform these actions, make sure you are in the base directory of the repository, or in other words, on the main branch of your "repo." You should see something in your terminal ending with `(master)` or `(main)`, e.g. ``` Desktop ~/documents/brown/homework/cs18/lab01 (master) $ ``` If this doesn't show up, you can also run `git status` in your terminal, which will let you know if the current directory is a git repository. **Task:** Double check which branch of the repository you are in right now, and make sure that you're in the master. To stage your changes, you can use **`git add -A`**. There are many options you can use with `add`, but doing `git add -A` usually suffices. By staging, you are essentially telling Git, "These are the changes I want to save to my repository" (`-A` means stage *all* changes, which is usually what we want). **Task:** Prepare to commit by staging the changes you made to lab01. To commit your changes, use **`git commit -m "<some informative message>"`**. This command saves all the changes you specified in staging, and files it in the version history with the (hopefully) informative message you wrote. For instance: `git commit -m "Added feature X to the code."` `git commit -m` saves to your local filesystem, without updating your online GitHub repository. **Task:** Commit your changes to your local filesystem. Now your code is saved in local history, but you need to let the remote repository (GitHub) know what has changed. Do **`git push`** to upload your changes to GitHub. **Task:** Upload your changes to GitHub by pushing. (Don't worry, this won't override our version of the lab or break anyone else's lab! We've given everyone individual lab repositories.) And that's it! To recap, in order to save your changes to GitHub: 1. Double check that you're in the master branch 2. Use **`git add -A`** to stage changes 3. **`git commit -m "<your message here>"`** to commit 4. **`git push`** to push your commits to GitHub To learn more about all the fun things you can do with GitHub, check out this [link](https://nbviewer.jupyter.org/github/dscov-tutorials/gitintro/blob/master/gitintro.ipynb). ## Basic Text Editing with Vim :::spoiler **If you have Windows, click here!** Windows unfortunately does not come with Vim pre-installed. You will have to install it manually. Follow [this guide](https://www.freecodecamp.org/news/vim-windows-install-powershell/#:~:text=Vim%20is%20a%20powerful%20code,it%20running%20on%20your%20PC.) to get it set up. **Note:** Don't worry about the 'PowerShell' bit - as long as you can use it in the basic command prompt application. ::: Sometimes you might find yourself in a position where you're working in the terminal and can't easily open or access a file with an application that has an easy to understand interface (e.g. Intellij). In these cases, it will be helpful to work with a terminal level text editor, like Vim or nano. **Task:** Open your terminal and navigate to the folder that contains your code for lab 1. Remember to use `ls` to see what directories you can move into and `cd` to move into one of those directories! Once in that folder, navigate to the `src` folder. Opening a file with Vim is very simple. All you have to do is type `vim` followed by the file you want to open. So, if you want to open a file called `ILoveCS18.java`, noce you navigated to the proper directory, you would type the following command: ``` vim ILoveCS18.java ``` **Task:** Open `Leaf.java` with Vim. Once you've opened a file in Vim, your terminal will display all of the text that appears in the file. Vim has a lot of functionality, but we're only going to worry about insert mode right now. You are free to explore how the other commands work if you so wish. For a complete overview of everything you can possibly do with Vim, [look at this document](https://devhints.io/vim). Opening a file with Vim only displays it, so in order to edit any text in the file, we'll need to enter insert mode. **Task:** Enter insert mode by typing `i`. At the bottom of the terminal window, you should now see `---INSERT---`. Once you're in insert mode, you can make changes to a file and save them without having to open an application like TextEdit or IntelliJ. **Task:** Navigate around `Leaf.java` by using the arrow keys. Get to the last line and then hit enter. This should create a new line at the bottom of the file. Once you've done that, write yourself a comment (remember that comments start with a double backslash, i.e. `//`). **Note:** You can also scroll using a trackpad (though sometimes this can be a little finicky). Now that you've made a change to the document, you'll need to exit insert mode and save it! To exit insert mode, press the `esc` button on your keyboard. Once you've exited insert mode, you can save a file by typing `:w`. You can save and close a file by typing `:wq`. **Task:** Exit insert mode, then save and close `Leaf.java`. Those are the absolutely basics of Vim! Feel free to play around and change actual text in any of the lab 1 files to see how replacement works. You likely will not need to use this during this class, but you may find it helpful for the future! Now you know how to use some basic tools in the terminal! Hopefully, these skills give you a better sense of the inner workings of your computer. --- *Please let us know if you find any mistakes, inconsistencies, or confusing language in this or any other CS18 document by filling out the (mostly) [anonymous feedback form](https://cs.brown.edu/courses/cs018/feedback)!*

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully