Linuxzoo Pipes Questions: Write the commands that will execute the following Que
ID: 3816098 • Letter: L
Question
Linuxzoo Pipes Questions: Write the commands that will execute the following
Question 6: using grep
Use grep on /usr/share/dict/words to find the first word that contains the three letter sequence wta
Question 7: count with grep
Use grep piped through wc on file /usr/share/dict/words to find the number of words that contain the letter x.
Question 8: negative grep
Use grep to find all lines in /etc/passwd that do not have nologin one the line. Make grep include the line numbers of the matching lines and send the output to file s5
Question 9: grep and ls
Use ls -l and grep to find all the files in the directory /etc that were last modified in August (hint: try looking for the case sensitive string "Aug"). Send this list to s6.
Question 10: ls grep and sort
Use ls -l and grep and sort to find all the files in /etc that were last modified in Jun. Sort this list in descending order of size and then alphabetically by name (so 2 files with the same size will appear in alphabetic order). Send the output to s7. Sorting using other techniques will probably not get the same answer...
Explanation / Answer
Question 6: Assuming there is only one such word per line,
grep -o -m 1 "wta" /usr/share/dict/words
-o would print only the word -m 1 would stop at the line where the first occurence is there
If there are multiple words per line with the same pattern, you need to pipe the above command with head
grep -o -m 1 "wta" /usr/share/dict/words | head -1. Otherwise you need to use awk or sed commands
Question 7: grep -o "x" /usr/share/dict/words | wc -w
-o prints only those words which contain the regular expression wc -w counts the number of words it receives as input
Question 8: grep -n -v "nologin" /etc/passwd > s5
-n option prints the line numbers. -v inverts the search. > operator writes to the file
Question 9: ls -l /etc | grep "Aug" > s6
Note: This sends the whole line and not only the filename
I don't know the answer for 10th one
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.