Open a bash shell window and Change directory to /etc/ 1. Find commands with pat
ID: 3816727 • Letter: O
Question
Open a bash shell window and Change directory to /etc/
1. Find commands with patterns
a. List all files/directories in the /etc/ directory that start with “p” or “q”.
b. List all files/directories in the /etc/ directory that start with “p” or “q” and must have a second letter as “p”.
c. List all files/directories in the /etc/ directory that must start the line with “se” and have the optional third letter of “r”.
d. List all files/directories in the /etc/ directory that use non-alphanumeric characters.
e. List all files/directories in the /etc/ directory that use the word “yum” and do it with word boundaries.
f. List all files/directories in the /etc/ directory that use digits in the name.
g. Modify the solution of 7 to show those files and directories that have digits and end in “d”.
h. List all files/directories in the /etc/ directory that have the text strings “cron” OR “yum” using alternation.
2. Create a directory in your work environment named test_users.
Write a bash script to:
a. Create the following output
Enter User’s Full Name :
Enter User’s ID :
Enter User’s Job Location : eg: PX17 , AM91 [AA99 pattern must ,match]
Enter User’s Manager Code :
Run this script, read input and print the result on screen.(Get a screen dump)
b. Add more code to the above script to pipe the output (i.e. user’s information) to a file named firstname_lastname.usr and save that file in the test_users directory created above. [Test with at least 2 users. Then Get a screen dump of the test_users directory] 3. Write a bash script to a. Read a file name with the pattern firstname_lastname.usr and then read that file from the test_users directory and echo that user’s information from the file.[get minimum of 2 user screen dumps] b. If the entered file name is not existing in the test_users directory echo a message “file : does not exists”. [Enter non existing file name and get a screen dump of the result]
Explanation / Answer
Sorry as per the forum rules, I'm suppose to answer only 4 questions. but just as a good gesture i have added 7.
PFB the answers
Open a bash shell window and Change directory to /etc/
1. Find commands with patterns
a. List all files/directories in the /etc/ directory that start with “p” or “q”.
ls -rlth | awk '{print $9}' | egrep "^p|^q”
It is self explanatory, I’m taking the 9th column through awk and then using grep.
b. List all files/directories in the /etc/ directory that start with “p” or “q” and must have a second letter as “p”.
ls -rlth | awk '{print $9}' | egrep "^pp|^q”
c. List all files/directories in the /etc/ directory that must start the line with “se” and have the optional third letter of “r”.
ls -rlth /etc | awk '{print $9}' | egrep "^se|^ser”
d. List all files/directories in the /etc/ directory that use non-alphanumeric characters.
find . -type f | grep -i '[^a-z0-9./_-]'
It is a regex after the find command ignoring the case with -i option
e. List all files/directories in the /etc/ directory that use the word “yum” and do it with word boundaries.
grep -rl “yum” /etc/*
I’m assuming the question is yum to find in files and in respective directories -l is to list the files and -r recursive searching
f. List all files/directories in the /etc/ directory that use digits in the name.
find . -type f | grep -i '[0-9]'
g. Modify the solution of 7 to show those files and directories that have digits and end in “d”.
find . -type f | grep '[0-9]' | grep “d$"
Again self explanatory, We are searching for digits then pipe to the last letter d with $ expression.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.