(GUIs) with a mouse/keyboard combination.
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`.
A *terminal* is a program you run that gives you access to the
shell. There are many different terminal programs that vary across
operating systems.
-
+
There are many reasons to learn about the shell. In my opinion, the
-most important reasons are that:
+most important reasons are that:
1. It is very common to encounter the shell and
command-line-interfaces in scientific computing, so you will
- probably have to learn it eventually
+ probably have to learn it eventually
2. The shell is a really powerful way of interacting with your
computer. GUIs and the shell are complementary - by knowing both
the data for this test, you will need internet access. Just enter the
command:
- git clone -b YYYY-MM-PLACE https://github.com/USERNAME/boot-camps.git
+ git clone -b YYYY-MM-PLACE --single-branch git://github.com/swcarpentry/boot-camps.git
This command will grab all of the data needed for this workshop from
the internet. (We will talk about the `git` command later in the
Let's learn how to move around the file system using command line
programs. This is really easy to do using a GUI (just click on
things). Once you learn the basic commands, you'll see that it is
-really easy to do in the shell too.
+really easy to do in the shell too.
First we have to know where we are. The program `pwd` (print working
directory) tells you where you are sitting in the directory tree. The
this case, the `pwd` command tells us that we are in the `/home/swc`
directory. This is the home directory for the `swc` user. That is our
user name. You can always find out your user name by entering the
-command `whoami`.
+command `whoami`.
## File Types
Then list the contents of the directory again. You should see that a
new entry, called `testfile`, exists. It is colored white meaning that
it is a file, as opposed to a directory. The `touch` command just
-creates an empty file.
+creates an empty file.
Some terminals will not color the directory entries in this very
convenient way. In those terminals, use `ls -F` instead of `ls`. The
Now, list the contents of the /bin directory. Do you see anything
familiar in there?
-* * * *
+* * * *
## Saving time with shortcuts, wild cards, and tab completion
This prints the contents of your home directory, without you having to
type the full path. The shortcut `..` always refers to the directory
-above your current directory. Thus:
+above your current directory. Thus:
ls ..
When you hit the first tab, nothing happens. The reason is that there
are multiple directories in the home directory which start with
`s`. Thus, the shell does not know which one to fill in. When you hit
-tab again, the shell will list the possible choices.
+tab again, the shell will list the possible choices.
Tab completion can also fill in the names of programs. For example,
enter `e<tab><tab>`. You will see the name of every program that
## Command History
-You can easily access previous commands. Hit the up arrow.
-Hit it again. You can step backwards through your command history.
-The down arrow takes your forwards in the command history.
+You can easily access previous commands. Hit the up arrow.
+Hit it again. You can step backwards through your command history.
+The down arrow takes your forwards in the command history.
^-C will cancel the command you are writing, and give you a fresh prompt.
(that's an exclamation mark).
-* * * *
+* * * *
**Short Exercise**
1. Find the line number in your history for the last exercise (listing
files in /bin) and reissue that command.
-* * * *
+* * * *
## Which program?
separated by colon characters, is listed. These are the places the
shell looks for programs to run. If your program is not in this list,
then an error is printed. The shell ONLY checks in the places listed
-in the `PATH` environment variable.
+in the `PATH` environment variable.
Navigate to the `shell` directory and list the contents. You will
notice that there is a program (executable file) called `hello` in
It will print out the contents of `ex_data.txt` twice. `cat` just
takes a list of file names and writes them out one after another (this
-is where the name comes from, `cat` is short for concatenate).
+is where the name comes from, `cat` is short for concatenate).
* * * *
**Short Exercises**
less ~/boot-camps/shell/dictionary.txt
`less` opens the file, and lets you navigate through it. The commands
-are identical to the `man` program.
+are identical to the `man` program.
**Some commands in `less`**
| key | action |
-| ------- | ---------- |
+| ------- | ---------- |
| "space" | to go forward |
| "b" | to go backwarsd |
| "g" | to go to the beginning |
Use the commands we've learned so far to figure out how to search
in reverse while using `less`.
-* * * *
+* * * *
## Redirection
rm /tmp/all_data_backup
The `mkdir` command is used to make a directory. Just enter `mkdir`
-followed by a space, then the directory name.
+followed by a space, then the directory name.
* * * *
**Short Exercise**
numbers. The first is the number of lines in that file. The second is
the number of words. Finally, the total number of characters is
indicated. The final line contains this information summed over all of
-the files. Thus, there were 10445 characters in total.
+the files. Thus, there were 10445 characters in total.
Remember that the `Bert/*` and `gerdal/*4*` files were merged
into the `all_data` file. So, we should see that `all_data` contains
*end-of-file* character. It is sort of the standard way of telling the
program "I'm done entering data". The `|` character is replaces the
data from the keyboard with data from another command. You can string
-all sorts of commands together using the pipe.
+all sorts of commands together using the pipe.
The philosophy behind these command line programs is that none of them
really do anything all that impressive. BUT when you start chaining
wc Bert/* | sort -k 3 -n | head -n 1
-* * * *
+* * * *
Printing the smallest file seems pretty useful. We don't want to type
out that long command often. Let's create a simple script, a simple
Now, `cd` into the `Bert` directory and enter the command
`../smallest`. Notice that it says permission denied. This happens
because we haven't told the shell that this is an executable
-file. If you do `ls -l ../smallest`, it will show you the permissions on
+file. If you do `ls -l ../smallest`, it will show you the permissions on
the left of the listing.
Enter the following commands:
ls -l ../smallest
-You will see that the file name is green and the permissions have changed.
+You will see that the file name is green and the permissions have changed.
Congratulations, you just created your first shell script!
# Searching files
grep Range *
-* * * *
+* * * *
**Short Exercise**
Create an executable script called `smallestrange` in the `data`
file containing the file with the smallest Range. Use the commands
`grep`, `sort`, and `tail` to do this.
-* * * *
+* * * *
# Finding files
find . -type f -print | xargs grep Volume
-`find` generates a list of all the files we are interested in,
-then we pipe them to `xargs`. `xargs` takes the items given to it
+`find` generates a list of all the files we are interested in,
+then we pipe them to `xargs`. `xargs` takes the items given to it
and passes them as arguments to `grep`. `xargs` generally only creates
a single instance of `grep` (or whatever program it is running).
-* * * *
+* * * *
**Short Exercise**
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):
-1. Find any file whose name is "NOTES" within `data` and delete it
+1. Find any file whose name is "NOTES" within `data` and delete it
2. Create a new directory called `cleaneddata`
Redo exercise 4, except rename only the files which do not already end
in `.txt`. You will have to use the `man` command to figure out how to
-search for files which do not match a certain name.
+search for files which do not match a certain name.
-* * * *
+* * * *