Chapter 9 Summary Flashcards
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 (-?).
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).
List 3 file comparison utilities
cmp
comm
diff
Display the beginning of a file
head
Display the end of a file
tail
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 (-?).
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).
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.
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.
You can join two files laterally with _____. By using the delimiter in a circular manner, _____ can join multiple lines into one.
You can join two files laterally with paste. By using the delimiter in a circular manner, paste can join multiple lines into one.
With ____, you can sort on one or more fields or keys (-?) and columns within these fields.
With sort, you can sort on one or more fields or keys (-k) and columns within these
fields.
You can sort numerically (-?), reverse the sort order (-?), make a case-insensitive
sort (-?), merge two sorted files (-?), and remove repeated lines (-?).
You can
- sort numerically (-n),
- sort order (-r)
- make a case-insensitive sort (-f)
- merge two sorted files (-m),
- remove repeated lines (-u).
____ 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.
uniq
______ 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.
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.
Provide a command that displays just lines 5, 6, 7, 8 and 9 of the file Summary.txt.
cat Summary.txt | head -9 | tail -5
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.
CurrentTime=$(date | cut -d’ ‘ -f4)
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
cat /etc/passwd | cut -d: -f3,5 | cut -d’,’ -f1 | sort -n
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) comm -12 YogaWorkshop FitnessWorkshop
b) comm -23 YogaWorkshop FitnessWorkshop
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.
cat YogaWorkshop FitnessWorkshop | sort | uniq > WorkshopAttendees
Provide a single command line that outputs just the name of the largest file in the current directory.
ls -l | tail +2 | tr -s ‘ ‘ | cut -d’ ‘ -f5,9 | sort -n | tail -1 | cut -d’ ‘ -f2
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.
ls -l ~rfederer | tail +2 | cut -c1 | tr ‘-‘ r | sort | tr ‘rdl’ ‘RDL’ | uniq -c