diff --git a/new_basic_shell/01_setting_up.md b/new_basic_shell/01_setting_up.md deleted file mode 100644 index fe3fea58..00000000 --- a/new_basic_shell/01_setting_up.md +++ /dev/null @@ -1,93 +0,0 @@ ---- -title: "Setting Up and Accessing the Shell" -author: "Sheldon McKay, Mary Piper, Radhika Khetani, Emma Berdan" ---- - -## Learning Objectives -- Install and locate the software/tools necessary for accessing the command line - - -## What even is shell? - -You have likely heard the words **bash**, **shell**, **unix**, and **linux** before but may not know what they mean or how they relate. Before we even access the shell let's try to understand these terms. - -* **Unix** is simply an operating system much like Windows or macOS. **Unix** and its "flavors" are the operating systems you find on high perfomance computing clusters (HPCs). -* **Linux** can be thought of as a clone or "flavor" of **unix**. The main difference between **unix** and **linux** is that **unix** is proprietary (i.e. requires a license) while **linux** is open source. -* **Shell** is a general term for a command line interpreter, a program that lets users control their operating system with text commands. **Shell** has been described as user-facing “**shell** around the computer’s whirring innards” ([Louis Pouzin](https://en.wikipedia.org/wiki/Louis_Pouzin)) -* Since **shell** is a general term, there are many different **shells**. The most prevalent is **bash** which is short for "Bourne-Again SHell" which replaced the original Bourne shell that was NOT developed by [Jason Bourne](https://en.wikipedia.org/wiki/Jason_Bourne) but by [Stephen Bourne](https://en.wikipedia.org/wiki/Stephen_R._Bourne) a programmer at Bell labs. - - ![Foxtrot by Bill Amend](img/open_sores.png) - - *Foxtrot by Bill Amend* - -## Starting with the shell -Depending on your operating system, there are different ways to access the shell: - -> **With Macs** -> -> Macs have a utility application called "**Terminal**" for performing tasks on the command line (shell). We can open this utility to access the shell. This is generally found in `/Applications/Utilities/Terminal` -> -> **With Windows** -> -> By default, there is no terminal for the bash shell available in the Windows OS, so you have to use a downloaded program. We recommend "**Git BASH**" a shell (bash) emulator that is a part of the [Git for Windows](https://git-for-windows.github.io/) download. - -#### Command prompt - -Once you have opened the shell, you should see the command prompt ending with `$`. It will have some characters before the `$`, something like `[MacBook-Pro-5:~]`, this is telling you what the name of the computer you are working on is. - -```bash -[MacBook-Pro-5:~]$ -``` - - -### Downloading data - -We will be exploring the capabilities of the shell by working with some RNA-Seq data. We need to **download the data to our current folder** using the link below. To do so, follow the step-by-step instructions below. - -**1. Find out what folder we are currently inside**. To do this, we can use the 'print working directory' command: - -```bash -$ pwd -``` - -> On a **Mac** your current folder should be something starting with `/Users/`, like `/Users/marypiper/`. -> -> On a **Windows** machine your current folder should be something starting with `C:/Users/marypiper`. To find this in your File explorer try clicking on PC and navigating to that path. - -_Once you have identified which folder you are in, this is where we will be downloading your data._ - -**2. Right click on the link below, and be sure to "Save link as..."**. You will be prompted to choose a folder within a Finder/File Explorer window. Navigate to the directory that was listed when running `pwd`. - -* Download data by [right-clicking here](https://github.com/hbctraining/Training-modules/blob/master/Intro_shell/data/unix_lesson.zip?raw=true) and choose **Save link as**. - -**3.** Once you have downloaded the file to the correct location, go back to your **terminal window and type the 'list' command**: - -```bash -$ ls -``` - -> `ls` stands for 'list' and it lists the contents of a directory. - -_You should see `unix_lesson.zip` as part of the output to the screen._ - -**4.** Finally, to **decompress the folder**, we can use the `unzip` command: - -```bash -$ unzip unix_lesson.zip -``` - -_You should see output stating the contents of the folder are being decompressed or inflated; this is good._ - -**5.** Now when you **run the `ls` command** again you should see a folder called `unix_lesson`. - -```bash -$ ls -``` - - - -*This lesson has been developed by members of the teaching team at the [Harvard Chan Bioinformatics Core (HBC)](http://bioinformatics.sph.harvard.edu/). These are open access materials distributed under the terms of the [Creative Commons Attribution license](https://creativecommons.org/licenses/by/4.0/) (CC BY 4.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited.* - -* *The materials used in this lesson were derived from work that is Copyright © Data Carpentry (http://datacarpentry.org/). -All Data Carpentry instructional material is made available under the [Creative Commons Attribution license](https://creativecommons.org/licenses/by/4.0/) (CC BY 4.0).* -* *Adapted from the lesson by Tracy Teal. Original contributors: Paul Wilson, Milad Fatenejad, Sasha Wood and Radhika Khetani for Software Carpentry (http://software-carpentry.org/)* diff --git a/new_basic_shell/02_shell_basics.md b/new_basic_shell/02_shell_basics.md deleted file mode 100644 index ccd5c337..00000000 --- a/new_basic_shell/02_shell_basics.md +++ /dev/null @@ -1,428 +0,0 @@ ---- -title: "The Shell Basics" -author: "Sheldon McKay, Mary Piper, Radhika Khetani, Emma Berdan" ---- - -## Learning Objectives -- Describe the organization of the file directory and how to move through it -- Demonstrate different ways to manipulate files, such as moving, copying, and renaming - -### Exploring the data directory - -Now we have each created our own copy of the example data folder into our home directory, **`unix_lesson`**. Let's go into the data folder and explore the data using the shell. - -```bash -$ cd unix_lesson -``` - -> 'cd' stands for 'change directory' - -Let's see what is in here. Type: - -```bash -$ ls -``` - -You will see: - -``` -genomics_data other raw_fastq README.txt reference_data -``` - -There are five items listed. **What types of files are they?** - -We can use a "modifier" with `ls` to get more information; this modifier is called an argument (more below). - -```bash -$ ls -F - -genomics_data/ other/ raw_fastq/ README.txt reference_data/ -``` - -The `-F` argument is the 'classify' argument. Anything with a forward slash `/` after it is a directory. Things with an asterik `*` after them are programs. If there are no decorations after the name, it's a file. - -> All commands are essentially programs that are able to perform specific, commonly-used tasks. - -You can also use the command: - -```bash -$ ls -l -``` - -To see whether items in a directory are files or directories. `ls -l` gives a lot more information too. The `-l` stands for long listing. - -``` -total 124 -drwxrwsr-x 2 mp298 mp298 78 Sep 30 10:47 genomics_data -drwxrwsr-x 6 mp298 mp298 107 Sep 30 10:47 other -drwxrwsr-x 2 mp298 mp298 228 Sep 30 10:47 raw_fastq --rw-rw-r-- 1 mp298 mp298 377 Sep 30 10:47 README.txt -drwxrwsr-x 2 mp298 mp298 238 Sep 30 10:47 reference_data -``` - -Let's go into the `raw_fastq` directory and see what is in there. - -```bash -$ cd raw_fastq/ - -$ ls -F - -Irrel_kd_1.subset.fq Irrel_kd_3.subset.fq Mov10_oe_2.subset.fq -Irrel_kd_2.subset.fq Mov10_oe_1.subset.fq Mov10_oe_3.subset.fq -``` - -All six items in this directory have no trailing slashes, so they are all files, not folders or programs. - - -#### Arguments - -Most commands take additional arguments that control their exact behavior. For example, `-F` and `-l` are arguments to `ls`. The `ls` command, like many commands, take a lot of arguments. Another useful one is `-a`, which shows everything, including hidden files. How do we know what the available arguments that go with a particular command are? - -Most commonly used shell commands have a manual available in the shell. You can access the manual using the `man` command. Try entering: - -```bash -$ man ls -``` - -This will open the manual page for ls. Use the SPACE key to go forward and b to go backwards. When you are done reading, just hit q to quit. - -> **Other ways to get help** -> -> In addition to the man page, many commands also include a help page accessible by typing the command and then `--help` (sometimes also `-h`). Try entering: -> ->```bash ->$ ls --help ->``` -> -> If you are still having problems, use your web searching powers to get it! In addition to the arguments, you can also find good examples online; Google is your friend. - - -## The Unix directory file structure (a.k.a. where am I?) - -#### Moving around the file system - -Let's practice moving around a bit. - -We're going to work in that `unix_lesson` directory. - -First we did something like go to the folder of our username. Then we opened `unix_lesson` then `raw_fastq` - -Like on any computer you have used before the file structure within unix is hierarchical, like an upside down tree with root (`/`) as the starting point of the tree-like structure: - -![Unix](img/Slide1.jpg) - -That root (`/`) is often also called the 'top' level. - -When you log in to a remote computer you are on one of the branches of that tree, your home directory (e.g. /home/username) - -> On mac OS, which is a UNIX-based OS, the root level is also "/". On a windows OS, it is drive specific; generally "C:\" is considered root, but it changes to "D:/", if you are on that drive. - -Now let's go do that same navigation at the command line. - -Type: - -```bash -$ cd -``` - -> This puts you in your home directory. No matter where you are in the directory system, `cd` by itself will always bring you back to your home directory. - - -Now using `cd` and `ls`, go in to the `unix_lesson` directory and list its contents. Now go into the `raw_fastq` directory, and list its contents. - -Let's also check to see where we are. Sometimes when we're wandering around in the file system, it's easy to lose track of where we are. The command that tells you this is: - -```bash -$ pwd -``` - -> This stands for 'print working directory'. i.e. the directory you're currently working in. - -What if we want to move back up and out of the `raw_fastq` directory? Can we just type `cd unix_lesson`? Try it and see what happens. - -To go 'back up a level' we can use `..` - -Type: - -```bash -$ cd .. -``` - -> `..` denotes parent directory, and you can use it anywhere in the system to go back to the parent directory. Can you think of an example when this won't work? - - -#### Examining the contents of other directories - -By default, the `ls` commands lists the contents of the working directory (i.e. the directory you are in). You can always find the directory you are in using the `pwd` command. However, you can also give `ls` the names of other directories to view. Navigate to the home directory if you are not already there. - -Type: - -```bash -$ cd -``` - -Then enter the command: - -```bash -$ ls unix_lesson/ -``` - -This will list the contents of the `unix_lesson` directory without you having to navigate there. - -The `cd` command works in a similar way. - -```bash -$ cd unix_lesson/raw_fastq/ -$ pwd -``` - -You should now be in `raw_fastq` and you got there without having to go through the intermediate directory. - -> If you are aware of the directory structure, you can string together as long a list as you like. However, once you get past a certain number of `..` it's almost easier if you just have a full path written. - - -**** - -**Exercise** - -List the `Mov10_oe_1.subset.fq` file from your home directory without changing directories. - -**** - -## Full vs. Relative Paths - -The `cd` command takes an argument which is the directory name. Directories can be specified using either a *relative path* or a *full path*. As we know, the directories on the computer are arranged into a hierarchy. The full path tells you where a directory is in that hierarchy. Navigate to the home directory (`cd`). Now, enter the `pwd` command and you should see something like: - -```bash -$ pwd -``` - -``` -/Users/marypiper/ -``` - -which is the full path for your home directory. This tells you that you are in a directory called `marypiper`, which sits inside a directory called `Users` which sits inside the very top directory in the hierarchy, the *root directory*. So, to summarize: `marypiper` is a directory in `Users` which is a directory in `/`. - -Now enter the following command **but replacing `/Users/marypiper/` with your own full path information**: - -```bash -$ cd /Users/marypiper/unix_lesson/raw_fastq/ -``` - -This jumps to `raw_fastq`. Now go back to the home directory (`cd`). We saw -earlier that the command: - -```bash -$ cd unix_lesson/raw_fastq/ -``` - -had the same effect - it took us to the `raw_fastq` directory. But, instead of specifying the full path (`/Users/marypiper/unix_lesson/raw_fastq`), we specified a *relative path*. In other words, we specified the path **relative to our current working directory**. This relative path would not work if we were in a different folder (one which did not contain unix_lesson/raw_fastq within it). The full path will always work no matter where you are in your directory. - -**A full path always starts with a `/`, a relative path does not.** - -A relative path is like getting directions from someone on the street. They tell you to "go right at the Stop sign, and then turn left on Main Street". That works great if you're standing there together, but not so well if you're trying to tell someone how to get there from another country. A full path is like GPS coordinates. It tells you exactly where something is no matter where you are right now. - -You can usually use either a full path or a relative path depending on what is most convenient. If we are in the home directory, it is more convenient to just enter the relative path since it involves less typing. - -Over time, it will become easier for you to keep a mental note of the structure of the directories that you are using and how to quickly navigate among them. - -*** - -**Exercise** - -Change directories to `~/unix_lesson/raw_fastq/`, and list the contents of `unix_lesson/other` without changing directories again. - -*** - -### Saving time with tab completion, wildcards and other shortcuts - -#### Tab completion - -Navigate to the home directory. Typing out directory names can waste a lot of time. When you start typing out the name of a directory, then hit the tab key, the shell will try to fill in the rest of the directory name. For example, type `cd` to get back to your home directly, then enter: - -```bash -$ cd uni -``` - -The shell will fill in the rest of the directory name for `unix_lesson`. Now go to `unix_lesson/raw_fastq` and - -```bash -$ ls Mov10_oe_ -``` - -When you hit the first tab, nothing happens. The reason is that there are multiple directories in the home directory which start with `Mov10_oe_`. Thus, the shell does not know which one to fill in. When you hit tab again, the shell will list the possible choices. - -> **Tab completion is your friend!** It helps prevent spelling mistakes, and speeds up the process of typing in the full command. - -#### Wild cards - -Navigate to the `raw_fastq` directory, which is inside the `unix_lesson` directory. This directory contains FASTQ files from a next-generation sequencing dataset. - -The '*' character is a shortcut for "zero or more characters". Thus, if you enter `ls *`, you will see all of the contents of a given directory. Now try this command: - -```bash -$ ls *fq -``` - -This lists every file that begins with zero or any number of characters followed by a `fq`. This command: - -```bash -$ ls /bin/*sh -``` - -Lists every file in `/bin` that ends in the characters `sh`. - -```bash -$ ls Mov10*fq -``` - -lists only the files that begin with 'Mov10' and end with 'fq' - -So how does this actually work? The shell (bash) considers an asterisk "*" to be a wildcard character that can be used to substitute for: no characters, any other single character or a string of characters. An asterisk/star is only one of the many wildcards in UNIX, but this is the most powerful one and we will be using this one the most for our exercises. - -> _**NOTE: The wildcard asterik used in shell is different than how it is used in regular expressions.**_ For example in regular expressions, you have to use the period character followed by the asterik .* to mean "zero or more characters". - -**** - -**Exercise** - -Do each of the following using a single `ls` command without -navigating to a different directory. - -1. List all of the files in `/bin` that start with the letter 'c' -2. List all of the files in `/bin` that contain the letter 'a' -3. List all of the files in `/bin` that end with the letter 'o' - -BONUS: List all of the files in `/bin` that contain the letter 'a' or 'c'. - -**** - - -#### 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. - -'Ctrl-r' will do a reverse-search through your command history. This -is very useful. - -You can also review your recent commands with the `history` command. Just enter: - -```bash -$ history -``` - -to see a numbered list of recent commands, including this just issues -`history` command. - -> Only a certain number of commands are stored and displayed with `history`, there is a way to modify this to store a different number. - - -## Creating, moving, copying, and removing - -Now we can move around in the file structure. But what if we want to do normal things like copy files or move them around or get rid of them. Sure we could do most of these things without the command line, but what fun would that be?! Besides it's often faster to do it at the command line, or you'll be on a remote server like Amazon where you won't have another option. - -Our raw data in this case is fastq files. We don't want to change the original files, so let's make a copy to work with. - -Lets copy the file using the copy `cp` command. The usage for this command is `cp source_file destination`. Navigate to the `raw_fastq` directory and enter: - -```bash -$ cp Mov10_oe_1.subset.fq Mov10_oe_1.subset-copy.fq - -$ ls -l -``` - -Now ``Mov10_oe_1.subset-copy.fq`` has been created as a copy of `Mov10_oe_1.subset.fq` - -Let's make a 'backup' directory where we can put this file. - -The `mkdir` command is used to make a directory. Just enter `mkdir` -followed by a space, then the directory name. - -```bash -$ mkdir backup -``` - -> File/directory/program names with spaces in them do not work in unix, use characters like hyphens or underscores instead. - -We can now move our backed up file in to this directory. We can move files around using the command `mv`. The usage for this command is `mv source_file destination` (look familiar? It's the same format as the cp command!). Enter this command: - -```bash -$ mv *copy.fq backup -``` - -```bash -$ ls -l backup - --rw-rw-r-- 1 mp298 mp298 75706556 Sep 30 13:56 Mov10_oe_1.subset-copy.fq -``` - -The `mv` command is also how you rename files. Since this file is so -important, let's rename it: - -```bash -$ cd backup - -$ mv Mov10_oe_1.subset-copy.fq Mov10_oe_1.subset-backup.fq - -$ ls - -Mov10_oe_1.subset-backup.fq -``` - -Finally, we decided this was silly and want to start over. - -```bash -$ cd .. - -$ rm backup/Mov10_oe_1.subset-backup.fq -``` - -> The `rm` file permanently removes the file. Be careful with this command. The shell doesn't -just nicely put the files in the Trash. They're really gone. -> -> Same with moving and renaming files. It will **not** ask you if you are sure that you want to "replace existing file". -> -> You can use `-i` modifier with both `rm` and `mv`. This will write a prompt to standard error before moving a file that would overwrite an existing file or ask before deleting the file(s). - -We really don't need these backup directories, so, let's delete both. By default, `rm`, will NOT delete directories, but you use the `-r` flag if you are sure that you want to delete the directories and everything within them. To be safe, let's use it with the `-i` flag. - -```bash -$ rm -ri backup_ref_data/ backup_fastq/ -``` - -- `-r`: recursive, commonly used as an option when working with directories, e.g. with `cp`. -- `-i`: prompt before every removal. - -## Commands, options, and keystrokes covered - -``` -## Commands - -cd # change directory to "~" or to specified directory -ls # list contents of current or specified directory -pwd # specify present working directory -echo "..." # display content in quotes on the standard output -history # display previous "historical" commands -cp <..> <..> # copy files or directories -mkdir # make a new directory/folder -mv <..> <..> # move or rename files or directories -rm # remove a file or a folder (-r) - -## Other -~ # home directory -. # current directory -.. # parent directory -* # wildcard -ctrl + c # cancel current command -``` - - - -*** - -*This lesson has been developed by members of the teaching team at the [Harvard Chan Bioinformatics Core (HBC)](http://bioinformatics.sph.harvard.edu/). These are open access materials distributed under the terms of the [Creative Commons Attribution license](https://creativecommons.org/licenses/by/4.0/) (CC BY 4.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited.* - -* *The materials used in this lesson were derived from work that is Copyright © Data Carpentry (http://datacarpentry.org/). -All Data Carpentry instructional material is made available under the [Creative Commons Attribution license](https://creativecommons.org/licenses/by/4.0/) (CC BY 4.0).* -* *Adapted from the lesson by Tracy Teal. Original contributors: Paul Wilson, Milad Fatenejad, Sasha Wood and Radhika Khetani for Software Carpentry (http://software-carpentry.org/)* ---- diff --git a/new_basic_shell/03_creating_files.md b/new_basic_shell/03_creating_files.md deleted file mode 100644 index 58088464..00000000 --- a/new_basic_shell/03_creating_files.md +++ /dev/null @@ -1,180 +0,0 @@ ---- -title: "Nano" -author: "Emma Berdan, Meeta Mistry" ---- - -## Learning Objectives - -- Create new files and make edits to existing files with nano -- Compare different commands for examining small or large files - -## Creating text files - -### GUI text editors - -You can easily create text files on your computer by opening up a text editor program such as [TextWrangler](http://www.barebones.com/products/textwrangler/), [Sublime](http://www.sublimetext.com/), and [Notepad++](http://notepad-plus-plus.org/), and start typing. These text editors often have features to easily search text, extract text, and highlight syntax from multiple programming languages. We refer to these as **GUI text editors** since they have a **G**raphical **U**ser **I**nterface that has buttons and menus that you can click on to issue commands to the computer and you can move about the interface just by pointing and clicking. - -> **NOTE:** When we say, "text editor," we really do mean "text": these editors can only work with plain character data, not tables, images, or any other media and it explicitly excludes *Microsoft Word* or *TextEdit*. - - -### Command-line text editors - -But what if we need **a text editor that functions from the command line interface**? If we are working on remote computer (i.e. high-performance compute environments) we don't have access to a GUI and so we need to use **Command-line editors** to create, modify and save files. When using these types of editors, you cannot 'point-and-click', you must navigate the interface using only the keyboard. - -Some popular command-line editors include [nano](http://www.nano-editor.org/), [Emacs](http://www.gnu.org/software/emacs/) or [Vim](http://www.vim.org/). These editors are available by default on any shell environment, including on high-performance compute environments (local or cloud). - -### Introduction to Nano - -Today, we are going to introduce the text editor 'nano'. `nano` is simple to use and the most intuitive of the editors. It may not be as powerful in functionality, but it is a great start for those who are new to the command-line. - -#### Nano Interface - -You can create a document by calling a text editor and providing the name of the document you wish to create. Change directories to the `unix_lesson/other` folder and create a document using `nano` entitled `draft.txt`: - -```bash -$ cd ~/unix_lesson/other - -$ nano draft.txt -``` - -Now press enter. - -#### Nano interface - -You should see this: - -![image](img/nano.png) - -This should look quite similar to using a GUI plain text editor. We can see that our file is called draft.txt and our cursor is ready to add text! Type the following into the nanao editor window: - -``` -This is my first document. -This is a draft. -When I save this file it will be in my "other" folder. -``` - -The bottom of the screen provides a legend for the keystrokes that correspond to common commands that you may need when working in nano. To **write to file (save)**, type Ctrl x. The program will ask if you are sure and you can type Y then press enter. - -Open up the file again using the same command you used to create the file: `nano draft.txt` **Do not modify the file** close it again with Ctrl x. How is this different from the first time? - -> If you don't change a file nano will not ask if you are sure to save it. - - -### Nano Editing -Create the document `spider.txt` in nano. Copy and paste the text as follows: - -``` -The itsy bitsy spider -Went up the water spout -Down came the rain -And washed the spider out. -``` - -To make it easier to refer to distinct lines, we can **add line numbers** by typing reopening the document with: - -``` -nano -c spider.txt -``` - -While we cannot point and click to navigate the document, we can use the arrow keys to move around. Navigating with arrow keys can be very slow, so `nano` has shortcuts. You can find some [here]([https://www.nano-editor.org/dist/latest/cheatsheet.html](https://www.unomaha.edu/college-of-information-science-and-technology/computer-science-learning-center/_files/resources/CSLC-Helpdocs-Nano.pdf)) Several of the more common ones are already at the bottom of your nano window. - -**NOTE:** If you are using a **Mac** you must **change your terminal preferences in order to use the option button as an alt button**. Go to: Terminal preferences -> Profiles -> (click keyboard button) -> select "Use Option as Meta key" - - -| Key | Action | -| ---------------- | ---------------------- | -| Ctrl + k | Delete the current line | -| Ctrl + u | Paste| - -*** - -**Exercise** - -We have covered some basic commands in `nano`, but practice is key for getting comfortable with the program. Let's practice what we just learned by folllowing the steps outlined below: - -1. Open `spider.txt`, and delete line #2. -2. Quit without saving. -3. Open `spider.txt` again, go to the last line and delete it. -4. Save the file and see whether your results below. - -
- Answer -

