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:
man
: display help informationcd
: change directorypwd
: print working directoryls
: list directory contentswc
: count letters, words, or linescp
,rm
,mv
,touch
: copy, remove, move, create/update files
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:
List the commands you could use to create a directory structure that looks like the hierarchy shown below (with all files empty).
Thetouch
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
What command would you use to remove all files starting with
a
,b
,c
, ord
in your current directory? What happens if there is a subdirectory starting withb
in your current directory?The
find
command is used to locate files (and list the found files). How can you use it in combination withwc
to count the number of DLLs in yourC
drive?The
grep
command searches through files (or standard input), much likefindstr
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 forgrep
to see how to select all lines that don't match a pattern.