Lab5 5 2
Lab5 5 2
Objectives:
• Review some commonly used metacharacters
• Use the ls (list files) command with metacharacters
• Use the Asterisk (*) to substitute for zero or more characters
• Use the Question Mark (?) to substitute for a single character
• Use Square Brackets to substitute for a range of characters
• Use the semicolon to execute multiple commands on one command line
Background:
In this lab the student will work with various metacharacters and use them with the ls command to refine
the student’s directory listings. Metacharacters are keyboard characters with special meaning to the
shell. A general definition of a metacharacter is any keyboard character that is not alphanumeric.
Metacharacters are used with many UNIX commands to provide greater flexibility. Some of the
metacharacters used with UNIX are similar in function to those used with DOS. The asterisk (*) and the
question mark (?) are metacharacters which are also known as wildcards. The student will work with the
ls command and the following common metacharacters with this lab.
Tools / Preparation:
a) Before starting this lab, the student should review Chapter 5, Section 5, Identifying and Using
Metacharacters.
b) The student will need the following:
1. A login user ID, for example user2, and a password assigned by their instructor.
2. A computer running the UNIX operating system with CDE.
3. Networked computers in classroom.
Notes:
1-4 Fundamentals UNIX 2.0—-Lab 5.5.2 Copyright 2002, Cisco Systems, Inc.
Use the diagram of the sample Class File system directory tree to assist with this lab.
a. Enter the command to change to the student’s home directory. What command was used?
b. Enter the command to verify the directory the student is currently in. What command was used?
2-4 Fundamentals UNIX 2.0—-Lab 5.5.2 Copyright 2002, Cisco Systems, Inc.
a. Enter the command to list files and directories in the student’s home directory that start with the
letter f. What command was used? What was listed?
b. Enter the command to list files and directories in the student’s home directory that start with the
letter d. What command was used? What was listed?
c. Enter the command to list files and directories in the student’s home directory that end with the
number 1. What command was used? What was listed?
d. Enter the command to list files and directories in the student’s home directory that have the
characters ‘ru’ anywhere in the file name. What command was used? What was
listed?
e. Enter the command to list files and directories in the coffees directory that start with the letter n
using a relative pathname. What command was used? What was listed?
$ ls dir?
a. Enter the command to list files and directories in the student’s home directory that start with the
letters file in the first four positions with anything in the fifth position but are not longer than five
characters. What command was used?
c. Enter the command to list files and directories in the student’s home directory that start with the
letter f in the first position with anything in the second and third positions and the characters e3 in
the last two positions that are not longer than five characters. What command was used?
3-4 Fundamentals UNIX 2.0—-Lab 5.5.2 Copyright 2002, Cisco Systems, Inc.
$ ls [b-f]*
dante dir1 dir3 file1 file3 fruit practice
dante_1 dir2 dir4 file2 file4 fruit2
$ ls [af]*
file1 file2 file3 file4 fruit fruit2
a. Enter the command to list files and directories in the student’s home directory that start with the
letters f through p with anything in the remaining positions. What command was used?
What was listed?
b. Enter the command to list files and directories in the student’s home directory that start with any
characters but have the numbers 1 through 3 in the last character. What command was used?
What was listed?
c. Enter the command to list files and directories in student’s home directory that start with either d
or p and have any characters in the remaining positions. What command was used?
What was listed?
$ date;cal
Wed Feb 28 11:05:39 MDT 2001
February 2001
S M Tu W Th F S
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28
a. Enter a series of commands on one line to clear the screen, display the current working directory,
and then display a long listing of files in the student’s home directory. What series of commands
were entered?
4-4 Fundamentals UNIX 2.0—-Lab 5.5.2 Copyright 2002, Cisco Systems, Inc.