More updates to shell section. Added first exercise!
[swc-modular-shell-hearing.git] / 1-Shell / Readme.md
1 # The Shell
2
3 [Back To The Menu](http://github.com/thehackerwithin/UofCSCBC2012/)
4 - [Forward to Python Variables](http://github.com/thehackerwithin/UofCSCBC2012/tree/master/2a-PythonVariables/)
5
6 * * * * *
7
8 **Presented By : Milad Fatenejad**
9
10 **Most of this material came from a presentation by: ??????**
11
12 # What is the shell how do I access the shell?
13
14 The *shell* is a program that presents a command line interface
15 which allows you to control your computer using commands entered
16 with a keyboard instead of controlling graphical user interfaces
17 (GUIs) with a mouse/keyboard combination.
18
19 A *terminal* is a program you run that gives you access to the
20 shell. There are many different terminal programs that vary across
21 operating systems. To open the default terminal in Ubuntu, just
22 click... or just use CTRL+ALT+t
23          
24 There are many reasons to learn about the shell. In my opinion, the
25 most important reasons are that: 
26
27 1.  It is very common to encounter the shell and
28     command-line-interfaces in scientific computing, so you will
29     probably have to learn it eventually 
30
31 2.  The shell is a really powerful way of interacting with your
32     computer. GUIs and the shell are complementary - by knowing both
33     you will greatly expand the range of tasks you can accomplish with
34     your computer. You will also be able to perform many tasks more
35     efficiently.
36
37 The shell is just a program and there are many different shell
38 programs that have been developed. The most common shell (and the one
39 we will use) is called the Bourne-Again SHell (bash). Even if bash is
40 not the default shell, it usually installed on most systems and can be
41 started by typing "bash" in the terminal. Many commands, especially a
42 lot of the basic ones, work across the various shells but many things
43 are different. I recommend sticking with bash and learning it well.
44
45 # The Example: Manipulating Experimental Data Files
46
47 We will spend most of our time learning about the basics of the shell
48 by manipulating some experimental data from a hearing tests. 
49
50 **Cochlear Implants**
51
52 A cochlear implant is a small electronic device that is surgically
53 implanted in the inner ear to give deaf people a sense of
54 hearing. More than a quarter of a million people have them, but there
55 is still no widely-accepted benchmark to measure their effectiveness.
56 In order to establish a baseline for such a benchmark, our supervisor
57 got teenagers with CIs to listen to audio files on their computer and
58 report:
59
60 1.  the quietest sound they could hear
61 2.  the lowest and highest tones they could hear
62 3.  the narrowest range of frequencies they could discriminate
63
64 To participate, subjects attended our laboratory and one of our lab
65 techs played an audio sample, and recorded their data - when they
66 first heard the sound, or first heard a difference in the sound.  Each
67 set of test results were written out to a text file, one set per file.
68 Each participant has a unique subject ID, and a made-up subject name.
69 Each experiment has a unique experiment ID. The experiment has
70 collected 351 files so far.
71
72 The data is a bit of a mess! There are inconsistent file names, there
73 are extraneous "NOTES" files that we'd like to get rid of, and the
74 data is spread across many directories. We are going to use shell
75 commands to get this data into shape. By the end we would like to:
76
77 1.  Put all of the data into one directory called "alldata"
78
79 2.  Have all of the data files in there, and ensure that every file
80     has a ".txt" extension
81
82 3.  Get rid of the extraneous "NOTES" files
83
84 If we can get through this example in the available time, we will move
85 onto more advanced shell topics...
86
87 # Let's get started
88
89 One very basic command is `echo`. This command is just prints text to
90 the terminal. Try entering the command:
91
92     echo Hello, World
93
94 Then press enter. You should see the text "Hello, World" printed back
95 to you. The echo command is useful for 
96
97 ## Moving around the file system
98
99 Let's learn how to move around the file system using command line
100 programs. This is really easy to do using a GUI (just click on
101 things). Once you learn the basic commands, you'll see that it is
102 really easy to do in the shell too. 
103
104 First we have to know where we are. The program `pwd` (print working
105 directory) tells you where you are sitting in the directory tree. The
106 command `ls` will list the files in files in the current
107 directory. Directories are often called "folders" because of how they
108 are represented in GUIs. Directories are just listings of files. They
109 can contain other files or directories.
110
111 [[[START AT HOME - Slide 28]]]
112
113 **File Types**
114
115 [[[FILE TYPES - Slide 29]]]
116
117 Directories can contain other files or directories. In Ubuntu, and
118 many operating systems, 
119
120 **Changing Directories**
121
122 [[[CHANGING DIRECTORIES - Slide 30]]]
123
124 ## Arguments
125
126 Most programs take additional arguments that control their exact
127 behavior. For example, `-F` is an argument to `ls`.  The `ls` program,
128 like many programs, take a lot of arguments. But how do we know what
129 the options are to particular commands?
130
131 Most commonly used shell programs have a manual. You can access the
132 manual using the `man` program. Try entering:
133
134     man ls
135
136 This will open the manual page for `ls`. Use the arrow keys to go up
137 and down. When you are done reading, just hit `q` to exit.
138
139 Programs that are run from the shell can get extremely complicated. To
140 see an example, open up the manual page for the `gcc` program, which
141 is an open source C compiler and see just how complicated programs can
142 get! No one can possibly learn all of these arguments, of course. So
143 you will probably find yourself referring back to the manual page
144 frequently.
145
146
147 ## Examining Files ##
148
149 The easiest way to examine a file ...
150
151 * * * *
152 **Short Exercise**
153
154 Use the commands we've learned so far to figure out what the `-Wall`
155 argument for `gcc` does.
156 * * * *
157
158 # Extra Commands
159
160 ## The backtick, xargs
161
162 ## Some more common commands
163
164 **which**
165
166 **alias**
167
168 ## .bashrc
169
170 ## ssh and scp
171
172 ## Regular Expressions
173
174 # Milad's Notes:
175
176 Don't we have to clone the repo?
177
178 Introduce less early - go over searching. 
179
180 # Background, Foreground, control-Z, control-C
181
182 # Not everything is a file or a directory...
183 - Symbolic links
184 - /dev