Main Course Webpage

Course Slack Page

In-Class Lab 3: Wildcards

Objective: Getting Familiar with Basic Commands and Wildcards

These exercises get more challenging. Don't hesitate to refer to the Answers (at the end here) if you get stuck. You should be logged into one of the Linux workstations to do these parts.

Part One: Basic Commands

  1. Connect to the Lab3 directory beneath our public work area (/pub/cs). List the current directory recursively, showing hidden files and including the mark to distinguish directories. Refer to the listing to do the remaining items. (If you are logged in twice, keep the recursive listing in one window and continue the exercise in the other window) Use relative paths in all answers. Change directory only when instructed.

  2. display the contents of the file named process

  3. list the directory named Downloads. One of the files has spaces in its name. Can you see it?

  4. list the file with spaces in its name (only) adding the option -l (that's lower-case L). Can you tell what information you are seeing? Can you tell how large the file is?

  5. Note that two of the files in the Downloads directory are PDF files. If you are on the console of your linux system, you can start a PDF reader to read one. Start the PDF reader named evince, giving it the path to file.pdf When you are done, quit the PDF reader to get back to the terminal (or just expose the terminal window and type control-C)

  6. change directory to the Downloads directory. Can you display the contents of the file process from where you are? can you list the contents of the hidden directory recursively?

  7. change directory to the directory named homework. Display the contents of the file process again. If you are on a local linux system, start the PDF reader evince on file.pdf again.

  8. there is a file in the Downloads directory that does not have a valid extension. Find out what type of file it is by using the command file. Do you know what the output means and what type of data the file is?

Part Two: Wildcards

Connect to the wildcards directory beneath the public work area on hills. Then write complete commands using ls and wildcards to list the objects in the current directory only as follows:

  1. the second character in the name is a vowel (a or e or i or o or u). Other characters can be anything.

  2. the name begins with a space

  3. the name is exactly three letters (upper- or lower- case)

  4. the name ends with a character that is not a number

  5. the name contains a punctuation character

  6. the name contains a space character (blank only)

  7. the name begins with a space character (either blank or tab)

  8. the name begins or ends with an upper-case character.

Submitting Your Homework Assignment

Transfer your output script session as an attachment on Canvas

If you find something particularly interesting, please include that in your homework submission as a comment. I may ask you to share your insights at the beginning of class for participation points.

Answers and Hints:

Part One:

  1. ls -RFA is the best choice for the listing

  2. cat backup/homework/asmt01/process

  3. ls -F backup/Downloads. The file Use and Care Guide - 12828119.pdf is the one with spaces in the name

  4. referring to a file with spaces in its name is problematic. There are several solutions. The straightforward one is to quote the filename like this: ls -F backup/Downloads/'Use and Care Guide - 12828119.pdf' another possibility is to use filename completion. Type ls -F backup/Downloads/UseTAB where TAB is the tab character. If the filename is unique (which it is), the shell will fill in with the filename. (We will cover tab completion next week.) the last possibility is to use a wildcard like this ls -F backup/Downloads/Use*

  5. evince backup/Downloads/file.pdf

  6. cd backup/Downloads

    cat ../homework/asmt01/process

    ls -F ../../.config

  7. cd ../homework

    evince ../Downloads/file.pdf

  8. file ../Downloads/lab1a.noext

    The file is a tar archive. Somewhat analagous to a zip file, it is a file that contains copies of other files. Notice that the extension is not required on a linux system.

Part Two:

cd /pub/cs/grwoo/cs160a/wildcards

  1. ls -dF ?[aeiou]*

  2. ls -dF \ *

  3. ls -dF [[:alpha:]][[:alpha:]][[:alpha:]]

  4. ls -dF *[![:digit:]]

  5. ls -dF *[[:punct:]]*

  6. ls -df *' '*

  7. ls -dF [[:space:]]*

  8. This takes two wildcards - one for 'ends with' and one for 'begins with'. Note that the use of the international 'upper case' class gives some non-ASCII characters.

    ls -dF [[:upper:]]* *[[:upper:]]