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

How do you combine a ps command with another command to only display the lines c

ID: 3913131 • Letter: H

Question

How do you combine a ps command with another command to only display the lines containing the word root?

process command -Remember that the command ps allows you to look up processes running on the system: Create a file called currentprocesses.txt. Print a header with the text "Process command 1" to currentprocesses.txt this is also the only step in the assignment you'll send your output of a command to a file other than output.txt Then, use the ps command to report on *every* process on the system and use the "full format listing" and send those results to currentprocesses.txt Print another header with the text "Process command 2" to currentprocesses.txt. Then perform the process command again but this time, Filter these results so that the output will be ONLY the lines that contain the word root (remember what we can use to combine 2 commands.) Again, send the output of this process command to your currentprocesses.txt file Finally, run a third process command (header text Process command 3) that outputs only the lines that contain the string pclab send the output of this once again to your currentprocesses.txt file

Explanation / Answer

To display all the processes(full format listing) : ps –ef >> currentprocesses.txt

e : display every active process

f /F: full-format listing

>> : to append output of the command to file currentprocesses.txt

To display lines containing particular string use pipe(|) to combine ‘grep’ command with ‘ps’: ps –ef | grep “PATTERN” , here grep command is used to search for the PATTERN in the output of the ps command.

E.g.

ps –ef | grep “root” >> currentprocesses.txt

ps –ef | grep “pclab” >> currentprocesses.txt

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