Chapter 9 Summary Flashcards

1
Q

The pr command formats _____ to _____ headers and page numbers but can also drop them
(-?).

The output can be numbered (-?), double-spaced (-?), and offset from the left (-?).

A

The pr command formats input to print headers and page numbers but can also drop them
(-t).

The output can be numbered (-n), double-spaced (-d), and offset from the left (-o).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

List 3 file comparison utilities

A

cmp
comm
diff

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Display the beginning of a file

A

head

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Display the end of a file

A

tail

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Unlike head, tail can also be used with a ____ ______ (with the + option) from where extraction should begin. It is most useful in monitoring the growth of a file (-?).

A

Unlike head, tail can also be used with a line number (with the + option) from where extraction should begin. It is most useful in monitoring the growth of a file (-f).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

cut selects ______ (-?) from its input, as well as _____ (-?).

The _____ numbers
have to be a comma-delimited sequence of ascending numbers with hyphens to denote
ranges.

A

cut selects columns (-c) from its input, as well as fields (-f). The field numbers
have to be a comma-delimited sequence of ascending numbers with hyphens to denote
ranges.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

You can join two files laterally with _____. By using the delimiter in a circular manner, _____ can join multiple lines into one.

A

You can join two files laterally with paste. By using the delimiter in a circular manner, paste can join multiple lines into one.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

With ____, you can sort on one or more fields or keys (-?) and columns within these fields.

A

With sort, you can sort on one or more fields or keys (-k) and columns within these
fields.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

You can sort numerically (-?), reverse the sort order (-?), make a case-insensitive
sort (-?), merge two sorted files (-?), and remove repeated lines (-?).

A

You can
- sort numerically (-n),
- sort order (-r)
- make a case-insensitive sort (-f)
- merge two sorted files (-m),
- remove repeated lines (-u).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

____ removes repeated lines, but can also select them as well as non-repeated lines.
The command is often combined with sort, which orders the input first.

A

uniq

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

______ translates characters using two expressions, but it only accepts standard input.
It can be used to change the case of letters.

You can compress multiple consecutive occurrences (-?) and delete a specific character (-?). You can also use it with _____ _____ values and escape sequences to transform non-printable characters.

A

tr translates characters using two expressions, but it only accepts standard input.
It can be used to change the case of letters.

You can compress multiple consecutive occurrences (-s) and delete a specific character (-d). You can also use it with ASCII octal
values and escape sequences to transform non-printable characters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Provide a command that displays just lines 5, 6, 7, 8 and 9 of the file Summary.txt.

A

cat Summary.txt | head -9 | tail -5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What command would you enter to assign the current time of day in the format HH:MM:SS to a variable called CurrentTime. Remember that the date command includes the current time.

A

CurrentTime=$(date | cut -d’ ‘ -f4)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Provide a single command line that displays a sorted list of all users’ userID numbers and last names. A user’s userID value is listed in the 3rd field of the /etc/passwd file. A user’s last name is the words listed to the left of the comma in the 5th field of the /etc/passwd file. If the 5th field does not contain a comma, you may assume that the entire 5th field should appear. The last six lines of output for a correct solution will look like this:

413:Bunny
414:Yosemite
415:Flintstone
60001:NFS Anonymous Access User
60002:No Access User
65534:SunOS 4.x NFS Anonymous Access User

A

cat /etc/passwd | cut -d: -f3,5 | cut -d’,’ -f1 | sort -n

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Consider two sorted files: YogaWorkshop and FitnessWorkshop. Each file contains a list of the names (one name per line) of the people attending a Yoga workshop and Fitness workshop respectively. Some people are attending both workshops and so their name will appear in both files. Using the comm command,

(a) Provide a command line that lists the names of people attending both workshops (i.e. people whose names appear in both files).

(b) Provide a command line that lists the names of people who are attending the Yoga workshop but not the Fitness workshop.

A

a) comm -12 YogaWorkshop FitnessWorkshop

b) comm -23 YogaWorkshop FitnessWorkshop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Still working with the files in the above example, provide a command line that creates a new sorted list of attendees’ names that is called WorkshopAttendees. This file should contain all the names that are in both the YogaWorkshop and FitnessWorkshop files, but no persons name should be duplicated. You must not use the comm command to answer this question.

A

cat YogaWorkshop FitnessWorkshop | sort | uniq > WorkshopAttendees

17
Q

Provide a single command line that outputs just the name of the largest file in the current directory.

A

ls -l | tail +2 | tr -s ‘ ‘ | cut -d’ ‘ -f5,9 | sort -n | tail -1 | cut -d’ ‘ -f2

18
Q

You have access to the home directory for user rfederer. You can run the command ls -l to view the contents of the directory. Try it. You will see that the directory is filled with regular files, directories and symbolic links. Recall that the first character of the each line of the ls -l command output indicates the type of file (“-“ indicates a regular file, “d” indicates a directory, and “l” indicates a symbolic link). Your job is to provide a command line that lists a count of the number of each type of item in the directory. Your command line should generate this output:

6 D
10 L
19 R

This output indicates that rfederer’s home directory contains 6 Directories, 10 symbolic Links, and 19 Regular files.

Hint: Start with the ls -ld ~rfederer command and add filters one-by-one until you get the output desired.

A

ls -l ~rfederer | tail +2 | cut -c1 | tr ‘-‘ r | sort | tr ‘rdl’ ‘RDL’ | uniq -c