Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Lab 4 Reading Read “The Command Line” starting on Sobell, page 126, up to the se

ID: 3575591 • Letter: L

Question

Lab 4

Reading

Read “The Command Line” starting on Sobell, page 126, up to the section titled “Simple Commands” on page 130.

Procedure

1. On a command line, what is a token? What is an argument and how does it usually affect a command? What is an option and how does it usually affect a command? How can you usually distinguish an argument from an option?

2. Review the previous labs. List one or more command lines in each of the following categories: a command line with zero arguments, one argument, two arguments, one option, and one opti

on and one argument

3. Most utilities have many options. You can read the man page or use the ––help option to learn which options a utility accepts. Experiment with the ls –r (reverse) option and try combining it with the –l option. Try using the cp –r (recursive) option to copy a directory hierarchy. Use the head –n (sub- stitute a number for n) option to display the first n lines of a file instead of the default 10; try the same option with tail. Many utilities accept the – –version option to display version and license information. Experiment with this option on some of the utilities you are familiar with.

4. What is a builtin (Sobell, page 153)? How does a builtin differ from a util- ity? The builtins man page describes the bash builtins. Which builtins have you used so far?

5. and The echo builtin copies its arguments to the screen. Given the following command line and its output, how can you repeat the command line with- out retyping it (Sobell, page 31)?

$ echo hi there

hi there

After giving the preceding command, how can you edit the command to replace hi with hello (Sobell, page 31)?

6. Using pathname expansion (Sobell, page 148), list the files in the /usr/bin directory that have the characters ab anywhere in their names.

List the files in the /usr/bin directory that begin with the letter u. Next list those that begin with un.

List the files in /usr/bin that have names that are one character long.

List the files in your home directory that begin with a period followed by the letters bash (.bash).

Deliverables

This lab introduces you to command-line terminology and has you practice using options, builtins, command-line editing, and pathname expansion. Copy all commands and output in a text file and submit to your instructor.

Explanation / Answer

1)
On the command line each sequence of nonblank characters is called a token or
word.
An argument is a token, such as a filename, string of text, number, or other
object that a command acts on. For example, the argument to a vim or emacs command
is the name of the file you want to edit.
An option is an argument that modifies the effects of a command. You can frequently
specify more than one option, modifying the command in several different
ways. Options are specific to and interpreted by the program the command line
calls, not by the shell.
Options are start with hyphen while arguments are not.

2)
A command line with
zero arguments:ls
one argument:cat temp
two arguments:cp temp tempcopy
one option:ls -l
one option and one argument:gcc -o prog.c

3)
try out these commands on your system and capture output:
ls -r
ls -l -r
cp -r
head -n 5 filename.txt
tail -n 5 filename.txt
bzip2 --version
vim --version

4)
A builtin is a utility (also called a command) that is built into a shell. Each of the
shells has its own set of builtins. When it runs a builtin, the shell does not fork a
new process.

builtin commands are:
echo
read
help

5)
echo 'hi there' | sed -r 's/hi+/hello/g'

6)
list the files in the /usr/bin directory that have the characters ab anywhere in their names.
cd /usr/bin
echo *ab*

List the files in the /usr/bin directory that begin with the letter u. Next list those that begin with un.
cd /usr/bin
echo [u]*
echo un*
  
List the files in /usr/bin that have names that are one character long.
cd /usr/bin
echo ?

List the files in your home directory that begin with a period followed by the letters bash
echo *.bash