Linuxzoo Pipes Questions: Write the commands that will execute the following Que
ID: 3815733 • Letter: L
Question
Linuxzoo Pipes Questions: Write the commands that will execute the following
Question 2: sort
Using cat create a pipe that will concatenate the two files club_members and names, sort them and send the output to the file s1.
Question 3: reverse sort
Using cat create a pipe that will concatenate the two files club_members and names, sort them in reverse order and send the output to the file s2.
Question 4: sort on a field
Sort the file club_members numerically by meetings attended (this is the last field). Send the output to file s3
Question 5: sort with field separator
Sort the /etc/passwd numerically by user id numbers (third field) in ascending order. You may wish to use the -t option here. Send the output to file s4
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...
Question 11: find root files
Find all the files and directories in /var (including subdirectories) that are owned by user root. Send the list of full path names to s8.
Your find command may produce "Permission Denied" errors during this search. This will have no effect on the answer, and this error can be safely ignored for this question.
Question 12: find .conf files
Find all the files in /etc (including subdirectories) end .conf Send the list of full path names to s9.
Your find command may produce "Permission Denied" errors during this search. This will have no effect on the answer, and this error can be safely ignored for this question.
Question 13: find new files
Find all the files and directories in the demo directory that are newer than s1. Send the output of the command to /var/tmp/t1 (don't send it to the demo directory). The names of the files should appear as full names. For example, the file "s5" would appear as "/home/demo/s5". The "/home/demo", if it appears in the output, should not have a trailing "/". The secret to avoiding the trailing slash is to use "/home/demo" not "/home/demo/" in the find command.
Question 14: list large files
Find all the files in the directory directory /etc/ and its subdirectories that are larger than 1 megabyte (which you can assume is 2048 blocks of 512 bytes). Send the output to s10.
Your find command may produce "Permission Denied" errors during this search. This will have no effect on the answer, and this error can be safely ignored for this question.
Question 15: small xsl files
Create a directory called smallc in /home/demo. Copy into it all the file that begin with s from /usr/include that are smaller or equal to 12K. You may find these instructions on the use of find from Developer's Daily useful.
Your find command may produce "Permission Denied" errors during this search. This will have no effect on the answer, and this error can be safely ignored for this question.
Explanation / Answer
Question 2: sort
Using cat create a pipe that will concatenate the two files club_members and names, sort
them and send the output to the file s1.
cat club_members names | sort > s1
cat club_members names will concatenate both the files.
Then piping the result to sort will sort the list.
Finally, the result is sent to the file s1.
Question 3: reverse sort
Using cat create a pipe that will concatenate the two files club_members and names, sort
them in reverse order and send the output to the file s2.
cat club_members names | sort -r> s2
cat club_members names will concatenate both the files.
Then piping the result to sort -r will reverse sort the list.
Finally, the result is sent to the file s2.
Question 4: sort on a field
Sort the file club_members numerically by meetings attended (this is the last field).
Send the output to file s3
awk '{print $NF,$0}' club_members | sort | cut -f2- -d' '
awk '{print $NF,$0}' club_members will list the last column followed by the whole line again.
Then the newly formed lines of club_members are sorted.
The result now removes the first column which is appended for sorting purpose.
Question 5: sort with field separator
Sort the /etc/passwd numerically by user id numbers (third field) in ascending order.
You may wish to use the -t option here. Send the output to file s4
cat /etc/passwd | sort -k 3 -t ':' > s4
cat /etc/passwd will list the contents of /etc/passwd
Now the list is sorted based on field 3, and the field separator ':'.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.