# The Shell
-[Back To The Menu](http://github.com/JHU-SWC-2012/SWC-bootcamp/)
-- [Forward to Python Variables](http://github.com/JHU-SWC-2012/SWC-bootcamp/tree/master/2a-PythonVariables/)
-
-* * * * *
-
-**Updated and presented by : Radhika Khetani**
-
-**Modified by : Sasha Wood**
-
-**This presentation originally developed by: Milad Fatenejad**
+**Material by Milad Fatenejad, Sasha Wood, and Radhika Khetani**
# What is the shell how do I access the shell?
with a keyboard instead of controlling graphical user interfaces
(GUIs) with a mouse/keyboard combination.
-Use the GUI to open the tutorial on github. Single click on the "Firefox
-Web Browser". Type in the URL:
- github.com/thehackerwithin/boot-camps/tree/2013-01-chicago
+Use a browser to open the tutorial on github, located at:
+ https://github.com/USERNAME/boot-camps/tree/YYYY-MM-PLACE
Click on the directory named `shell`.
the data for this test, you will need internet access. Just enter the
command:
- git clone https://github.com/thehackerwithin/boot-camps.git
+ git clone -b YYYY-MM-PLACE https://github.com/USERNAME/boot-camps.git
Followed by:
- git checkout 2013-01-chicago
+ cd boot-camps
+ git checkout YYYY-MM-PLACE
These 2 commands will grab all of the data needed for this workshop from the
internet.
convenient way. In those terminals, use `ls -F` instead of `ls`. The
`-F` argument modifies the results so that a slash is placed at the
end of directories. If the file is *executable* meaning that it can be
-run like a program, then a star fill be placed of the file name.
+run like a program, then a star will be placed at the end of of the
+file name.
You can also use the command `ls -l` to see whether items in a
directory are files or directories. `ls -l` gives a lot more
**Changing Directories**
Now, let's move to a different directory. The command `cd` (change
-directory) is used to move around. Let's move into the `SWC-bootcamp`
+directory) is used to move around. Let's move into the `boot-camps`
directory. Enter the following command:
- cd SWC-bootcamp
+ cd boot-camps
Now use the `ls` command to see what is inside this directory. You
will see that there is an entry which is green. This means that this
This directory contains all of the material for this boot camp. Now
move to the directory containing the data for the shell tutorial:
- cd 1-Shell
+ cd shell
If you enter the `cd` command by itself, you will return to the home
-directory. Try this, and then navigate back to the `1-Shell`
+directory. Try this, and then navigate back to the `shell`
directory.
## Arguments
home directory if you are not already there. Then enter the
command:
- ls SWC-bootcamp
+ ls boot-camps
-This will list the contents of the `SWC-bootcamp` directory without
+This will list the contents of the `boot-camps` directory without
you having to navigate there. Now enter:
- ls SWC-bootcamp/1-Shell
+ ls boot-camps/shell
-This prints the contents of `1-Shell`. The `cd` command works in a
+This prints the contents of `shell`. The `cd` command works in a
similar way. Try entering:
- cd SWC-bootcamp/1-Shell
+ cd boot-camps/shell
-and you will jump directly to `1-Shell` without having to go through
+and you will jump directly to `shell` without having to go through
the intermediate directory.
## Full vs. Relative Paths
Now enter the following command:
- cd /home/swc/SWC-bootcamp/1-Shell
+ cd /home/swc/boot-camps/shell
-This jumps to `1-Shell`. Now go back to the home directory. We saw
+This jumps to `shell`. Now go back to the home directory. We saw
earlier that the command:
- cd SWC-bootcamp/1-Shell
+ cd boot-camps/shell
-had the same effect - it took us to the `1-Shell` directory. But,
+had the same effect - it took us to the `shell` directory. But,
instead of specifying the full path
-(`/home/swc/SWC-bootcamp/1-Shell`), we specified a *relative path*. In
+(`/home/swc/boot-camps/shell`), we specified a *relative path*. In
other words, we specified the path relative to our current
directory. A full path always starts with a `/`. A relative path does
not. You can usually use either a full path or a relative path
There are some shortcuts which you should know about. Dealing with the
home directory is very common. So, in the shell the tilde character,
-`~`, is a shortcut for your home directory. Navigate to the `1-Shell`
+`~`, is a shortcut for your home directory. Navigate to the `shell`
directory, then enter the command:
ls ~
ls ..
-prints the contents of the `/home/swc/SWC-bootcamp`. You can chain
+prints the contents of the `/home/swc/boot-camps`. You can chain
these together, so:
ls ../../
-prints the contents of `/home/swsc` which is your home
+prints the contents of `/home/swc` which is your home
directory. Finally, the special directory `.` always refers to your
current directory. So, `ls`, `ls .`, and `ls ././././.` all do the
same thing, they print the contents of the current directory. This may
**Wild cards**
-Navigate to the `~/SWC-bootcamp/Shell-1/data/THOMAS` directory. This
+Navigate to the `~/boot-camps/shell/data/THOMAS` directory. This
directory contains our hearing test data for THOMAS. If we type `ls`,
we will see that there are a bunch of files which are just four digit
numbers. By default, `ls` lists all of the files in a given
cd S<tab>
The shell will fill in the rest of the directory name for
-`SWC-bootcamp`. Now enter:
+`boot-camps`. Now enter:
ls 3<tab><tab>
starts with an `e`. One of those is `echo`. If you enter `ec<tab>` you
will see that tab completion works.
-** Command History**
+**Command History**
You can easily access previous commands. Hit the up arrow.
Hit it again. You can step backwards through your command history.
then an error is printed. The shell ONLY checks in the places listed
in the `PATH` environment variable.
-Navigate to the `1-Shell` directory and list the contents. You will
+Navigate to the `shell` directory and list the contents. You will
notice that there is a program (executable file) called `hello` in
this directory. Now, try to run the program by entering:
hello
You should get an error saying that hello cannot be found. That is
-because the directory `/home/swc/SWC-bootcamp/1-Shell` is not in the
+because the directory `/home/swc/boot-camps/shell` is not in the
`PATH`. You can run the `hello` program by entering:
./hello
located right here. So, you can run any program by entering the path
to that program. You can run `hello` equally well by specifying:
- /home/swc/SWC-bootcamp/1-Shell/hello
+ /home/swc/boot-camps/shell/hello
Or by entering:
- ../1-Shell/hello
+ ../shell/hello
When there are no `/` characters, the shell assumes you want to look
in one of the default places for the program.
* * * *
**Short Exercises**
-1. Print out the contents of the `~/SWC-bootcamp/1-Shell/dictionary.txt`
+1. Print out the contents of the `~/boot-camps/shell/dictionary.txt`
file. What does this file contain?
-2. Without changing directories, (you should still be in `1-Shell`),
+2. Without changing directories, (you should still be in `shell`),
use one short command to print the contents of all of the files in
- the /home/swc/SWC-bootcamp/1-Shell/data/THOMAS directory.
+ the `/home/swc/boot-camps/shell/data/THOMAS` directory.
* * * *
be annoying to use. The program, `less`, is useful for this
case. Enter the following command:
- less ~/SWC-bootcamp/1-Shell/dictionary.txt
+ less ~/boot-camps/shell/dictionary.txt
`less` opens the file, and lets you navigate through it. The commands
are identical to the `man` program. Use "space" to go forward and hit
## Redirection
Let's turn to the experimental data from the hearing tests that we
-began with. This data is located in the `~/SWC-bootcamp/1-Shell/data`
+began with. This data is located in the `~/boot-camps/shell/data`
directory. Each subdirectory corresponds to a particular participant
in the study. Navigate to the `Bert` subdirectory in `data`. There
are a bunch of text files which contain experimental data
Use `>>`, to append the contents of all of the files which contain the
number 4 in the directory:
- /home/swc/SWC-bootcamp/1-Shell/data/gerdal
+ /home/swc/boot-camps/shell/data/gerdal
to the existing `all_data` file. Thus, when you are done `all_data`
should contain all of the experiment data from Bert and any
## Creating, moving, copying, and removing
We've created a file called `all_data` using the redirection operator
-`>`. This is critical file so we have to make copies so that the data
-is backed up. Lets copy the file using the `cp` command. The `cp`
+`>`. This file is critical - it's our analysis results - so we want to
+make copies so that the data is backed up.
+Lets copy the file using the `cp` command. The `cp`
command backs up the file. Navigate to the `data` directory and enter:
cp all_data all_data_backup
* * * *
-Let's navigate back to `~/SWC-bootcamp/1-Shell/data`. Enter the following command:
+Let's navigate back to `~/boot-camps/shell/data`. Enter the following command:
wc Bert/* | sort -k 3 -n
* * * *
**Short Exercise**
-Navigate to the `data` directory. Use one find command to perform each
+Navigate to the `data` directory. Use one `find` command to perform each
of the operations listed below (except number 2, which does not
-require a find command):
+require a `find` command):
1. Find any file whose name is "NOTES" within `data` and delete it
Hint: If you make a mistake and need to start over just do the
following:
-1. Navigate to the `1-Shell` directory
+1. Navigate to the `shell` directory
2. Delete the `data` directory