-The itsy bitsy spider
-Went up the water spout
-Down came the rain
-  

-
- -## Examining Files - -We now know how to move around the file system and look at the -contents of directories, and create files - but how do we look at the contents of files? Obviously we could open files up with a text editor like `nano` but there MUST be a better way! - -The easiest way to examine **a small file** (i.e. few enough lines, that we could easily scroll through) is to just print out all of the contents using the command `cat`. Print the contents of `spider.txt` by entering the following command: - -```bash -$ cat spider.txt -``` - -This prints out the all the contents of `spider.txt` to the screen. - -> `cat` stands for catenate; it has many uses and printing the contents of a files onto the terminal is one of them. - -`spider.txt` is all of 3 lines. When you have a 100000 line file you hardly want to print the entire thing to screen (and it can take a while!). When you are working on the cluster for data analysis you will inevitably encounter with large files. - -For **large files** the command, `less`, can be useful. Let's take a look at the files in the `raw_fastq` folder. You can check the size of them by using the command `ls -lh`. This will give you the size of them in human readable format. - -```bash -$ cd ~/unix_lesson/raw_fastq - -$ ls- lh -``` - -These files are quite large, so we probably do not want to use the `cat` command to look at them. Instead, we can use the `less` command. Let's try this with one of the files. - -```bash -less Mov10_oe_1.subset.fq -``` - -We will explore FASTQ files in more detail later, but notice that FASTQ files have four lines of data associated with every sequence read. Not only is there a header line and the nucleotide sequence, similar to a FASTA file, but FASTQ files also contain quality information for each nucleotide in the sequence. - -The `less` command opens the file, and lets you navigate through it. -Shortcuts for `less` - -| key | action | -| ---------------- | ---------------------- | -| SPACE | to go forward | -| b | to go backwards | -| g | to go to the beginning | -| G | to go to the end | -| q | to quit | - -`less` also gives you a way of searching through files. Just hit the / key to begin a search. Enter the name of the string of characters you would like to search for and hit enter. It will jump to the next location where that string is found. If you hit / then ENTER, `less` will just repeat the previous search. `less` searches from the current location and works its way forward. If you are at the end of the file and search for the word "cat", `less` will not find it. You need to go to the beginning of the file and search. - -For instance, let's search for the sequence `GAGACCC` in our file. You can see that we go right to that sequence and can see what it looks like. To exit hit q. - -There's another way that we can look at files, and in this case, just -look at part of them. This can be particularly useful if we just want -to see the beginning or end of the file, or see how it's formatted. - -The commands are `head` and `tail` and they just let you look at -the beginning and end of a file respectively. - -```bash -$ head Mov10_oe_1.subset.fq -``` - - -```bash -$ tail Mov10_oe_1.subset.fq -``` - -Now that we have shown you how to create files, edit them and examin them - let's move on to the next lesson to learn more! - - -*This lesson has been developed by members of the teaching team at the [Harvard Chan Bioinformatics Core (HBC)](http://bioinformatics.sph.harvard.edu/). These are open access materials distributed under the terms of the [Creative Commons Attribution license](https://creativecommons.org/licenses/by/4.0/) (CC BY 4.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited.* - -* *The materials used in this lesson were derived from work that is Copyright © Data Carpentry (http://datacarpentry.org/). -All Data Carpentry instructional material is made available under the [Creative Commons Attribution license](https://creativecommons.org/licenses/by/4.0/) (CC BY 4.0).* -* *Adapted from the lesson by Tracy Teal. Original contributors: Paul Wilson, Milad Fatenejad, Sasha Wood and Radhika Khetani for Software Carpentry (http://software-carpentry.org/)* diff --git a/new_basic_shell/04_shell_scripts.md b/new_basic_shell/04_shell_scripts.md deleted file mode 100644 index 67a96761..00000000 --- a/new_basic_shell/04_shell_scripts.md +++ /dev/null @@ -1,154 +0,0 @@ ---- -title: "Shell scripts" -author: "Meeta Mistry, Bob Freeman, Mary Piper, Radhika Khetani, Jihe Liu, Will Gammerdinger, Emma Berdan" ---- - -Approximate time: 20 minutes - -## Learning Objectives - -- Contrast shell scripts with direct commands - - -## Shell scripts - -By this point in the module you have been introduced to a number of commands to explore your data. To demonstrate the function of each command we have run them one at a time at the command prompt. The command prompt is useful for testing out commands and also performing simple tasks like exploring and organizing the file system. When we are **running analyses which require a series of tasks to be run**, there is a more efficent way to do this using **shell scripts**. - -Shell scripts are **text files that contain commands we want to run**. Here we will introduce you to shell scripts by providing a simple example. - - -### A simple script - -We are finally ready to see what makes the shell such a powerful programming environment. To create our first script, we are going to take some of the commands we have run previously and save them into a file so that we can **re-run all those operations** again later, by typing just **one single command**. For historical reasons, a bunch of commands saved in a file is referred to as shell script, but make no mistake, this is actually a small program! - -#### File extension for shell scripts -Interestingly, when working with Shell or on the command line you can give files any (or no) extension (.txt, .tsv, .csv, etc.). Similarly, for a shell script you *don't need a specific extension*. However, it is **best practice to give shell scripts the extension `.sh`**. This is helpful to your future self and your collaborators to identify that a given file is a shell script. - -Move over to the `other` directory and create a new file using `vim`. We will call our script `listing.sh`: - -```bash -$ cd ~/unix_lesson/other -$ nano listing.sh -``` - -#### Adding commands to our script - -This shell script will do two things: - -1. Tell us our current working directory -2. List the contents of the directory - -We already know the commands for doing both of these things so let's add the 2 commands into our script, with a comment for each: - -```bash -# Print working directory -pwd - -# List contents of the directory -ls -l -``` - -Now, let's save and quit this shell script. This should bring you back to the command prompt. Check and see that the new script file you created is in this directory: - -```bash -$ ls -l -``` - -#### Running our script - -The `bash` command is typically used to start a new Bash shell session. However, if you provide it an argument, it treats that argument as the name of a script file to be run. To run the shell script you can use the `bash` command, or a short form of it, the `sh` command, followed by the name of your script: - -```bash -$ sh listing.sh -``` - -_Did it work as you expected? Do you see the output printed to your console?_ - -### Best practices for shell scripts - -This is a very simple shell script, just to introduce you to the concept. Before we jump into more scripts which better demonstrate their utility, we will take a moment to cover a few adjustments we would make to our script which we consider best practice when writing shell scripts. - -#### Shebang! - -Open up the script with `nano`. At the beginning of our script we are going to add what is called a **shebang line**. - -```bash - #!/bin/bash -``` - -This line is the **absolute path to the Bash interpreter**. The shebang line ensures that the bash shell interprets the script even if it is executed using a different shell. - -**Why do I need a shebang line? My scripts ran perfectly well before without it.** - -Having a shebang line is best practice. Your script runs fine without it, because in our current environment bash is the default shell. We mentioned previously that there are various flavors of the shell, and if your system defaults to something other than bash the script will not work. To avoid any issues, we explicitly state that this script needs to executed using the bash shell. - -#### Adding verbosity - -Our example script is quite short, and therefore is quick to run. In practice your scripts will be longer, and probably more computationall intensive. In these situations it would be great to have some report of what your script is doing as it works through the commands. This is also super useful when troubleshooting. - -An easy way to add verbosity is to **use the `echo` command**. The `echo` command is used to display a line of text that is passed in as an argument. This is a bash command that is mostly used in shell scripts to output status to the screen or to a file. - -We can include an `echo` statement for each command that we are running in our script: - -```bash -#!/bin/bash - -echo "Your current working directory is:" -pwd - -echo "These are the contents of this directory:" -ls -l - -``` - -Save your script and quit `nano`. Try running this script and see how our edits impact the output! - -_Were the `echo` commands helpful in letting you know what came next?_ - - -*** - -**Exercise** - -1. Open up the script `listing.sh` using vim. Add the command which prints to screen the contents of the file `Mov10_rnaseq_metadata.txt`. -2. Add an echo statement for the command, which tells the user "This is information about the files in our dataset:" -3. Run the new script. Report the contents of the new script and the output you got after running it. - -
- Answers -

