Week 2: Intro

Video Notes

  • Some main commands:
    • ls - list directory
    • cd - change directory
      • will only look in my current directory
    • cd ~ : takes you to home folder
    • cd / : go to root directory
    • cd .. : one directory up
    • tab completion: pressing tab automatically completes the file name
    • clear : erase all commands
    • up arrow lets you access previous commands you’ve used
    • ctrl-c interrupt command
    • ctrl-d disconnect (used for programs like python
    • ctrl-z takes out of current process, like minimizing
  • Text editors:
    • Vim has a high learning curve and it’s universal (already installed)
    • Emacs has a smaller learning curve but you have to install it yourself
  • Vim:
    • type vim into command line to open it
    • type “:” to enter command mode
    • insert mode, press i
    • h and l move left and right
    • j and k move up and down
    • vimtutor: gives instructions
  • Emacs:
    • ctrl-x, ctrl-c
  • chsh: change shell
    • give the address to the shell you want (“bin/zsh”)
  • echo: can use regular expressions to search
    • echo resume.? : will return all files titled resume followed by a single character
    • recursive searching - echo **/* (every subdirectory in current directory / every file in that sub directory)
    • grep [text pattern] [where to search]
    • check for permissions: echo **/*(rwx)
    • can also search based on:
      • time created, modified, accessed
      • size
      • type

Lab

The purpose of this lab is to get setup with Unix and with your environment.  We expect that you have watched all of the videos in the intro module listed in the Video Schedule.  

Your tasks in this lab are as follows:

If you would like to learn about setting up a virtual machine and running Ubuntu (Linux OS) on your machine, start with step 1. If you would prefer to use the myth cluster machines or your own terminal, feel free to move to step 2. Note that if you have a Mac, you can simply use your Terminal application for the entirety of this course.

1.  Get Unix (OPTIONAL)

*** If you are running Windows, you can download Ubuntu through your Windows Store! Just type "Ubuntu" into the Windows store search bar. ***

Otherwise, to accomplish this, do the following:

  • Download Ubuntu at: http://www.ubuntu.com/download/desktop
  • Download and install some VirtualBox
  • Then, you will point it to the ISO that you downloaded from the Ubuntu website (or another Linux distro's website). The specific directions should be listed when you first run your virtual machine.

One thing to keep in mind: when you install Linux, it lets you run a "live disk" to get started fast, but this WILL NOT install Linux.  For this course, you should not run the live disk.  You need to actually install it.

2.  Getting to know your shell. In a sense, the shell allows you to drive your computer in manual mode. The shell takes input from a user, interprets the input as commands, then directs the operation of a computer by executing the commands. Shells come in a few flavor such as bash, zsh, and many others but most likely your machine is running a bash shell. This is a very important concept so make sure those sentences sunk in. In order to interact with your shell, you open a graphical program called the Terminal. If you're running Ubuntu, you can find the Terminal application if you go to your Dash home then search for 'Terminal'. If you're using your Mac, you can also perform a search for the Terminal application. We'll be using the terminal quite often so I suggest you create a shortcut to it by dragging it to your dock or navigation bar once you've found the application. Once you've got your terminal up and running, you can enter and execute the commands you've seen in the intro videos.

3.  Learn your editor. Your editor will be the tool you use to create/edit files and programs. We mention two VERY popular text editors: vim and emacs. If you want to try vim, you can run a vim tutorial program by typing 'vimtutor' (without the quotes) at the command line then pressing return. If you want to try emacs, you can run emacs and type Ctrl+h t (hold control, type h, release control and h, type t) after emacs starts. 

What if vim or emacs isn't installed on your system? If you're using Ubuntu, you can install something using apt-get.  To install emacs, you might type

      sudo apt-get install emacs23

sudo means "super user do" and it lets you run a command as an administrator. 

4.  Set up your shell and editor configuration files.  You now have a shell and a text editor. You can customize these to your heart's content! Though there are already many different types of shells with different features, you can customize your shell even more by creating a configuration file.  These files let you change the way your commonly used programs look and feel (and the way they function in some cases).  A configuration file is typically a 'dot file,' which means that it will be hidden unless you use 'ls -a' to list ALL files.  They will typically also be in your home directory.  You can configure many things, including your shell AND text editor. The config file for vim is .vimrc, for emacs is .emacs, for the zsh shell, it's .zshrc, and for the bash shell it's .bashrc. If you're on a Mac and not running Ubuntu, you might also have a file called .bash_profile. A quick google search of '.bashrc vs .bash_profile' will explain to you the difference between the two. But if you want to skip the google search, add any extensions you want in the .bash_profile file.

You probably won't have these files already, so you'll have to make them using a text editor. Assuming you're in your home directory, you can just execute 'vim .vimrc' to create your configuration file for the vim editor. You can add things such as automatic indentation, key mappings, line numbers, and so forth just by writing a few lines of text. For example, my .vimrc file might contain the line:

syntax on

In order to enable syntax highlighting. Do a google search to figure out what you need to type in order to acheive what you want. 

Similiarly, to create a configuration file for your shell, you just create it with your text editor. If you're running zsh, you can do 'vim .zshrc' then start customizing away. Do a google search to learn more about how you can configure your shell and text editor, be creative! If you're on a Mac or Ubuntu, try adding this to your shell's config file:

alias m="ssh -X [email protected]"

This will make it so that when you type in the letter 'm' and press return, the command "ssh -X [email protected]" will be executed. If you don't know, this command is to gain ssh access via the terminal to one of the myth cluster machines. You can change the input command 'm' to be anything you want as well as the meaning it maps to. If you're using a long command again and again, as you'll have to do in some classes, making an alias will be VERY helpful. Many advanced programmers and users have multiple aliases in their config files.

It's fun to create your own configuration files. You can see Sam's vimrc and zshrc at https://github.com/samking/config-files.  You are encouraged to download them for your own use.  Also note that some of them use on the other files in the repository, so you may want to download everything (see step 4).  

If you prefer to use emacs, you'll have to google for .emacs files.

5.  Have fun!