03 Apr 2012 [ 185 week12 ]

We're going to run through some examples using the Bash shell and some utility programs in Cygwin.

Here are a few of the commands we'll use:

Filesystem

Cygwin provides a Unix compatibility layer over the Windows filesystem, which gives a single-hierarchy interface rather than a collection of letters for each drive. All real drives (like C, etc.) are found in the virtual directory /cygdrive.

Globbing

Globbing is the way that Bash refers to multiple files at once (using wildcards). It will often work the same as in the Windows command line, but in the Windows command line globbing is performed by each program (so it can vary from program to program), while the Bash shell performs globbing itself.

Homework

Work through Exercise 1 & 2 (not to turn in).

To turn in:

  1. List the commands you could use to create a directory structure that looks like the hierarchy shown below (with all files empty).
    The touch command creates an empty file if the name doesn't already exist.

    folder1/
        a.txt
        b.txt
        c.txt
    folder2/
        a.txt
        b.txt
        c.txt
    folder3/
        a.txt
        b.txt
    
  2. What command would you use to remove all files starting with a, b, c, or d in your current directory? What happens if there is a subdirectory starting with b in your current directory?

  3. The find command is used to locate files (and list the found files). How can you use it in combination with wc to count the number of DLLs in your C drive?

  4. The grep command searches through files (or standard input), much like findstr that is usually available in the Windows command line. It uses regular expressions to define a pattern for the search. Suppose you want to print all the lines of a Java program that aren't comments. What command could you use to do that? Assume that commented lines always start with some number of spaces and then the single-line Java comment token (//). Hint: look at the man page for grep to see how to select all lines that don't match a pattern.