Question 1
- Add this command to listing.sh using vim:
- cat Mov10_rnaseq_metadata.txt

-

Question 2
- Add this command to listing.sh using vim:
- echo "This is information about the files in our dataset:"

-

Question 3
- sh listing.sh

-

 Your current working directory is:
-	/home/mm573/unix_lesson/other
-	These are the contents of this directory:
-	total 240
-	-rw-rw-r-- 1 mm573 mm573  346 Sep 30 12:47 directory_info.sh
-	-rw-rw-r-- 1 mm573 mm573  193 Oct  5 14:53 listing.sh
-	-rw-rw-r-- 1 mm573 mm573   93 Sep 30 10:40 Mov10_rnaseq_metadata.txt
-	-rw-r--r-- 1 mm573 mm573 1057 Sep 30 10:40 sequences.fa
-	-rw-rw-r-- 1 mm573 mm573   48 Oct  5 14:49 spider.txt
-	This is information about the files in our dataset:
-	sample	celltype
-	OE.1	Mov10_oe
-	OE.2	Mov10_oe
-	OE.3	Mov10_oe
-	IR.1	normal
-	IR.2	normal
-	IR.3	normal
-
- - - -*** - -*This lesson has been developed by members of the teaching team at the [Harvard Chan Bioinformatics Core (HBC)](http://bioinformatics.sph.harvard.edu/). These are open access materials distributed under the terms of the [Creative Commons Attribution license](https://creativecommons.org/licenses/by/4.0/) (CC BY 4.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited.* - -* *The materials used in this lesson were derived from work that is Copyright © Data Carpentry (http://datacarpentry.org/). -All Data Carpentry instructional material is made available under the [Creative Commons Attribution license](https://creativecommons.org/licenses/by/4.0/) (CC BY 4.0).* -* *Adapted from the lesson by Tracy Teal. Original contributors: Paul Wilson, Milad Fatenejad, Sasha Wood and Radhika Khetani for Software Carpentry (http://software-carpentry.org/)* diff --git a/new_basic_shell/Lesson5_tocome.md b/new_basic_shell/Lesson5_tocome.md deleted file mode 100644 index 391bd0ae..00000000 --- a/new_basic_shell/Lesson5_tocome.md +++ /dev/null @@ -1,11 +0,0 @@ -SO SO MUCH! - -Automate everything! - -

- -

- - - -***

Screw manual labor, learn to make the computer do everything!

*** diff --git a/new_basic_shell/README.md b/new_basic_shell/README.md deleted file mode 100644 index 3f8fe184..00000000 --- a/new_basic_shell/README.md +++ /dev/null @@ -1,64 +0,0 @@ -## Introduction to the Command Line Interface - -| Audience | Computational skills required | Duration | -:----------|:----------|:----------| -| Biologists | None | 2-3 hour workshop (~3 hours of trainer-led time)| - - -### Description - -This repository has teaching materials for a **2-3 hour**, hands-on **Introduction to the command-line interface** workshop led at a relaxed pace. - - -### Learning Objectives - -* Recognize the importance of bash in the analysis of high throughput sequencing (HTS) data -* Install and locate the software/tools necessary for accessing the command line -* Describe the organization of the file directory and how to move through it -* Demonstrate different ways to manipulate files, such as moving, copying, and renaming -* Compare different commands for examining small or large files -* Create new files and make edits to existing files with nano -* Contrast shell scripts with direct commands - - -> These materials are developed for a trainer-led workshop, but also amenable to self-guided learning. - - -### Contents - -| Lessons | Estimated Duration | -|:------------------------|:----------| -|[Why Bash?]() | 15 min | -|[Acessing the Shell](Lesson1_Acesssingtheshell.md) | 15 min | -|[Moving around and basics](Lesson2_basics.md) | 45 min | -|[Creating Files and Searching](Lesson3_creatingfiles.md) | 45 min | -|[Shell Scripts](Lesson4_shellscripts.md) | 20 min | -|[Preview of other modules](Lesson5_tocome.md) | 15 min | - - - -### Dataset -[Introduction to Shell: Dataset](https://www.dropbox.com/s/t3lkyz1pz021222/unix_lesson.tar.gz?dl=1) - -### Installation Requirements - -***Mac users:*** -No installation requirements. - -***Windows users:*** -[GitBash](https://git-scm.com/download/win) - - -### Resources - -* Shell cheatsheets: - * [http://fosswire.com/post/2007/08/unixlinux-command-cheat-sheet/](http://fosswire.com/post/2007/08/unixlinux-command-cheat-sheet/) - * [https://github.com/swcarpentry/boot-camps/blob/master/shell/shell_cheatsheet.md](https://github.com/swcarpentry/boot-camps/blob/master/shell/shell_cheatsheet.md) -* [Explain shell](http://explainshell.com) - a web site where you can see what the different components of a shell command are doing. -* Software Carpentry tutorial: [The Unix shell](https://swcarpentry.github.io/shell-novice/) -* [Introduction HOW-TO Bash](https://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html) - ---- - -*These materials have been developed by members of the teaching team at the [Harvard Chan Bioinformatics Core (HBC)](http://bioinformatics.sph.harvard.edu/). These are open access materials distributed under the terms of the [Creative Commons Attribution license](https://creativecommons.org/licenses/by/4.0/) (CC BY 4.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited.* - diff --git a/new_basic_shell/img/Slide1.jpg b/new_basic_shell/img/Slide1.jpg deleted file mode 100644 index 424b5a82..00000000 Binary files a/new_basic_shell/img/Slide1.jpg and /dev/null differ diff --git a/new_basic_shell/img/nano.png b/new_basic_shell/img/nano.png deleted file mode 100644 index eb224a13..00000000 Binary files a/new_basic_shell/img/nano.png and /dev/null differ diff --git a/new_basic_shell/img/open_sores.png b/new_basic_shell/img/open_sores.png deleted file mode 100644 index b2b9b208..00000000 Binary files a/new_basic_shell/img/open_sores.png and /dev/null differ diff --git a/new_basic_shell/img/readme.md b/new_basic_shell/img/readme.md deleted file mode 100644 index 21b8ba89..00000000 --- a/new_basic_shell/img/readme.md +++ /dev/null @@ -1 +0,0 @@ -image files diff --git a/new_basic_shell/img/simpsons.gif b/new_basic_shell/img/simpsons.gif deleted file mode 100644 index 077c41d1..00000000 Binary files a/new_basic_shell/img/simpsons.gif and /dev/null differ