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

Explain how and what the following commands are trying to accomplish. Looking fo

ID: 3630921 • Letter: E

Question

Explain how and what the following commands are trying to accomplish. Looking for an expert to double check my work and maybe give some pointers as I am new to UNIX.
ls /etc | grep conf | grep -v "." | sort > ~/conf

In this pipe we have the first command ls /etc which lists the contents of the directory /etc which is then piped using the | operator and a filter to the standard in of the grep conf command which searches the contents of the directory /etc for any lines of the input stream for text containing conf. The data is then piped from the standard out and into the standard in of the grep -v "." Command where it searches through all the lines in the files that contain conf for lines without a period, then pipes it using a filter to the sort > ~/conf command. The sort then sorts the results into alphabetical order, then the > operator creates the file in the home directory ~/conf.


cat /etc/passwd | awk -F":" '{print $1}' | sort >> ~/users 2>&1

In this pipe, the first command cat /etc/passwd displays all of the content in the file /etc/passwd then this information is piped using a filter to the  awk -F":" '{print $1}' command. The awk -F":" '{print $1}' command then uses the awk –F”:” to put a space in then : (field separator) and  then the actual awk command  '{print $1}' which prints the first field of each line then pipes it to the sort >> ~/users 2>&1 command using a filter. The data is then sorted into alphabetical order and next redirected using the >> (append) operator to the end of the home directory file ~ /users. The 2>&1 portion of the command takes the standard error data and sends it to the same place as the standard out.

Thanks

Explanation / Answer

Looks correct to me. I would mention though, that if you wrote those commands it's probably better to use "ls -1" in place of "ls" since it will only print out the file name and not permissions, owner, modification time, etc.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote