User Tools

Site Tools


assignments:ex2

Exercise 2


UNIX and Command Line Tools

Part 1

In this exercise, we will attemp to demystify the computer terminal and introduce some common command line tools.

Useful UNIX commands for the exercises below (see unix_commands.pdf for a more complete list):

  • To change directories use cd.
  • To determine current working directory use pwd.
  • To list the contents of a directory use ls.
  • To create a new directory use mkdir.
  • To create a new file use touch.
  • To insert text into a file use echo.
  • To display the contents of a file in the terminal use less or more.
  • To open a file from the command line use open. To specify a program use the -a option.
  • To delete a file use rm. To delete a directory use the -r option.
  • To print output from a command to a new file use >file_name.
  • To append output from a command to an existing file use >>file_name.
  • To go to the beginning of a line in the shell, use ctrl+a.
  • To go to the end of a line in the shell, use ctrl+e.
  • To delete text preceeding cursor in the shell, use ctrl+u.
  • To scroll back or forth in the command history use the up and down arrow keys.
  • To autofill text, use tab. This is highly recommended in order to minimize typos.

★ Interactive Exercise

1. Open a shell or terminal window.

2. Print the phrase Hello, world! to the terminal window:

$ echo Hello, world!

3. Change into the bz360 directory using cd:

$ cd /Users/bz360/

4. Confirm that you are in the bz360 directory using pwd:

$ pwd

5. List the contents of the unix directory using ls:

$ ls

6. Open the unix directory using Finder and compare between the shell list of contents and the GUI list of contents.

7. Create a new directory named unix_temp using mkdir:

$ mkdir unix_temp

8. Change into the unix_temp directory using cd:

$ cd unix_temp

9. List the contents of the unix_temp directory using ls:

$ ls

10. Create a new file named birthday.txt using touch:

$ touch birthday.txt

11. Examine the contents of the unix_temp directory using both ls and the Finder GUI to confirm that the new file exists:

$ ls

12. Add your name to the file using echo:

$ echo name >>birthday.txt

13. Add your birthday to the file using echo:

$ echo birthday: birthday >>birthday.txt

14. Add the day of the week you were born using echo (if you don’t know what day you were born, use the cal command to find out: cal month year):

$ echo born on: day >>birthday.txt

15. Add the day of the week your birthday falls on this year using echo:

$ echo Birthday in 2018: day >>birthday.txt

16. Display the contents of the file in the terminal using more or less:

$ more birthday.txt

17. Open the file from the command line in the default program using open:

$ open birthday.txt

18. Open the file in TextWrangler from the command line using open:

$ open birthday.txt -a TextWrangler

19. Delete the file using rm:

$ rm birthday.txt 

20. Confirm that the file was deleted using ls.

★ Independent Exercise 2A

During the exercise, practice using ctrl+a to go the beginning of a line, ctrl+e to go the end of a line, and ctrl+u to delete text. Examine the contents of the directory you make from both the command line and the Finder GUI.

1. Create a new directory named dna within the unix_temp directory.

2. From the command line, create a new file named dna.txt within the unix_temp directory.

3. From the command line, insert a 12-nt DNA sequence in the 5’-3’ direction into the file.

4. From the command line, insert 12 pipes (i.e. '||||||||||||' – be sure to include quotes around the pipes because pipes have a special meaning from the command line) into the dna.txt file.

5. From the command line, add the reverse complement of the original DNA sequence in the 3’-5’ direction to the file.

6. Display the contents of the sequence in the terminal.

7. Open the file in TextWrangler from the command line.

8. Are the sequences properly basepaired?

9. From the command line, delete the file and the dna directory.

10. Confirm that the directory and file were deleted.

Part 2

In this exercise, we'll introduce some basic text editing tools.

Useful UNIX commands for the exercises below (see unix_commands.pdf for a more complete list):

  • To reverse a string use rev.
  • To make single character substitutions use tr.
  • To pass one command to another use a pipe |.
  • To pass text to a command on the command line use echo.
  • To determine the number of characters, words, and lines in a document or string, use wc.

1. Determine the number of characters in your name using wc:

$ echo name | wc

Notice the number of characters is one greater than expected. Use echo -n to remove the new line character:

$ echo -n name | wc

If you want to return only the number of characters, use wc -m:

$ echo -n name | wc -m

2. Convert DNA to RNA using tr:

$ echo ATGTTT | tr T U

3. Convert lower case text to upper case text using tr:

$ echo atgctgact | tr a-z A-Z

4. Copy the contents of your terminal window and submit it to Canvas for grading.


★ Independent Exercise 2B

Use the unix commands from above to answer the questions below in the terminal.

1. Determine the complement of the following oligonucleotide sequence: ACTGCCCATTGCCTTGGGGG

2. Determine the reverse of the above oligo.

3. Determine the reverse complemepent of the above oligo.

4. Determine the length of the above oligo.

assignments/ex2.txt · Last modified: 2018/08/30 10:46 by dokuroot