COMP2718 Lab 2

Your Name -- Your Student Number

Complete this assignment by downloading this HTML file and editing it (using a text editor---not a special HTML editor). Wherever you see emphasized text (e.g. "Your name" and "Your Student Number" above) you should insert your own text, as appropriate. Submit via D2L at the end of the lab period.

A. File manipulation commands

What commands could be used to accomplish to following?

  1. Create a directory called my-dictionary in your home directory.

Change this with your answer.

  1. Change into the directory with an absolute path name.

Change this with your answer.

  1. Create a symbolic link to /usr/share/dict/words called words.

Change this with your answer.

  1. Copy /usr/share/dict/words to a file called local-words.

Change this with your answer.

  1. State which of the previous two commands is the most efficient. Justiy your answer.

Change this with your answer.

  1. Determine if a hard link can be made to words.

Change this with your answer.

  1. Determine if a hard link can be made to local-words.

Change this with your answer.

  1. Change to your home directory, make a complete (i.e. recursive) copy of my-dictionary called my-dictionary-2. How were the symbolic links copied?

Change this with your answer.

  1. If you wish, remove the my-dictionary and my-dictionary-2 directories. What command was used?

Change this with your answer.

B. Globbing

Change into the /bin directory and use globbing to determine the following. State the command and the result.

  1. The names of all the four letter files that start with c.

Change this with your answer.

  1. The names of all the five letter files that start with z.

Change this with your answer.

  1. The names of all the files that contain x.

Change this with your answer.

  1. The names of all the files that start with l and end with s.

Change this with your answer.

  1. The names of all the files that start with l or m and end with d or t.

Change this with your answer.

  1. Identify if any of the files that start with l or m and end with d or t are symbolic links.

Change this with your answer.

C. Text commands and Pipelines

In a terminal window, enter the following:

$ cd ~  # Or other suitable directory
$ git clone https://gitlab.com/COMP2718/lab2_repos.git
$ cd lab2_repos

Some of the git repo contents include: words, words1, words2, words3, words4, and words5. words is a copy of the dictionary from /usr/share/dict/words. The rest of the files contain a random shuffle of the words found in words. These files with the shuffled words can be recombined to produce words.

Solve the following questions using some of the text tools: wc, ls, cat, grep, sort, uniq, head, and tail. All of the problems can be solved with one command pipeline.

  1. A long directory list for only words1, words2, words3, words4, and words5. Use globbing to select these files.

Change this with your answer.

  1. Count the number of lines and words in the files: words1, words2, words3, words4, and words5. Use globbing to select these files. What is the total count of lines for all the files?

Change this with your answer.

  1. Count the number of occurrences of pre in words2 and words3. Use globbing to select words2 and words3.

Change this with your answer.

  1. Count the number of occurrences of ation in words5, using only the last 100 lines from words5.

Change this with your answer.

  1. Show the first 5 lines of words3.

Change this with your answer.

  1. Show the last 5 lines of words4.

Change this with your answer.

  1. Provide a list of the first 6 words from sorting words1.

Change this with your answer.

  1. Provide a list of the first 6 words from sorting words1, but you must use the -r option to sort. The words from this answer must be the same as the previous question (although their order may differ).

Change this with your answer.

  1. Create a file called, all-words that is identical to words, using the files: words1, words2, words3, words4, and words5.

Change this with your answer.

  1. Count the number of occurrences of words that contain x and y from the file words. You cannot use regular expressions.

Change this with your answer.

  1. Count the number of occurrences of words that contain x, y and u from the file words. You cannot use regular expressions.

Change this with your answer.

  1. Show the first 5 words that contain x, y and u from the files words2 and words3. The list of words must be sorted before the first five are selected. You cannot use regular expressions.

Change this with your answer.

D. less, sort, grep and date manpage

Using the man command, answer the following questions.

  1. What option to sort causes sort to ignore case when sorting?

Change this with your answer.

  1. What option to sort causes sort to use numeric sorting?

Change this with your answer.

  1. What does the -c option do for grep? Give an example using the words file.

Change this with your answer.

  1. What does the -n option do for grep.

Change this with your answer.

  1. When using the command less words and after typing G, what does typing ?oo do. Describe in general terms.

Change this with your answer.

  1. Enter the following commands and observe the date program's output:

    % date +"%m-%d-%y"
    % date +"%d/%m/%Y"
    % date +"date is %d/%m/%Y"

    Modify the date's format to produce an output similar to the following:

    February 1, 2016

Change this with your answer.