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

Please help with this and DO NOT copy others answers since I am looking for basi

ID: 3744107 • Letter: P

Question

Please help with this and DO NOT copy others answers since I am looking for basic commands cus we just started our class
Commands like the picture I am attaching - Nothing fancy please - trying to learn the basic but I am stock in a few commands Open a bash shell window and Change directory to /etc/ 1. Find commands with patterns List all files/directories in the /etc/ directory that start with "p" or "q". List all files/directories in the /etc/ directory that start with "p" or "q" and must have a second letter as "p". List all files/directories in the /etc/ directory that must start the line with "se" and have the optional third letter of "r" List all files/directories in the /etc/ directory that use non-alphanumeric characters in their names List all files/directories in the /etc/ directory that use the word "yum" in their names. List all files/directories in the /etc/ directory that use digits in the name. Modify the solution of (f) to show those files and directories that have digits and end in "d". List all files/directories in the /etc/ directory that have the text strings(within the files/directories) "cron" OR "yum" a. b. c. d. e. f. g. h.

Explanation / Answer

First to get into /etc/ directory, use cd /etc/

a. To list all the files or directories starting with either p or q. This is achieved by usage of brackets with all the characters you want to match. * beside the closing bracket says match anything after the first character. -d is optional (means in case of directory, only list it's name not it's entire contents)

ls [pq]* -d

b. Usage of a p beside the closing bracket says the second character should strictly be 'p' and after that it can be anything (*)

ls [pq]p* -d

c. Assuming it is - files which start with 'se' as well as 'ser' but 'ser' will be a subset of of files which start with 'se'. Here we are combining multiple wildcards using @() and | mechanism.

ls @(se|ser)* -d

d. A file can start with any letter and any number of letters but should have a non alphanumeric character at any point ([^0-9A-Za-z._-] ) and can contain anything thereafter.

ls -d *[^0-9A-Za-z._-]*

e. A file can start with any letter and can have multiple letters (*) but at some point it needs to have yum together. And can have anything after that as well (*)

ls *yum* -d

f. A file can have anything and any number of characters (even zero) at the start and at the end but at some point should have a digit between 0-9  

ls *[0-9]* -d

g. Similar to f but should strictly end with d. Hence the character 'd' in the end.

ls *[0-9]d -d

h. Cannot be achieved using simple ls alone in this case. We can the use the powerful grep utility for this.

grep -Rl 'cron|yum'

grep matches all files which have the supplied strings (cron and yum). -R denotes recursive (search subfolders recursively) and l says display only the filenames not the lines. Note that we need to escape '|' using a backslash '' to match multiple strings (cron and yum) in this case.