McMullin Questions Chapter 2

2.1 Command Line Parts

2.1.1 Identify the Parts of a Command
In the following command lines, identify the command name, the options (if any)
and the operands [arguments or parameters] (if any):
a) ls -aF .. 
b) cat /etc/passwd
c) pwd
d) ls -a
e) head -n 1 /etc/passwd /etc/group
f) make -v -f makefile.new

2.1.2 Interpret options and operands [arguments or parameters]

a) How is an option different than an operand [argument or parameter] ?
b) Do all command have options and operands [arguments or parameters] ?

Enter the following commands:
	ls
	ls -F
c) How do they differ?

2.1.3 Read a Usage Line
The command fold has the following Usage line:
	fold [-b] [-s] [-w width] [File ...]
Assume the file letters is in your current working directory.  For each of the 
following commands, tell whether or not it would be valid for the command:
a) fold
b) fold -w -s letters
c) fold letters
d) fold -b -q -w 60 letters vowels
e) fold -q letters

2.1.4 Multiple Choice

1) True or false: The first word in a command is always the command name.

2) Among the options of ls are the options -1, -C, -F .  The ls command can
take -1 or -C but not both; and it can always take -F .  Which synopsis
fragment correctly describes this?
a) 	[-1CF]
b)  [-1F][-CF]
c)  [-1|C][-F]
d)  [-F -1|C]

3) Suppose for ls, you enter all three options (as in: ls -1 -C -F ). What
might the program do?
a)  Print an error message and stop.
b)  Behave as though you typed -1 -F only.
c)  Behave as though you typed -C -F only.
d)  Any one of these; it depends on the command.

2.2 File Redirection and Pipes

2.2.1 Save Output in a file
In your home directory, type: pwd > iamhere
a) What does this command do?
b) Use ls to prove that the file exists.
c) Display the contents of the file iamhere with the command: cat iamhere?

d) Type the following commands:
	cd ..
	pwd > ~/iamhere
	cd
e) What do the above commands do?
f) Display the contents of the file iamhere with the command: cat iamhere
g) How did the contents of the file iamhere change?

2.2.2 Use a file as input
Type the following command:	cat < iamhere

a) What does this command do?

Type the following command:	cat < iamhere /etc/passwd /etc/group 

b) How does input file redirection differ from using file operands with cat?

2.2.3 Copy a file with File Redirection
Type the following commands: cat < iamhere > here2
Then type the following command: cat > here3 < here2
a) What do these commands do?
b) What does this command do?	cat iamhere here2 here3 > allhere

2.2.4 Append to a file
Create a file called more, and then type the following command: cat more >> allhere
a) What command do you use to create a file called more?
b) What does the specified command do?

2.2.5 Pipe to another command
Type the following command: ls -lR / | sort | more
a) Where is ls sending its output?
b) Do error messages also go there?
c) Which command is acting as a filter?

2.2.6 Escape File Redirection characters
Type the following command: echo To redirect, use > filename
a) What happened?

Type the following command: echo To redirect, use \> filename
b) What Happened?

c) What does the '\' Character do?

2.2.7 True or False?
1) All UNIX programs have access to three (standard) files.
2) A filter command must change its input.

2.2.8 Matching
1) >		i) Pipe output of this command into the next command
2) |		ii) Append output of this command into a file
3) >>		iii) Save standard error messages into a file
4) 2> 		iv) Redirect input from this file instead of the keyboard
5) <		v) Save output of this command into a file

2.3 Perhaps harder questions

1) How would you use file redirection to store a command's output in a file named:
'>>2>|' ? Would it be a good idea to create such a file?

2) Suggest a way to force a command to produce its Usage line.  Do all commands 
write Usage lines?

3) Some commands are filters and some are not.  In a long "pipeline" of commands,
Which can go at the beginning? Which at the end? Which in the middle?

4) Based on the information in this chapter, can you pipe a command's error messages?
(STDERR)?  If you wanted to transform the error messages using a filter program,
how would you go about it?

5) The sed command is a filter.  This command pipeline filters a file and mails it 
using the mailx command.  Without knowing anything more about sed or mailx, can you
think of a shorter way to write the following command line?
	cat archivefile | sed -f script | mailx root


Questions? Robert Katz: rkatz@ned.highline.edu
Last Update July 2, 2002