Question Description
General Instructions
–Follow all of the instructions exactly and answer the questions along the way.
–Perform only the tasks that are indicated.Doing anything more or anything less may cause subsequent answers to be incorrect.
–Submit this lab to the appropriate area on Blackboard when you are done.
–If a question asks you what command you typed, provide the command exactly as you entered it in the terminal window.
–Use the man pages as needed, and/or refer back to the lecture videos as needed.
–Record your answers using a different color font. Upload in a .doc or .docx format.
Section 1 – Basic grep Commands
- Log in to your Pi as a regular (non-root and non-admin) user, then open a terminal window and navigate to /usr/share/common-licenses/
- Run the following command:grep “GNU” GPL-3
- Modify the command in #2 so that it displays the total number of lines containing matches.
- How many lines are there?
- What command did you enter for this step?
- Modify the command in #2 so that it returns the number of matches.(We saw how to do this with pipes in the lecture videos.)
- How many matches are there?
- What command did you enter for this step?
- Modify the command in #4 so that it returns the number of case-insensitive matches (meaning it doesn’t care about capitalization).
- How many matches are there?
- What command did you enter for this step?
- This shows all lines in GPL-3 ending with a capital letter:grep “[A-Z]$” GPL-3
How many such lines are there? - Consider this grep command:grep -v “license” GPL-3
- What does the given grep command do?
- How many lines in the file are returned by the grep command?(Hint: Modify the given command slightly and run the modified version.)
- Run a grep command to display the lines that START with the expression GNU in all capitals.
- What command did you enter for this?
- How many lines are there?
- Run a grep command to display the lines that END with the word license regardless of capitalization.(In other words, your matches should be case insensitive.)
- What command did you enter for this?
- How many lines are there?
- Explain in general what the following regular expression matches:”^[^aeiouy]”
- The regular expression “.*” is very useful because it means “match 0 or more non-newline characters”.Remember that the period means “any non-newline character” and the asterisk means “0 or more of the preceding regex”.This allows us to match essentially any string of characters completely contained on one line.
Remember also that we must “escape” using the backslash if we want to match special characters.For example, “.” matches the period character.
Explain in general what the following regular expression matches:“^[A-Z].*.$”
- Make sure you are still in /usr/share/common-licenses.Which two words does the following regular expression match?egrep “(copy)?right” GPL-3
- Give a different command that’s equivalent to the one in #12.(Hint: think grep with an option)
- Give a single grep command to find all lines matching the following description:
- Consider the following grep commands:
- egrep “[AEIOUaeiou]{3}” GPL-3shows all lines in GPL-3 with 3 consecutive vowels.How many such lines are there?
- egrep “[A-Za-z]{16,20}” GPL-3shows all lines in GPL-3 with 16, 17, 18, 19, or 20 consecutive alphabetic characters.How many such lines are there?
- One common way to find files is by name.This command searches the /usr directory and all of its subdirectories for files named “pip”:find /usr -name “pip”
- Give a find command that can be used to find all files named “cron” inside the /etc directory.(You may need sudo to make it actually work on your Pi but you don’t need to include sudo in your answer.)
- We can also use the find command to search for files by size.
- This command searches the current directory and all of its subdirectories for files that are exactly 50 bytes:find -size 50c
- This command searches /usr and all of its subdirectories for files that are less than 200 kilobytes:find /usr -size -200k
- This command searches /etc and all of its subdirectories for files that are more than 15 megabyes:find /etc -size +15M
Give a find command that searches the /lib directory for files that are more than 400 kilobytes.(You don’t need to put sudo in your answer.)
- Navigate to your home directory and run this command:find / -name “pip”
You should see a bunch of “permission denied” messages on the screen and possibly some successful results such as /usr/bin/pip.- Give a modified version of the given find command that will redirect the “permission denied” messages into the trash can (remember the trash can is /dev/null).
Give a modified version of the given find command that will both redirect the successful messages to file.txt AND redirect the “permission denied” messages into the trash can.
Section 2 – Extended Regular Expressions
The line begins with a lowercase letter, followed by one or more non-newline characters, followed by either the word “license” in all lowercase or the word “software” in all lowercase, followed by zero or more non-newline characters, and the line must end with anything except for a lowercase letter.
Your output should look like this:
form of a separately written license, or stated as exceptions;
work thus licensed is called the contributor’s “contributor version”.
or that patent license was granted, prior to 28 March 2007.
free software which everyone can redistribute and change under these terms.
Section 3 – Using the find Command
Section 4 – Redirecting Output